doujing1858
2016-08-13 22:49
浏览 394

在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.

图片转代码服务由CSDN问答提供 功能建议

我有一个页面使用 modal 来注册新用户这是模态代码:

 &lt; div id =“register”class =“modal fade”role =“dialog”&gt; 
&lt; div class =“modal-dialog”&gt; \  n 
&lt;! - 模态内容 - &gt; 
&lt; div class =“modal-content”&gt; 
&lt; div class =“modal-header”&gt; 
&lt; button type =“ 按钮“class =”close“data-dismiss =”modal“&gt;&amp; times;&lt; / button&gt; 
&lt; h4 class =”modal-title“&gt;新用户&lt; / h4&gt; 
&lt; /  div&gt; 
&lt; div class =“modal-body”&gt; 
 
&lt; form id =“new_customer”action =“../ model / php / action.php”method =“post”&gt; \  n&lt; div class =“form-group”&gt; 
&lt; label for =“usr”&gt; username:&lt; / label&gt; 
&lt; input type =“text”name =“user”class =“  form-control“id =”usr“&gt; 
&lt; / div&gt; 
&lt; div class =”form-group“&gt; 
&lt; label for =”em“&gt; email:&lt; / label&gt;  
&lt; input type =“text”name =“email”class =“form-control”id =“em”&gt; 
&lt; / div&  gt; 
&lt; div class =“form-group”&gt; 
&lt; label for =“pwd”&gt; password:&lt; / label&gt; 
&lt; input type =“password”name =“pwd”class  =“form-control”id =“pwd”&gt; 
&lt; / div&gt; 
&lt; button type =“submit”id =“signup”name =“signup”class =“btn btn-success btn-lg”  &gt;注册&lt; span class =“glyphicon glyphicon-user”&gt;&lt; / span&gt;&lt; / button&gt; 
&lt; / form&gt;  &lt; / div&gt; 
&lt; div class =“modal-footer”&gt; 
&lt; button type =“button”class =“btn btn-info”data-dismiss =“modal”&gt; close&lt; / button&gt  ; 
&lt; / div&gt; 
&lt; / div&gt; 
 
&lt; / div&gt; 
&lt; / div&gt; 
   
 
 

此处示例 操作页面:

 &lt;?php 
 if(isset($ _ POST ['signup']))
 {
 if(empty($ _ POST ['user)  '])|| empty($ _ POST ['email'])|| empty($ _ POST ['pwd']))
 {
 echo $ lang ['empty']; 
} 
} 
  ?&gt; 
   
 
 

我希望在同一个对话框中查看结果。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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
        }
    });
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题