Page 1 of 1
Retain values after POST
Posted: Thu Feb 23, 2006 11:17 am
by scs3rd
I think this should be quite simple, but can't find any info on the Web.
I would like the values in textboxes to be retained if the users POST's them to the next page,
then presses the "Back" button in the browser to return to the previous page.
There is no sensitive data, usernames/passwords etc.
Thanks for any help
Posted: Thu Feb 23, 2006 11:24 am
by feyd
That isn't controlled by PHP really. Only if the page actually fetches again can PHP really do anything about it. Their browser chooses whether to cache their form info or not (with some possible nudging PHP can do).
Read up on how PHP can affect the cache settings (hint:
header())
Posted: Thu Feb 23, 2006 11:39 am
by scs3rd
Thanks, most helpful
Posted: Thu Feb 23, 2006 12:14 pm
by a94060
if u put the default value of the boxes as
Code: Select all
<?PHP echo '$_POST['watuwant']'; ?>
Posted: Thu Feb 23, 2006 12:15 pm
by feyd
The post variables won't exist at that point a94060. And your code breaks.
Posted: Fri Feb 24, 2006 12:01 pm
by a94060
ok well,i guess i learned somthing new...and by the breaks you mean a return at the lines?
Posted: Fri Feb 24, 2006 12:50 pm
by feyd
breaks, as in doesn't compile in PHP.
Posted: Fri Feb 24, 2006 12:53 pm
by kyoru
store them in session variables, and make sure the forms post the value if they exist?
Posted: Fri Feb 24, 2006 1:27 pm
by fangorn
In my experience, pressing back on a page that has posted variables will result in blank text boxes as you seem to have seen. But the GET method will not. I think it's a post issue - and I'm speaking strictly about Internet Explorer. I get this complaint too and it's nothing I've been able to fix.
Posted: Fri Feb 24, 2006 1:29 pm
by d3ad1ysp0rk
kyoru wrote:store them in session variables, and make sure the forms post the value if they exist?
I don't think you quite get what (s)he wants to do. If you push back in most browsers, they have stored a copy of the page, and the copy would be the one without the text entered into the form.
The only way to do it is really what Feyd said; forcing no-cache. However, if that doesn't work, the only other alternative (alternative because it requires one extra step on the users' part) is to include a link on your form page that mentions "Lost data? Click <a>here</a> to attempt to recover it." which just reloads the page, in which you print out the session variables if they exist.