Franksye Sipangkar
Franksye Sipangkar

Reputation: 139

How to submit form in Modal?

I have a problem when I submit form, this page is not direct to next PHP page but go to main page.

(entry_pbd.php)

This my modal code.

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

This is entry_pdb.php sample code

<?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.'">';
?>

I just want to look message (error or success) in entry_pdb.php after submit form in modal.

Upvotes: 0

Views: 80

Answers (1)

Neeraj Amoli
Neeraj Amoli

Reputation: 1026

write redirection code in your php file just below record saving code. like

Either

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

Or (if you are using cakePHP)

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

Upvotes: 1

Related Questions