View Full Version : Form data & Back button
jnscollier
05-18-2007, 01:12 AM
I have a form and here's what I have an issue with....
If the user types something in the boxes, and then accidentally goes to another site/page in the site WITHOUT hitting submit on the form, all the data is lost when they click the back browser button. What I want them to be able to do is hit the back button and all the information to still be there.
How can I do this? I'm using php, so I don't know if I've posted this in the right forum.... I've seen this on many other sites just don't know how to do it.
Any help would be appreciated!
jnscollier
05-18-2007, 01:41 AM
A quick example of this at work would be yahoo email. If you compose an email and type a subject, to, and main email and then go to another site. You hit back and the info you entered is still all there (even though the email was never sent)
thetestingsite
05-18-2007, 01:42 AM
You could use Javascript Cookies to accomplish this. Not sure how exactly, but I do know it can be done.
jnscollier
05-18-2007, 03:07 AM
Is there a way to do this without using cookies? If not, does anybody know how to accomplish this with Javascript cookies? I'm not familiar with javascript cookies....
Thanks!
djr33
05-18-2007, 03:27 AM
Yes, there is. Use a browser that works like this. Some browsers, and even sometimes some forms in some browsers remember, while others do not.
Short of using cookies, no, there is not another way to override the default. (I suppose you could try to use ajax and a database, but that is way too much work. Cookies are a much better.)
Not sure how to use them with javascript myself, but you could use the onChange value for all fields in the form, then store the value into the cookie of the same name as the name/id of that field in the form.
For the javascript, take a look here--
http://www.quirksmode.org/js/cookies.html
Or, of course--
http://www.google.com/search?q=javascript+set+cookie
mwinter
05-18-2007, 03:05 PM
As djr33 pointed out, it is an built-in function of some browsers to retain the values from form fields when revisiting them via the Back and Forward buttons.
This functionality cannot be replicated reliably: using the Back and Forward buttons neither generates new requests to the server, nor does it necessarily cause scripts to be re-executed (in Firefox, for instance).
jnscollier
05-18-2007, 05:03 PM
Thanks for your help you guys.... here's what I'm doing and every time i type something in this title box part of the form and then go to another site and hit the back browser button, nothing is in the title box....This is the case with Firefox and IE
I think this is right from everything I've read...
<input name="txt_blogname" type="text" id="txt_blogname" value="<?php echo $_COOKIE["TestCookie"]; ?>" size="75" maxlength="100">
<?php
$value=$HTTP_POST_VARS['txt_blogname'];
// send a simple cookie
setcookie("TestCookie",$value);
?>
I've tried putting the setcookie part before the textbox and after it and neither works... Any help would be appreciated.
djr33
05-18-2007, 08:29 PM
PHP is only parsed upon a new request. Back and forward are from your cache, so that's just as good as a pure html page, without anything dynamic about it.
Using javascript is the only option. (Though I like PHP more in general myself.)
I think the one loophole to what John said, though he made some great points, is that you could have it check for content always and somehow know that the page was revisited. It would be complex and resource intensive, but it would be possible. But... not worth it unless you REALLY need this.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.