1

I want a modal popup after an if-statement is satisfied. The following is a sample of the code:

<form action="" method="post">
<button type="submit" name="btn">Test</button>
</form>

<?php
 if (isset($_POST['btn'])) {
//then trigger the modal pop-up
}
?>
DarkBee
  • 16,592
  • 6
  • 46
  • 58
progr
  • 31
  • 2
  • 6
  • 3
    use javascript to trigger modal to show – Haziq Ahmed Jan 10 '18 at 10:02
  • You can output the modal markup, if your css handles that correctly, it will be displayed as a "modal window". Usually you would handle such things with javascript - as it almost always requires user interaction (close modal for example). – Philipp Wrann Jan 10 '18 at 10:04
  • Look at https://stackoverflow.com/questions/10233550/launch-bootstrap-modal-on-page-load – dhinchliff Jan 10 '18 at 10:09

1 Answers1

2

If you want open modal window then you have to use javascript / jquery as shown below

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<form action="" method="post">
<button type="submit" name="btn">Test</button>
</form>

<?php if (isset($_POST['btn'])) { ?>

<script>
$(function() {
$("#myModal").modal();//if you want you can have a timeout to hide the window after x seconds
});
</script>

<!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Sample modal window</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

<?php } ?>
DarkBee
  • 16,592
  • 6
  • 46
  • 58
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40