Saving Form Info
Moderator: General Moderators
Saving Form Info
I have a form I'm making that contains text boxes, check boxes, and radio buttons. If the something invalid is typed into a text box or maybe for example, they left a required field blank I want to be able to save all the info that they typed into the form and display it so they don't have to retype everything when an error occurs. I'm not sure how to do this. I tried following this guide: http://www.qualitycodes.com/tutorial.ph ... &pageid=84 but that did not work. Anyone know of a way to accomplish this?
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Saving Form Info
You can do it with php.
Do you have the error checking working? and just want data to remain after the check has completed?
Are you checking server or client side (or both hopefully)?
For a textarea use this (if using POST)
<textarea name='info'><?php echo $_POST['info']; ?></textarea> <!-- or without the php tags and echo if you are already within them -->
For input
<input type='text' name='firstname' value='<?php echo $_POST['firstname']; ?>' />
Do you have the error checking working? and just want data to remain after the check has completed?
Are you checking server or client side (or both hopefully)?
For a textarea use this (if using POST)
<textarea name='info'><?php echo $_POST['info']; ?></textarea> <!-- or without the php tags and echo if you are already within them -->
For input
<input type='text' name='firstname' value='<?php echo $_POST['firstname']; ?>' />
Re: Saving Form Info
Thank you so very much. Worked like a charm 
Re: Saving Form Info
By any chance is there a similar method for radio buttons or check boxes?
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Saving Form Info
Checkboxes and radio button require a slightly different approach:
The same can be used for radio elements.
Code: Select all
echo'<input type="checkbox" name="chk" ' . if($_POST['chk']==1){ echo 'checked="checked"'; } ?> .' value="1" />';