wantTheBest
wantTheBest

Reputation: 1720

tell browser to discard prior form post

I have noticed the following with my page "thePage.php". My page thePage.php has a form on it where the user can enter their name and email and click a submit button.

1) If I arrive at thePage.php due to a user clicking a link from a different page, thePage.php is called from the server. Here is the html that has the link that, when clicked on, retrieves thePage.php from the server and displays it in the browser:

<div>
    <a id="logged-in-status" hef="http://mySite/thePage.php"> Click to go to the data entry page</a>      
</div>

After thePage appears in the browser, having been retrieved from the server, I can click the browser 'reload' button and I get a page reload from the server and nothing else.

The above div appears on my index.php landing page. When the user clicks the above link, thePage.php is requested from the server and displayed in the browser. thePage.php has an 'enter name and email' form on it. After thePage.php loads -- with the blank, not-yet-filled-out-or-submitted form on it -- if I click the 'reload' button in the browser the page simply reloads. No message box warning 'about to re-send info' appears -- just a page reload.

2) HOWEVER -- if the user does or does not enter any form data (doesn't matter) then pushes the 'submit' button -- after this first submit of the form, the reload behavior in (1) above is lost. Even if the form is left blank and the user presses 'submit' the browser seems to set a 'dirty bit' internally -- so that when the browser reload button is clicked, the browser seems to say "Oh look -- there is apparently a form on this page -- and it has been submitted at least once -- I'm going to ignore the outcome of that form submission, and from now on -- since the form has been submitted once -- I'm no longer going simply reload the page. I'll display a message box about 're-sending previously submitted info'"

Here's what I want to do. I want to clear that 'dirty bit' that the browser sets internally so that, even if a form on a page was submitted -- I want the browser to go back to behaving as in (1) above, as if I had just clicked a link on another page that led me to thePage so that the browser 'forgets' that a form on the page was submitted.

There must be a way to do this. If you think about it -- if a link to thePage.php is clicked from elsewhere, the 'dirty bit' gets cleared and thePage reload behavior is as in (1) above, without the 're-send info' message box in (2) above.

Is there a programmatic way to tell the browser "look -- pretend I just got here from an off-page link to thePage.php, okay? Just forget all prior form submissions on this page. Thank you very much."

Upvotes: 0

Views: 146

Answers (1)

Zac
Zac

Reputation: 1635

Once you have parsed the form data in the php script then just use header() to send them back to the page instead. This will prevent the resend data notice.

<?php
////Parse form
header("Location: http://Wherever");
exit();
?>

If you need to know the form was submitted successfully/unsuccessfully just send with a $_GET and pick that up.

?php
////Parse form
header("Location: http://Wherever?notice=successful");
exit();
?>

Upvotes: 1

Related Questions