简体   繁体   English

jQuery Bootstrap模态PHP

[英]Jquery Bootstrap modal PHP

I have a form with many fields and when I click the submit button, before saving the data in my database, I would like to show a bootstrap modal popup that displays a question to the user. 我有一个包含很多字段的表单,当我单击提交按钮时,在将数据保存到数据库之前,我想显示一个引导模式弹出窗口,向用户显示问题。 The user can answer "yes" or "no" to the question. 用户可以对问题回答“是”或“否”。 In these two cases, the data will be saved in the database. 在这两种情况下,数据将保存在数据库中。 The difference between the "yes" and "no" button is the action. “是”和“否”按钮之间的区别在于操作。

I get some trouble to manage with this. 我在管理上有些麻烦。 I know that Ajax and PHP are required but I do not really know how to do the trick. 我知道Ajax和PHP是必需的,但我真的不知道该怎么做。

A hand would be appreciate. 一只手将不胜感激。

Sorry for my poor english. 对不起,我英语不好。

You just need to call the modal when the submit is clicked. 单击提交时,您只需要调用模式即可。 Then, do the ajax call based on what the user clicked. 然后,根据用户单击的内容进行ajax调用。

SOme like this: 这样的SOme:

HTML 的HTML

//Submit Button
<div class="form-group">
    <button id="submit" name="submit" class="btn btn-primary">Submit</button>
</div>

//Modal to ask for confirmation
<div id="confirm" class="modal hide fade">
  <div class="modal-body">
    Are you sure?
  </div>
  <div class="modal-footer">
    <button type="button" data-dismiss="modal" class="btn btn-primary" id="yes">Yes</button>
    <button type="button" data-dismiss="modal" class="btn" id="no">No</button>
  </div>
</div>

Then, you just need to add listeners to each button and do the corresponding action. 然后,您只需要向每个按钮添加侦听器并执行相应的操作。

Javascript Java脚本

<script type="text/javascript">

    //If user submits, show modal.
    $("#submit").click(function() {
        showModal();
    });

    //If user selects Yes, do action A.
    $("#yes").click(function() {
        doAjax_A();
    });

    //If user selects No, do action B.
    $("#no").click(function() {
        doAjax_B();
    });

</script>

All thats left is to do your Ajax Call. 剩下的就是打您的Ajax电话。 More on: http://api.jquery.com/jquery.ajax/ 有关更多信息: http : //api.jquery.com/jquery.ajax/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM