Reputation: 93
Question is simple ,
I have a form submission after successful submission of form , i want to print Alert massage on next page that "Form successfully submitted !" ?
using php and jscript
Upvotes: 1
Views: 1350
Reputation:
I learned this approach from Laravel, its called flash message. Basically you set some variable in the session (your choice in naming)
//from your originating page
<?php
$_SESSION["flash"] = array();
$_SESSION["flash"]["message"] = "Your message";
$_SESSION["flash"]["status"] = "error";
?>
<?php
//to your destination page
if(isset($_SESSION["flash"])){
echo $_SESSION["flash"]["message"];
//or
echo "<script>alert('{$_SESSION["flash"]["message"]}');</script>";
unset($_SESSION["flash"]);
}
?>
Upvotes: 1
Reputation: 348
After saving the form you can redirect user on a page with alert script using:
// PHP
header('Location: http://www.example.com/path_to_page');
Then on that page you can add js
// Js (include jquery before it)
<script>
$(document).ready(function(){
alert('Form successfully submitted!');
});
</script>
If you are not using jquery then use:
<body onload="alert_call()">
<!-- your page content -->
<script>
function alert_call(){
alert('Form successfully submitted!');
}
</script>
</body>
Upvotes: 1