Page 1 of 1

Problem when reloading PHP page

Posted: Mon May 02, 2011 8:12 pm
by arzoo
I noticed something bothersome when I have a page that whose text fields are are filled data retrieved from POST. This is fine, but when the user suddenly opts to press <enter> in the address bar, the page reloads but this time without the posted data, so kinda messing things up. If the user reloads the page with the refresh button things are ok. This is in firefox.

Here's a simple example to illustrate. This is the form portion of a page that will POST to test.php:

Code: Select all

<form action="test.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
Then here's test.php which retrieves the POST and prints them.

Code: Select all

Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
All works fine. But after test.php loads properly, if the user chooses to press <enter> on the address bar which has http:localhost/.... test.php, it reloads test.php but this time without the POSTed data.

Re: Problem when reloading PHP page

Posted: Tue May 03, 2011 8:38 am
by oscardog
That is exactly what should happen and will happen, and unless you store the data in a session or something (which I wouldn't recommend as the chances are if a person is doing that they don't want their data).

When you do what you described it essentially just creates a fresh page, as it would look for the first load.