0

How can I prevent the ordermodal.php from closing when I click a button even it refresh?

What I want to happen is when I click a button it will refresh the modal, BUT it will not CLOSE the modal either.

It is event handler? Im not sure tho.

This is my code for ordermodal.php

<?php

include_once 'ordermodal2.php';

/** *ordermodal.php **/

$id = "";
$order_date = "";
$order_time = "";
$order_id = "";
$order_deliverCharge = "";
$order_status = "";
$order_totalAmount= "";
$coordinates = "";
$driver_number = "";
$address = "";


$food_name="";
$special_request="";
$quantity="";
$amount="";
$orders="";

?>

<!-- MODALS --> <!-- DETAILS -->
<div id="myModal" class="modal fade" role="dialog" style="z-index: 1400;">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <form action="" method="post" class="form-horizontal">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><center>&times;</button>
          <h4 class="modal-title" id="titleModal">Order Information</h4>
        </div>
        <div class="modal-body">

          <div class="form-group">
            <label for="order_id" class="col-sm-2 control-label">Order ID</label>
            <div class="col-lg-3">
              <input type="text" input style="width:500px" class="form-control" name="ORDER_ID" id="ORDER_ID" placeholder="" value="" required="required" readonly>
            </div>
          </div>

          <div class="form-group">
            <label for="id" class="col-sm-2 control-label">User ID</label>
            <div class="col-lg-3">
              <input type="text" input style="width:500px" class="form-control" name="user_id" id="user_id" placeholder="" value="" required="required" readonly>
            </div>
          </div>

          <div class="form-group">
            <label for="order_date" class="col-sm-2 control-label">Order Date</label>
            <div class="col-lg-3">
              <input type="text" input style="width:500px" class="form-control" name="order_date" id="order_date" placeholder="" value="" required="required" readonly>
            </div>
          </div>

          <div class="form-group">
            <label for="order_time" class="col-sm-2 control-label">Order Time</label>
            <div class="col-lg-3">
              <input type="text" input style="width:500px" class="form-control" name="order_time" id="order_time" placeholder="" value="" required="required" readonly>
            </div>
          </div>

          <div class="form-group">
            <label for="order_deliverCharge" class="col-sm-2 control-label">Delivery Charge</label>
            <div class="col-lg-3">
              <input type="text" input style="width:500px" class="form-control" name="order_deliveryCharge" id="order_deliveryCharge" placeholder="" value="" required="required" readonly>
            </div>
          </div>

          <div class="form-group">
            <label for="order_totalAmount" class="col-sm-2 control-label">Total Amount</label>
            <div class="col-lg-3">
              <input type="text" input style="width:500px" class="form-control" name="order_totalAmount" id="order_totalAmount" placeholder="" value="" required="required" readonly>
            </div>
          </div>

          <div class="form-group">
            <label for="address" class="col-sm-2 control-label">Address</label>
            <div class="col-lg-3">
              <input type="text" input style="width:500px" class="form-control" name="address" id="address" placeholder="" value="" required="required" readonly>
            </div>
          </div>

          <div class="form-group">
            <label for="coordinates" class="col-sm-2 control-label">Coordinates</label>
            <div class="col-lg-3">
              <input type="text" input style="width:500px" class="form-control" name="coordinates" id="coordinates" placeholder="" value="" required="required" maxlength="11" readonly>
            </div>
          </div>

          <div class="form-group">
            <label for="driver_number" class="col-sm-2 control-label">Driver Number</label>
            <div class="col-lg-3">
              <input type="text" input style="width:500px" class="form-control" name="drivers_number" id="drivers_number" placeholder="" value="" required="required" readonly>
            </div>
          </div>

          <div class="form-group">
            <label for="order_status" class="col-sm-2 control-label">Order Status</label>
            <div class="col-lg-3">
              <input type="text" input style="width:500px" class="form-control" name="order_status" id="order_status" placeholder="" value="" required="required" readonly>
            </div>
          </div>

          <?php
          $order_id = trim(addslashes($_POST['ORDER_ID']));
          $sql = "SELECT food_name, special_request, quantity, amount
            FROM cart_tbl
            WHERE order_id=$order_id";
          $result = mysqli_query(connection2(), $sql);
          ?>
          <table class="table table-hover table-bordered">
            <thead>
              <tr>
                <th>Food</th>
                <th>Special Request</th>
                <th>Quantity</th>
                <th>Amount</th>
              </tr>
            </thead>
            <?php
            if(mysqli_num_rows($result)>0)
            {
              while($row = mysqli_fetch_array($result))
              {
              ?>
              <tr>
                <td><?php echo $row["food_name"];?></td>
                <td><?php echo $row["special_request"];?></td>
                <td><?php echo $row["quantity"];?></td>
                <td><?php echo $row["amount"];?></td>
              </tr>
              <?php
              }
            }
            ?>

          </table>
        </div>
        <div class="modal-footer"> //This are the buttons
          <button type="submit" input style="background-color:#00000;color:white;float:left" name="showfood" id="showFood" class="btn btn-primary " onclick="if(!confirm('Are you sure you want to see food order?')){return false;}"> Show Food </button>
          <button type="submit" input style="background-color:#4CAF50;color:white" name="submitDelivered" id="submitDelivered" class="btn btn-primary " onclick="if(!confirm('Are you sure you want to deliver order?')){return false;}" > Delivered </button>
          <button type="submit" input style="background-color:#0000FF;color:white" name="submitAccept" id="submitAccept" class="btn btn-primary" onclick="if(!confirm('Are you sure you want to accept order?')){return false;}" > Accept </button>
          <button type="button" style="background-color:#FFFF00;color:black" class="btn btn-success" data-toggle="modal" data-target="#myDropdown" onclick="send('<?= $_POST['order_id'] ?>')"> Send </button>
          <button type="submit" input style="background-color:#f44336;color:white" name="submitCancel" class="btn btn-danger" onclick="if(!confirm('Are you sure you want to cancel order?')){return false;}">Cancel</button>
          <?php
          if(isset($_POST['submitDelivered'])){
            $order_id = trim(addslashes($_POST['ORDER_ID']));
            $query = "UPDATE order_tbl SET `order_status`='Delivered' WHERE `order_id` = $order_id";
            if (mysqli_query(connection2(), $query)) {
              mysqli_query(connection2(), "COMMIT");
              $_SESSION['message'] = "Order Delivered";
            } else {
              $_SESSION['message'] = mysqli_error(connection2());
              mysqli_query(connection2(), "ROLLBACK");
            }
          }

          if(isset($_POST['submitAccept'])){
            $order_id = trim(addslashes($_POST['ORDER_ID']));
            $query = "UPDATE order_tbl SET `order_status`='Accepted' WHERE `order_id` = $order_id";
            if (mysqli_query(connection2(), $query)) {
              mysqli_query(connection2(), "COMMIT");
              $_SESSION['message'] = "Order Accepted";
            } else {
              $_SESSION['message'] = mysqli_error(connection2());
              mysqli_query(connection2(), "ROLLBACK");
            }
          }


          if(isset($_POST['submitCancel'])){
            $order_id = trim(addslashes($_POST['ORDER_ID']));
            $query = "UPDATE order_tbl SET `order_status`='Cancelled' WHERE `order_id` = $order_id";
            if (mysqli_query(connection2(), $query)) {
              mysqli_query(connection2(), "COMMIT");
              $_SESSION['message'] = "Order Cancelled";
            } else {
              $_SESSION['message'] = mysqli_error(connection2());
              mysqli_query(connection2(), "ROLLBACK");
            }
          }

          ?>

        </div>
      </form>
    </div>
  </div>
</div>
<script>
function send(order_id) {
  document.getElementById("titleModal2").innerHTML = "Choose Driver";
  document.getElementsByName("ORDER_ID_MODAL_2")[0].setAttribute("value", order_id);
  document.getElementsByName("send")[0].setAttribute("name", "send");
}
</script>
Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
One Punch
  • 37
  • 1
  • 5
  • `data-dismiss="modal"` is what making the modal close... If that is the question. – Louys Patrice Bessette Sep 17 '17 at 05:58
  • @Louys , Nah dude, it still closing :( – One Punch Sep 17 '17 at 06:51
  • you need jquery for this – Gagantous Sep 17 '17 at 06:54
  • @Gagantous Im not familiar with jquery man. Im stucked at this problem a couple of days already :( – One Punch Sep 17 '17 at 07:02
  • It looks a bit like you're using Bootstrap?! If so, check out this question https://stackoverflow.com/q/16152073/5039312 – Marco Sep 17 '17 at 07:10
  • @Marco The modal is not closing but when I click the buttton it will close. I need to click that button. Can I/how I use this data-backdrop="static" data-keyboard="false" in my button? – One Punch Sep 17 '17 at 07:33
  • @OnePunch You would add it to the button that opens your modal. – Marco Sep 17 '17 at 07:51
  • @Marco Thats not what I want to happen dude. What I want to happen is even I click a button INSIDE my MODAL, my modal will not close. So its not the same button – One Punch Sep 17 '17 at 08:00
  • @OnePunch: That isn't just your modal that close when you click on the buttons in your modal-footer, but **the whole page reloads** because you are submitting the data back to server-side to "refresh" all your read-only form. -- You **will** need to learn jQuery and Ajax to do what you want... Or hire a coder. – Louys Patrice Bessette Sep 17 '17 at 14:22

0 Answers0