(我尝试在 #modal 之前回显 $user_id )-6ren">
gpt4 book ai didi

PHP : How to put and pass variable in modal URL

转载 作者:行者123 更新时间:2023-12-02 01:02:22 26 4
gpt4 key购买 nike

所以,我有一个按钮可以直接链接到同一页面中的模式。

这是按钮和网址

<a data-toggle="modal" 
href="main_user.php?user_id=<?php echo $user['user_id']; ?>#myModal"
class="btn btn-warning">

(我尝试在 #modal 之前回显 $user_id )对吗?

在我点击按钮后,模式将出现。这是带有表单的模式。

<form class="form-login" action="action/doEditUserStatus.php" method="post">
<div class="login-wrap">
<div class="changestatus">
<p>Banning or Activing User Status</p></div>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-success active">
<input type="radio" name="options" value="1" autocomplete="off" checked> Actived
</label>
<label class="btn btn-primary">
<input type="radio" name="options" value="2" autocomplete="off"> Banned
</label>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
<button class="btn btn-theme" name="modalSubmit" type="submit">Submit</button>
</div>
</form>

然后我尝试提交模态表单,但操作无法读取我放在 #modal 之前的 $user_id

更新:表格代码:

这是我的 table :

<tr class="success">
<th class="numeric">ID</th>
<th class="numeric">E-mail</th>
<th class="numeric">Name</th>
<th class="numeric">Phone</th>
<th class="numeric">Picture</th>
<th class="numeric">Status</th>
<th colspan="2" class="numeric">Action</th>
</tr>


<tr>
<td class="numeric"><?php echo $user['user_id']; ?></td>
<td class="numeric"><?php echo $user['email']; ?></td>
<td class="numeric"><?php echo $user['name']; ?></td>
<td class="numeric"><?php echo $user['phone']; ?></td>
<td class="numeric"><?php echo $user['picture']; ?></td>
<td class="numeric">
<a data-toggle="modal" href="main_user.php?user_id=<?php echo $user['user_id']; ?>#myModal" class="btn btn-warning">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>&nbsp;Change Status
</a>
</td>
</tr>

主要问题是:当我单击该按钮时,模式将出现,但它无法从该按钮获取 $user_id

最佳答案

将带有 user_id 的隐藏输入字段放入您的表单中:

<input type="hidden" name="user_id" value="<?php echo $user['user_id']; ?>">

编辑:如果你的意思是 Bootstrap,试试这个:

链接/按钮:

<a data-toggle="modal" data-userid="<?php echo $user['user_id']; ?>"
href="main_user.php#myModal"
class="btn btn-warning">

隐藏表单域:

<input type="hidden" name="user_id" value="">

Javascript:

$('#myModal').on('show.bs.modal', function(e) {
var userid = $(e.relatedTarget).data('userid');
$(e.currentTarget).find('input[name="user_id"]').val(userid);
});

另见 http://getbootstrap.com/javascript/#modals-related-targetPassing data to a bootstrap modal

您应该在问题中提到 Bootstrap。 PHP 不是合适的标签。

关于PHP : How to put and pass variable in modal URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27027186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com