Page 1 of 1

losing form data

Posted: Wed Oct 01, 2003 12:53 pm
by digihoo
i am validating form data, but when i redirect the user back to the form page to correct their errors, all the data they entered has disappeared.

Please Help.

Thanks

Posted: Wed Oct 01, 2003 12:56 pm
by Derfel Cadarn
You'll need something like:

Code: Select all

<input type="text" name="name" size="50" id="Name" value="<?php echo $HTTP_POST_VARS&#1111;'name']; ?>" />

Posted: Wed Oct 01, 2003 1:17 pm
by digihoo
i should be more specific.. the problem also occurs if the user clicks away (say, the back button), and then clicks back to the form -- all data is gone in that case, also.

is there a way to prevent form data from disappearing, whether or not it has been submitted into post variables?

Posted: Wed Oct 01, 2003 6:33 pm
by JAM
You need to add a header() before anything is printed to the browser.

Code: Select all

header("Cache-control: private");
A bug in IE6.

Posted: Thu Oct 02, 2003 3:40 am
by Derfel Cadarn
Hey, that's a new one to me too! But I never met it before using Mozilla instead of M$. I'll have a look on php.net.

I keep learning here! :wink:

Posted: Thu Oct 02, 2003 10:02 am
by digihoo
unfortunately this didn't seem to fix the problem.

in fact, i am able to recreate it using Netscape as well...(?)

is this some kind of default php characteristic with dynamically generated (HTML) forms?

i guess it is rewriting the page each time the user clicks away.

is there any way to prevent this?


Thanks

Posted: Thu Oct 02, 2003 3:29 pm
by Cruzado_Mainfrm
well, if you pass down the variables as GET when you click 'back' that will solve the problem, or if you use session variables then you can save the data and recover it later...

Posted: Thu Oct 02, 2003 5:21 pm
by Unipus
You're supposed to lose form data if you actively navigate away from it without submitting. HTTP is stateless... that's just how it works.

So any time you've navigated away from a form and come back and your data has remained, that's either a browser FormFill sort of setting, back history memory, or a site that's using sessions/cookies to store your data.

Posted: Fri Oct 03, 2003 4:42 am
by JAM
Unipus wrote:You're supposed to lose form data if you actively navigate away from it without submitting. HTTP is stateless... that's just how it works.
Very true, my header()-example only works if the form was POST was sendt. I have tested this in many forms, and yet havn't found any problems about missing information that didn't belong to this bug.
i should be more specific.. the problem also occurs if the user clicks away (say, the back button), and then clicks back to the form -- all data is gone in that case, also.

is there a way to prevent form data from disappearing, whether or not it has been submitted into post variables?
A javascript guru might be able to do this, but a personal oppinion is why put down the effort? PHP will never solve this as the information is trapped in the client (javascript might work).