PDA

View Full Version : Keeping form info


Nightfire
06-27-2003, 02:58 PM
Is there a class or anything that will store form info in textboxes after the form has been submitted, but the user presses t he back button on the browser to get to the form again?

Whenever I do this, all the form fields are always empty, is this a browser issue or just the way forms work?

raf
06-27-2003, 03:13 PM
I noticed the same thing, buth i think it's a server issue. (not a browser issue)

When i run my PHP's on my local machine, the formfields are blank when i jump back to the form, buth on my host, the values are still there ...

weronpc
06-27-2003, 03:25 PM
I had read a premade script about it before, I don't know it's the right or not but hope will help

<input type="text" value = "
<?php
if(isset($_POST['id'])){
echo $_POST['id'];
}
else
{
echo " ";
}
?>
" size = "20">


you can also use $_GET instead of $_POST..

whackaxe
06-27-2003, 04:13 PM
use cookies if its that important?

Nightfire
06-27-2003, 04:41 PM
Originally posted by raf
I noticed the same thing, buth i think it's a server issue. (not a browser issue)

When i run my PHP's on my local machine, the formfields are blank when i jump back to the form, buth on my host, the values are still there ...

I think you're right, works on my host but not on my pc

cpradio
06-28-2003, 09:10 AM
I use sessions for mine. Like so.

When the form is submitted the first thing I do is store all form contents into a session variable like so:

$_SESSION['webForm'] = $_POST;

Then if the information they entered was correct I erase that data using unset($_SESSION['webForm']);

This way if the data was false the user can back track and I can recall the prior data.

-Matt

raf
06-28-2003, 09:51 AM
Hmm. I think we're mixing two situation here:
- validating a form
- jumping back to a form

When i validate a form, i always use a multi-purpose page --> just post the form to itself, validate all values, display messages where there are invalid values. Else process the date.
So i can just use $_POST to get the entered info. No need to use sessions there. (by setting a flag when the page is parsed for the first time and checking for that flag on top of the page, you can you can skip the validations on first load)

But sometimes i jump back to a form (for instance, when debugging and testing app's) using the back button or alt + <--
and then i noticed this formclearing

cpradio
06-28-2003, 03:56 PM
Ahh, see I save time and use a single php file to validate any form I make. To where I do not necessarily know what form fields were on the page the form was submitted from.

So the method I use is store it in a session for when anyone has to visit back. When using the "Back" button it is not transferring the variables as POST anymore. The information infact is not longer being transferred which is why the form is blank.

By using a session you can grab that data because you already stored it temporarily.

-Matt