POST Form Memory?
Moderator: General Moderators
POST Form Memory?
Wasn't exactly sure where to post this, but I have an issue regarding a registration form that gives the user feedback if they enter anything incorrectly. (Email in use/username taken/invalid email/passwords do not match, etc)
However, when it redirects back to the form obviously the form is now empty and the user would have to enter everything again - that would be frustrating for them.
What would be the best way to go about doing this? Storing all the form data (except passwords) in session variables and then populating the form again? This is the only way I can think of without redesigning my entire form. (I do not POST the form data to the same page the form is on which is what I've read elsewhere on the forum, I POST to a separate PHP file and then return to the registration form if there is a problem)
Also, just quickly, in order to highlight the violating fields on the form, I assume CSS would be best way to do this? (I'm not the best at design haha)
Any ideas and tips are welcome! Thanks.
However, when it redirects back to the form obviously the form is now empty and the user would have to enter everything again - that would be frustrating for them.
What would be the best way to go about doing this? Storing all the form data (except passwords) in session variables and then populating the form again? This is the only way I can think of without redesigning my entire form. (I do not POST the form data to the same page the form is on which is what I've read elsewhere on the forum, I POST to a separate PHP file and then return to the registration form if there is a problem)
Also, just quickly, in order to highlight the violating fields on the form, I assume CSS would be best way to do this? (I'm not the best at design haha)
Any ideas and tips are welcome! Thanks.
Re: POST Form Memory?
Post to the same page as the form and use the $_FORM variable to repopulate the fields.
Re: POST Form Memory?
$_FORM variable? Huh.. 
Re: POST Form Memory?
Sorry, I meant the $_POST superglobal
slip of tongue
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: POST Form Memory?
You type with your tongue? Wicked!pytrin wrote:Sorry, I meant the $_POST superglobalslip of tongue
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: POST Form Memory?
Ha thought so... is there no other way I could implement for now? Rather than reimplementing my entire submitting form process >__>
Re: POST Form Memory?
Why would you need to reimplement your form handling process? you can include files in other files.

It's not a problem once you get used to itYou type with your tongue? Wicked!
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: POST Form Memory?
If errors are encountered then I would store the vars as session vars on the processing page and redirect. Check for these vars on the form page and if set then use them. As for the error messages, you can add other session vars before redirect and use those for classes of the inputs and style them red or whatever. Additionally you could set an error message var, check for it in the form and display it next to the fields.timWebUK wrote:Ha thought so... is there no other way I could implement for now? Rather than reimplementing my entire submitting form process >__>
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: POST Form Memory?
Yeah I've already got all that setup, it's purely repopulating the form with the details they entered previously and then marking the violating fields.
At the moment I display an error and they have to fill out the entire form again.
At the moment I display an error and they have to fill out the entire form again.
Re: POST Form Memory?
You could set a variable for every field in the form then use
<?php echo $variable; ?>
in the value of each form field.
Then you user wont have to fill in all the info again.
<?php echo $variable; ?>
in the value of each form field.
Then you user wont have to fill in all the info again.
Re: POST Form Memory?
Yeah I probably will! In future, when I remake this web application I will definitely POST the form to itself, this seems to have many benefits. Are there any drawbacks people know of?
-
ribble1001
- Forum Newbie
- Posts: 1
- Joined: Sat Dec 26, 2009 5:37 am
Re: POST Form Memory?
The only drawbacks to using session variables to store form fields may be one of security; one way round this is to use cookies in conjunction with sessions.
- SimpleManWeb
- Forum Commoner
- Posts: 57
- Joined: Wed Dec 30, 2009 4:15 pm
- Location: New Hampshire, USA
Re: POST Form Memory?
Another solution (and a better solution) would be to check the variable values using Javascript. Doing it this way means that you never have to worry about where the information gets posted to because it will not get posted until all of the fields are filled in correctly. If you're not familiar with Javascript, then you could also check the posted values using your current code, and then if they aren't correct, use a header redirect to go back to your form and pass the correct variables in the URL. Something like index.php?id=3&fname=John&lname=Doe..... Then, on your form you could use code like:
Those values could then be used like:
Hope this helps
Code: Select all
$FName = $_GET['fname'];
$LName = $_GET['lname'];
Code: Select all
<input type="text" name="fname" value="<?php echo $FName; ?>" />
Re: POST Form Memory?
Using Javascript is good - if the user has Javascript. You have to consider not everyone will have Javascript turned on, so you're back to square one.
One thing you might want to consider is using $_GET. Put what the user entered in the URL you redirect them back to, and in your form, auto-populate from $_GET if possible.
One thing you might want to consider is using $_GET. Put what the user entered in the URL you redirect them back to, and in your form, auto-populate from $_GET if possible.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.