如何在Modal中提交表格?

时间:2019-05-20 06:37:45

标签: javascript php html

提交表单时遇到问题,该页面不直接进入下一个PHP页面,而是转到主页。

  

(entry_pbd.php)

这是我的模式代码。

<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

            <!-- body modal -->
            <div class="modal-body">
                <form action="entry_pbd.php" class="form-horizontal" method="POST" id="form-save">
                    <div class="panel-group" id="price1">
                        <div class="panel panel-default">
                            <div class="panel-title">
                                <a data-toggle="collapse" data-parent="#billto" href="#collapse1" id="billto" class="btn btn-default btn-block">
                                    <b>Price 1 </b></a>
                            </div>
                        </div>
                        <div id="collapse1" class="panel-collapse collapse ">
                            <ul class="list-group">
                                <label> Minimum Order Quantity (MOQ)</label>
                                <input class="form-control" type="text" placeholder="Minimum Order Quantity" id="moq_1" name="moq_1" style="text-transform:uppercase" /> <br></br>
                                <label>Unit Price</label>
                                <input class="form-control" type="text" placeholder="Unit Price" id="up_1" name="up_1" style="text-transform:uppercase" />
                            </ul>
                        </div>
                    </div>
<div class="modal-footer">                               
        <button style="margin-top: 10px" class="btn btn-success" type="submit"> Submit</button>
        <button style="margin-top: 10px" class="btn btn-warning" type="reset"> Reset</button>
        </div>
                </form>
            </div>

这是entry_pdb.php示例代码

<?php

$id_form = $_POST['id_form'];
$id_pur = $_POST['id_purchase'];
$moq_1 = $_POST['moq_1'];$up_1 = $_POST['up_1'];

if ($moq_1 != "")
{
$sql = "insert into pbd_pur values ('1','$id_form','$moq_1','$up_1')";
$hasil = mysqli_query($connect2,$sql);  
}
echo $sql;
$link = "update_p.php?id=".$id_pur;
//echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$link.'">';
?>

在模态提交表单后,我只想在entry_pdb.php中查看消息(错误或成功)。

1 个答案:

答案 0 :(得分:1)

在记录保存代码下方的php文件中写入重定向代码。喜欢

任何一个

header("Location: http://www.redirect.to.url.com/"); // pass your file path ,where you want to navigate

或者(如果您使用的是cakePHP)

$this->redirect(array('controller' => 'my_controller', 'action' => 'my_action'));  // if you are using cake php