如何添加模态?

时间:2015-03-25 05:58:48

标签: php twitter-bootstrap modal-dialog

这是我在view.php文件中的链接我想在单击“添加播放器”按钮时以模态显示我的表单。我该怎么做?我在模板中使用bootstrap。

 <a data-toggle="modal" data-target="#myModal_login" class="btn btn-primary"  href="backend/players/player">Add Player</a>

insertPlayer.php 这是我的插入表单,我想在模态中显示我的插入表单。

    <div class="modal fade" id="myModal_login" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <table  class="form-horizontal">
                        <tr  class="form-group"><td>First Name</td><td><?php echo form_input($fname) ?></td></td></tr>
                        <tr class="form-group" ><td>Last Name</td><td><?php echo form_input($lname) ?></td></tr>
                        <tr class="form-group"><td>Address</td><td><?php echo form_textarea($address) ?></td></tr>
</table>
</div>

2 个答案:

答案 0 :(得分:2)

尝试以下代码,其工作......:)

<a class="btn btn-primary" data-toggle="modal" href="#myModal">Add Player</a>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
         // Your form
         <form>
           First name:<br>
           <input type="text" name="firstname">
            <br>
           Last name:<br>
           <input type="text" name="lastname">
          </form> 
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

答案 1 :(得分:0)

您可以将表单放在modal div标签中,如

<div class="modal fade" id="myModal_login" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <form>
   First name:<br>
   <input type="text" name="firstname">
     <br>
   Last name:<br>
   <input type="text" name="lastname">
</form> 
</div>

并将其称为

<?php    
    include'insertPlayer.php';   
?> 
<a data-toggle="modal" data-target="#myModal_login" class="btn btn-primary"  href="backend/players/player">Add Player</a>