Let me preface that it has been 20 years or so since I’ve worked in PHP, just to set expectations on the code.
I have a web page with a form on it. I want, on submit, to validate the form contents in my PHP script; if valid, do something with it, then redirect the user to the same page and pop up an alert that says either Thanks, we got your message, or There was an error.
My code so far is this:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//validate form
$isValid = FALSE;
//redirect
$referer = $_SERVER['HTTP_REFERER'];
header("Location: $referer");
//display message
echo "<script type='text/javascript'> window.onload=showAlert('test message'); </script>";
}
?>
The form validation I can handle, the page redirect is working, the alert is not. I tried to echo a script with just the alert(message) in it but that did not work. Poked around on SO and found a suggestion to call a Javascript function onload but that did not work either.
Would appreciate any help on this.