Retain values after POST

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
scs3rd
Forum Newbie
Posts: 16
Joined: Mon Jan 30, 2006 6:17 am

Retain values after POST

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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())
scs3rd
Forum Newbie
Posts: 16
Joined: Mon Jan 30, 2006 6:17 am

Post by scs3rd »

Thanks, most helpful
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

if u put the default value of the boxes as

Code: Select all

<?PHP echo '$_POST['watuwant']'; ?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The post variables won't exist at that point a94060. And your code breaks.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

ok well,i guess i learned somthing new...and by the breaks you mean a return at the lines?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

breaks, as in doesn't compile in PHP.
kyoru
Forum Commoner
Posts: 26
Joined: Mon Feb 13, 2006 9:35 pm

Post by kyoru »

store them in session variables, and make sure the forms post the value if they exist?
fangorn
Forum Commoner
Posts: 41
Joined: Fri May 21, 2004 9:04 am

Post 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.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

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