Page 1 of 1

Saving Form Info

Posted: Mon Oct 27, 2008 2:45 am
by ununium
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?

Re: Saving Form Info

Posted: Mon Oct 27, 2008 3:00 am
by jaoudestudios
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']; ?>' />

Re: Saving Form Info

Posted: Mon Oct 27, 2008 4:36 am
by ununium
Thank you so very much. Worked like a charm :)

Re: Saving Form Info

Posted: Mon Oct 27, 2008 4:40 am
by ununium
By any chance is there a similar method for radio buttons or check boxes?

Re: Saving Form Info

Posted: Mon Oct 27, 2008 11:13 am
by aceconcepts
Checkboxes and radio button require a slightly different approach:

Code: Select all

 
echo'<input type="checkbox" name="chk" ' . if($_POST['chk']==1){ echo 'checked="checked"'; } ?> .' value="1" />';
 
The same can be used for radio elements.