How To Open A Bootstrap Modal With PHP?
Solution 1:
I think that for this purpose it's not very important whether validation is done client side or not. You can change it to client side validation if you wish, but the script you are adding isn't working because it's running before the necessary html elements are loaded. To ensure it runs after, change that line to
if ($error) { ?>
<script type="text/javascript">
$(document).ready(function() {
$('#myModal').modal('show');
});
</script>
<?php
} else {
...
The script is added only when there is an error, so it will run when loaded but only when the page is reloaded after submission and errors were found.
Solution 2:
I had the same problem and solved it:
You had to echo
the script because when you end the php code ?>
and start it again <?php
the code between the end and start will be ignored or always visable/enable. See the exemple below i think that will work!
if ($error) { ?>
<script type="text/javascript"> $('#myModal').modal('show'); </script>
<?php
}
Has to be
if ($error) {
echo '<script type="text/javascript"> $("#myModal").modal("show")</script>';
}
The '
in the script are replaced with "
because a '
will ignore "
so it just echo it
Some other things in your code: At the if ($error)
or if (!$_Post[...])
It wont work because there is no requirement like $error = 1
or T$_Post[...] > "1"
in this case the if will never run
and here :
if (mail("dprb17@gmail.com", "RSVP", "
Name: ".$_POST['name']."
Head Count: ".$_POST['head-count']."
Reception Check: ".$_POST['reception-check']."
Comments: ".$_POST['comments'])) {
header("location: http://www.ourpeachwedding.com/pages/thankyou.php");
exit();
There is no consequence
I think when this work it will be very nice! I hope this will work! Good Luck.... and check your code.
Post a Comment for "How To Open A Bootstrap Modal With PHP?"