简体   繁体   English

PHP没有出现在下一个模式中

[英]PHP not showing up on next modal

I'm trying to show what the user inputted on a new modal but it's not showing up. 我试图显示用户在新模态上输入的内容,但没有显示出来。

This gets the input (first modal) 这得到输入(第一个模态)

<div class="modal fade" id="shipping" role="dialog">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h1 id= "modalHeader" class="modal-title"></h1>
            </div>
            <div align="center" id="imageinfo" class="modal-body">
              <div>
                         <h3 id= "modalHeader"><strong>Shipping Information</strong></h3>
                            <br />

                            <form action="index.php" method="post">
                                <label><b>First Name</b></label>
                                <br />
                                <input type="text" placeholder="Enter First Name" name="fname" required>
                                <br /><br />
                                <label><b>Last Name</b></label>
                                <br />
                                <input type="text" placeholder="Enter Last Name" name="lname" required>
                                <br /><br />
                                <label><b>Address</b></label>
                                <input type="address" placeholder="Enter Address" name="address" required> 
                                <br />
                            <div class="modal-footer">
                            <input type="submit" class="btn btn-default" value="Confirm Address" data-dismiss="static">
                            <button type="submit" class="btn btn-default invoice" data-dismiss="modal">Final Invoice</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                          </div>
                            </form>
              </div>
            </div>
          </div>
        </div>
      </div>

This outputs the info 这输出信息

 <div class="modal fade" id="final" role="dialog">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h1 id= "modalHeader" class="modal-title"></h1>
            </div>
            <div align="center" id="imageinfo" class="modal-body">
              <div>
                  <h3 id= "modalHeader"><strong>Final Invoice</strong></h3>
                  <div class="item">

                                        <div class="invoice">
                                        First Name: <?php echo $_POST["fname"]; ?><br>
                                        Last Name: <?php echo $_POST["lname"]; ?><br>
                                        Address: <?php echo $_POST["address"]; ?><br>
                                        </div>
                  <br />
              </div>
            </div>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>

Also in the input modal you can see that there two buttons "confirm address" and "Final invoice" the confirm address is so that it will validate the info and then the "Final invoice" button will go to the next modal and display it. 同样在输入模式中,您可以看到有两个按钮“确认地址”和“最终发票”,确认地址是这样,它将确认信息,然后“最终发票”按钮将转到下一个模式并显示它。

I use this in my js so that after I click the confirm address it doesn't close 我在我的js中使用它,以便在单击确认地址后它不会关闭

$(document).ready(function() {
  $("form").submit(function() {
    return false;
  })
});

Follow this steps- 请按照以下步骤操作:

  1. Use Ajax to submit the form. 使用Ajax提交表单。
  2. Change the input type submit to button 将输入类型更改为提交到按钮
  3. On success open another modal. 成功后,打开另一个模式。

To get a simple POST version of this working: try removing the data-dismiss attribute from your submit button that you actually want to work, so instead of: 要获得此工作的简单POST版本:请尝试从您实际想要工作的“提交”按钮中删除data-dismiss属性,而不是:

<button type="submit" class="btn btn-default invoice" data-dismiss="modal">Final Invoice</button>

Try: 尝试:

<button type="submit" class="btn btn-default invoice">Final Invoice</button>

Looks like you're using Bootstrap's modal framework, which stops the usual submit event for the button propagating if it has data-dismiss on it. 似乎您正在使用Bootstrap的模式框架,如果该按钮上有data-dismiss ,它将停止按钮传播的常规Submit事件。 This should then trigger a normal browser reload as usual. 然后,这应该会像往常一样触发正常的浏览器重新加载。

However, if you want the users of the site to stay in the modal etc, then you'll need to submit the form via some kind of AJAX. 但是,如果您希望网站的用户停留在模态等中,则需要通过某种AJAX提交表单。

I assume this is a single page then Why you are using form in first modal if you just want to display the detail in 2nd modal? 我假设这是一个页面,那么如果您只想在第二个模态中显示详细信息,那么为什么在第一个模态中使用表单? You can simply access this details using jQuery? 您可以简单地使用jQuery访问此详细信息吗?

In your jQuery you need to create two functions. 在您的jQuery中,您需要创建两个函数。 1st for validate the address 2nd for opening the second modal. 第一个用于验证地址,第二个用于打开第二模式。

$(document).ready(function(){
   function validateaddress(address){
     //code to validate address
      if(validate){
      return true; 
      }else{
      return false;
      }
   }

   $("#finalinvoice").click(function(e){
    e.preventDefault();
    var fname = $("#fname").val();
    var lname = $("#lname").val();
    var address = $("#address").val();
    if(validateaddress(address)){
      //Assign value in second model
        $("#showfname").text(fname);
        $("#showlname").text(lname);
        $("#showaddress").text(address);
        $("#final").modal("show");
    }else{
       //Show error for incorrect address
     }
   });

    $("#validateaddress").click(function(e){
    e.preventDefault();
    if(validateaddress($("#address").val())){
     $("#finalinvoice").trigger("click");
     }else{
         //show error
      }

    });
});

Change your code with below code 使用以下代码更改代码

 <div class="modal fade" id="shipping" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h1 id= "modalHeader" class="modal-title"></h1>
        </div>
        <div align="center" id="imageinfo" class="modal-body">
          <div>
                     <h3 id= "modalHeader"><strong>Shipping Information</strong></h3>
                        <br />

                            <label><b>First Name</b></label>
                            <br />
                            <input type="text" id="fname" placeholder="Enter First Name" name="fname" required>
                            <br /><br />
                            <label><b>Last Name</b></label>
                            <br />
                            <input type="text" id="lname" placeholder="Enter Last Name" name="lname" required>
                            <br /><br />
                            <label><b>Address</b></label>
                            <input type="address" id="address" placeholder="Enter Address" name="address" required> 
                            <br />
                        <div class="modal-footer">
                        <input type="button" id="validateaddress" class="btn btn-default" value="Confirm Address" data-dismiss="static">
                        <button type="button" id="finalinvoice" class="btn btn-default invoice" data-dismiss="modal">Final Invoice</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                      </div>

          </div>

        </div>
      </div>
    </div>
  </div>

2nd modal 第二模态

 <div class="modal fade" id="final" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h1 id= "modalHeader" class="modal-title"></h1>
        </div>
        <div align="center" id="imageinfo" class="modal-body">
          <div>
              <h3 id= "modalHeader"><strong>Final Invoice</strong></h3>
              <div class="item">

                                    <div class="invoice">
                                    First Name: <span id="showfname"></span>
                                    Last Name: <span id="showlname"></span>
                                    Address: <span id="showaddress"></span>
                                    </div>
              <br />
          </div>
        </div>
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>

remove this 删除这个

$(document).ready(function() {
$("form").submit(function() {
return false;
 })
  });

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

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