0

Been trying to use modal to create a notification window which notifies the user that the record was successfully created. The idea is that a session confirm is set to yes at the end of the query, and on return to the form page, a modal will pop up for a fixed amount of time, i.e. 2 seconds, notifying the user that the record was successfully added to the table.

Ive been playing around with w3 tutorials but no luck, biggest struggle is trying to understand how to call the modal automatically on page load. This type of modal is perfect, but im unsure how to get rid of the button and automatically load & close on timer.

https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal_sm&stacked=h

Within an IF statement. Code on the php page, to feature the modal below:

<?php
    $confirmation = strip_tags($_SESSION['confirm']);
    if ($confirmation == 'yes') {
        echo '<div id="confirm_msg">';
        echo 'Record has been successfully created.';
        $_SESSION["confirm"] = 'No';
        echo '</div>';
    }
?>  

Ideally, id like to swap the #confirm_msg with an automatic modal, that closes after a few seconds.

sanitizer
  • 95
  • 3
  • 14

2 Answers2

1

i think you can set your modal to be loaded at the same time of your body page which mean whenever you run that page it will open up with an open modal follow this link How to make modal dialog open at page load in bootstrap

and then after that you can set a period of time that you want your modal to be loaded How to automatically close Bootstrap 3 modal after time period

when it closed direct it to the location you want

Community
  • 1
  • 1
Hirwa Jean
  • 39
  • 4
  • Thanks Jarel, you have definately pointed me in the right direction. Managaed to get the modal working as required, still working on the timer but ill get there! – sanitizer Mar 01 '17 at 11:20
0

To display the modal form, only when the user has returned from the mysql update qry page & session confirm = yes. No auto-timer implemented. But modal works perfectly.

<?php
$confirmation = strip_tags($_SESSION['confirm']);
if ($confirmation == 'yes') { ?>
<script>
    $(document).ready(function(){
    $('#myModal').modal('show')
    });
</script>
<div class="container">
    <div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Notification</h4>
                </div>
                <div class="modal-body">
                    <p>The record has been created successfully.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</div>
sanitizer
  • 95
  • 3
  • 14