1

I have a HTML form completed by the user and then submitted via the Post action into a PHP script. It validates the data and uploads the info to a DB. All good. at the end of the PHP script I want to open a bootstrap modal. i.e. without the user clicking another button to launch it. The modal I have works fine if you use the modal button like so

<button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal">Open Modal</button>

I've tried a few ways to get it to run in the PHP script, this looking like the most promising:

echo '<script>$("#myModal").modal({show: true});</script>';

But no luck. I'm a complete noob when it comes to JS!

Stu
  • 23
  • 2
  • 6
  • You want to open a modal where you can submit data through form ? Or, you want success/failure message in modal after submitting ? – Nana Partykar Nov 10 '15 at 18:00
  • After the script is finished I just want the modal box to popup. The simple version is, how do I open a modal box from a PHP script? – Stu Nov 10 '15 at 18:54

3 Answers3

0

Few functions of bootstrap modal.

$('#myModal').modal('toggle');
$('#myModal').modal('show');
$('#myModal').modal('hide');

Change this

$('#myModal').modal({show: 'false'}); 

To

$('#myModal').modal('show'); 

For more info, click This

Community
  • 1
  • 1
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
  • If you look my example says ``modal({show: true})`` . I've tried the example you suggested also. – Stu Nov 10 '15 at 18:55
0

Sorry I should have just looked a bit harder. The answer is just that you need to wrap jquery in a function when calling from PHP.

jQuery(function(){
    //Your Code
});
Stu
  • 23
  • 2
  • 6
0

You can use javacript window load function to trigger button and call modal without clicking the button and button can bi hidden also. Here is your PHP code:

echo "<script type='text/javascript'> $(window).load(function(){ $('#myModal').modal('show'); }); </script>";

You can use some 'if' conditions to determine when trigger will be triggered.

Aleksandar
  • 55
  • 5