doujing1858 2016-08-13 22:49
浏览 519
已采纳

在bootstrap模式中提交表单

I have a page using a modal to register new user Here is the modal code :

<div id="register" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">New User</h4>
      </div>
      <div class="modal-body">

      <form id="new_customer" action="../model/php/action.php" method="post">
     <div class="form-group">
  <label for="usr">username:</label>
  <input type="text" name="user" class="form-control" id="usr">
</div>
 <div class="form-group">
  <label for="em">email :</label>
  <input type="text" name="email" class="form-control" id="em">
</div>
<div class="form-group">
  <label for="pwd">password :</label>
  <input type="password" name="pwd" class="form-control" id="pwd">
</div>
        <button type="submit"  id="signup" name="signup" class="btn btn-success btn-lg">signup<span class="glyphicon glyphicon-user"></span></button>
     </form>   </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-info" data-dismiss="modal">close</button>
      </div>
    </div>

  </div>
</div>

and here example action page :

<?php
   if(isset($_POST['signup']))
   {
       if(empty($_POST['user']) || empty($_POST['email']) || empty($_POST['pwd']))
       {
       echo $lang['empty'];
       }
   }
   ?>

i want view back the results in the same dialog.

  • 写回答

1条回答 默认 最新

  • douzhuochao4027 2016-08-13 23:04
    关注

    This ajax request for your question, if you don't understand it read about jquery and ajax requests.

    http://api.jquery.com/jquery.ajax/
    https://learn.jquery.com/

    ajax request it will not call reload of the page, so your modal will still displayed:

    $.ajax({
        type: "POST",
        data: {user: $('#usr').val(), email: $('#em').val(), pwd: $('#pwd').val()},
        url: "/model/php/action.php",
        success: function(data){
              //here data will contain all output from .php, so for your script it will equal to $lang['empty'], you ca do whatever you want with data
              //f.e. set to modal
        },
        error: function(data) {
            console.log(data); //error message
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog