losing form data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
digihoo
Forum Newbie
Posts: 4
Joined: Wed Oct 01, 2003 12:53 pm

losing form data

Post 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
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post 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']; ?>" />
digihoo
Forum Newbie
Posts: 4
Joined: Wed Oct 01, 2003 12:53 pm

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post 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:
digihoo
Forum Newbie
Posts: 4
Joined: Wed Oct 01, 2003 12:53 pm

Post 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
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post 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...
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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).
Post Reply