So, I have these two pages: pageOne.php and pageTwo.php . The form is in pageOne.php :
<form method="post" action="pageTwo.php"> .... </form>
and after completing the entire build-data validation and sending emails in pageTwo.php (the reason I do everything on two separate pages is to avoid re-sending the data when the page is refreshed ... it was the easiest way to deal with this problem). So far, everything is working fine.
Now I want to display a success / failure message using the notification field after submitting the form, and have tried several things without any luck. For instance. when I tried THIS solution on pageTwo.php , the popup does not appear and I think that since I have this header on top of this page
<?php header("Location: http://TestPages.com/pageOne.php"); ?> <?php if( $_POST ) {
And when you tried this second solution in pageOne.php , I get a warning window that appears every time I refresh the page and get an error message, even if the data was inserted into the database and the letters were sent. pageOne.php :
<html> <body> <?php if( $GLOBALS["posted"]) <form method="post" action="pageTwo.php"> .... </form> </body>
and pageTwo.php :
<?php header("Location: http://TestPages.com/pageOne.php"); ?> <?php $posted = false; if( $_POST ) { $posted = true;
Why is this simple thing not working :( is there any simple way to fix it? Thanks!
UPDATE
So, I made some changes according to drrcknlsn sugession, and this is what I still have .... pageOne.php :
<?php session_start(); if (isset($_SESSION['posted']) && $_SESSION['posted']) { unset($_SESSION['posted']); <html> <body> <form method="post" action="pageTwo.php"> .... </form> </body> </html>
and pageTwo.php :
<?php session_start(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $_SESSION['posted'] = true;
The page redirection and success message now works with these changes, but I get an error message every time I open / refresh the page (I know because the session key is not set yet) ... how can I avoid this? Thanks again!!