Welcome to WebmasterWorld Guest from 54.166.220.138

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP not remembering $ POST variables

$_POST variables dissapearing

     
10:11 am on Sep 15, 2006 (gmt 0)

5+ Year Member



Hi,

I wonder if any one can help me..

I am developing a drawing register for the company i work for on our intranet. We recently got a new server (Windows 2003), so i installed PHP and MySQL on it.

When a user fills in a web form (i'll call it form.php) on the intranet i make the form post the variables to another file (form-parse.php) which parses the data. If they have not entered the required information i display the form errors on the form-parse.php telling them to go back to the original form and correct them.

My problem is that when they click the back button on the browser the $_POST variables are lost from the form.

I have included value="<? echo $_POST[variable1];?>" for each of the relevant <input> tags in the original form, so i know its not that.

Could it be a setting in the php.ini file or is this something to do with the server settings and this post is in the wrong forum completely.

Thanks in advance

Seamless

11:56 am on Sep 15, 2006 (gmt 0)

5+ Year Member



The data has been POSTed to form-parse.php (not form.php) and so no post array exists for form.php and this is why it's not working as expected.

You could start a session and save the post data in the session array and so then if you needed to go back to form.php you could call the values from the session data.

1:34 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



You could post it to the same page and us an IF statement to include the process form script when Form was submbitted.

5:09 pm on Sep 15, 2006 (gmt 0)

5+ Year Member



In plain english, the $_POST array is not sent back to the form page by using the back button (I wish it were that easy). I'll tell you a trick I use.

The default action for forms is the very same page that they are on. Submit the form to the form page and combine the form and form parsing code. It will look something like this:

if ($_POST) {
process data and show results...
if (errors in data) {
$prev_values = $_POST;
}
end script...
}

<form method="post">
<input name="thing" value=" <?php echo $prev_values['thing'];?>">

...
You use $prev_values to re-populate the form. If there was no $prev_values nothing is printed.

Good luck

12:23 pm on Sep 19, 2006 (gmt 0)

5+ Year Member



Thanks for your replies, i have managed to work my way around it, however i experimented a little and found the following results.

On the companies intranet server:
I took all the php code out of form.php and renamed it to form.html.

When i filled out the form on form.html and clicked submit (making sure i missed out a required field) form-parse.php throws up an error (as it should). I then clicked the back button on the browser and i didn't need to fill the form in again, the previous data i entered was already there.

On a web server I pay for:
I uploaded form.php and form-parse.php to the external server that i have a website hosted on and the whole thing works as it should.

So i shouldn't have to add any extra code to the users data back in the form. Which is why this is puzzling me because i have never needed to do it on other servers.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month