dongshuo2752 2014-11-19 21:19
浏览 47
已采纳

PHP:如何在模态URL中放置和传递变量

So, I have a button to give a direct link to modal in same page.

this is the button and url

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

( 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>

And then I try to submit the modal form, but the action cannot read the $user_id which I put before #modal.

UPDATE : Table code :

So this is my 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>

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?

  • 写回答

2条回答 默认 最新

  • drvlf9739 2014-11-19 21:26
    关注

    Put a hidden input field with the user_id into your form:

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

    EDIT: If you mean Bootstrap try this:

    Link/Button:

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

    Hidden Form Field:

    <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);
    });
    

    See also http://getbootstrap.com/javascript/#modals-related-target and Passing data to a bootstrap modal

    You should have mentioned Bootstrap in your question. PHP is not the appropriate tag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划