I’m working on several forms right now for a website, and I would like to have a custom pass/fail notification after submission on the same page as the form:
$get = $_GET;
$post = $_POST;
ob_start();
header('Location: ' . $_SERVER['PHP_SELF']);
ob_end_flush();
submit_form($get, $post) ? print('passed') : print('failed');
The submit form function works fine, but the print statements are not showing up – I’m not sure what the flaw in my logic is here, and would really appreciate some assistance.
So, basically this is a question of messaging. If your redirect is within the same site and you’ll have access to the php of the ending page, then you should do the following:
Use the $_SESSION variable to store a custom variable called “system-message” or whatever you want to call it. (remember, to use $_SESSION, you need to call “session_start()” at the beginning of each php file.)
Upon success of your form, say
THEN call your header redirect.
In the ending page, have it look for a possible system message by doing something like this:
Then empty out that variable so it doesn’t show up every time you go to a new page… (you want it to only show one time…)