Page 1 of 1
Keeping Form Values
Posted: Fri May 02, 2008 11:34 am
by icesolid
Scenario: A user is filling in a form and accidentally browses back.
Is there a way to use cache or something of the sort so that the user can just hit forward and the form values they were just filling out are not lost? Or not use cache at all and if the user hits the delete key or backspace key it will pull up a javascript prompt asking if they are sure they want to do that, if so what javascript command is used to detect this?
Re: Keeping Form Values
Posted: Fri May 02, 2008 11:56 am
by remyx187
ive had this problem before
It might go something like this:
Code: Select all
<form>
<input type="text" name="random" value="<?php echo $_POST['random']; ?>">
<select name="state">
<option value="XX" <?php if($_POST['state'] == "XX") echo "selected"; ?>>XX</option>
</select>
</form>
etc.
Note: for the drop down list, you have to specify the if statement on each option value.
This might not be exactly what youre looking for but i think it should help a little.
Granted the user submits the form.
Re: Keeping Form Values
Posted: Fri May 02, 2008 11:58 am
by aceconcepts
but if they hit the back button without "posting" any values then the values will never exist!
Re: Keeping Form Values
Posted: Fri May 02, 2008 12:06 pm
by yacahuma
The only thing that comes to mind is using javascript with onchange so that you DO keep the data in a cookie as soon as they type
Re: Keeping Form Values
Posted: Fri May 02, 2008 12:57 pm
by icesolid
Any other ideas?
Re: Keeping Form Values
Posted: Fri May 02, 2008 1:05 pm
by aceconcepts
You can't retrieve data that hasn't been posted.
Re: Keeping Form Values
Posted: Fri May 02, 2008 1:06 pm
by Verminox
Javascript? Cookie? Cache? Errm...
It's the default behaviour of a web browser
User types something in form...
User clicks back button by mistake...
OOPS! User clicks forward again...
The form values are restored
No scripting required.