I am currently using a Bootstrap 3 Alert div
to flash a message when a transaction is completed. The Alert contents is coming from a header (location) from the previous page.
Above the closing /body tag:
</script>
<script type="text/javascript">
window.setTimeout(function() {
$(".alert").fadeTo(500, 0).slideUp(500, function(){
$(this).remove();
});
}, 4000);
</script>
And my Alert:
<div class="bs-example">
<div class="alert alert-success" id="success-alert" style="font-size:120%;">
<a href="#" class="close" data-dismiss="alert">×</a>
<?php
$email = $_GET['e'];
$receipt = $_GET['r'];
if (isset($_GET["msg"])) {
$msg = $_GET["msg"];
if ($msg == "1") {
echo "Receipt $receipt was sent to $email.";
} else {
echo "Message was not sent.";
}
}
?>
</div>
</div>
The Alert div
shows up even if the $_GET
's are not there. In other words on load before I do anything the div
is there blank. I want the user to complete the form on my page and be redirected with the URL?msg=1 to same page with the Alert message showing. Other than that the div
does not have to show.
You need to wrap the alert code inside a PHP if statement where you can check if the $_GET variable are set.
<?php if(isset($_GET['e']) && isset($_GET['r'])) { ?>
<div class="bs-example">
<div class="alert alert-success" id="success-alert" style="font-size:120%;">
<a href="#" class="close" data-dismiss="alert">×</a>
<?php
$email = $_GET['e'];
$receipt = $_GET['r'];
if (isset($_GET["msg"])) {
$msg = $_GET["msg"];
if ($msg == "1") {
echo "Receipt $receipt was sent to $email.";
} else {
echo "Message was not sent.";
}
}
?>
</div>
</div>
<?php } ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.