PHP:如何在模态URL中放置和传递变量 [英] PHP : How to put and pass variable in modal URL
问题描述
因此,我有一个按钮可以直接链接到同一页面中的模式.
So, I have a button to give a direct link to modal in same page.
这是按钮和网址
<a data-toggle="modal"
href="main_user.php?user_id=<?php echo $user['user_id']; ?>#myModal"
class="btn btn-warning">
(我尝试在#modal
之前回显$user_id
)对吗?
( I try to echo the $user_id
on before #modal
) is it right ?
,然后单击按钮,将出现模态. 这是具有形式的模态.
and after I click the button, the modal will appear. This is the modal with the form.
<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
.
And then I try to submit the modal form, but the action cannot read the $user_id
which I put before #modal
.
更新: 表格代码:
这是我的桌子:
<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> Change Status
</a>
</td>
</tr>
主要问题是:
当我单击按钮时,将出现模态,但无法从该按钮获取$user_id
?
The main problem is :
When I click the button, then the modal will appear but it can't get the $user_id
from that button?
推荐答案
将带有user_id的隐藏输入字段放入表单:
Put a hidden input field with the user_id into your form:
<input type="hidden" name="user_id" value="<?php echo $user['user_id']; ?>">
如果您的意思是Bootstrap,请尝试以下操作:
If you mean Bootstrap try this:
链接/按钮:
<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:
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-target 和将数据传递到引导程序模式
您应该在问题中提到Bootstrap. PHP不是适当的标记.
You should have mentioned Bootstrap in your question. PHP is not the appropriate tag.
这篇关于PHP:如何在模态URL中放置和传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!