Saving Form Info

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ununium
Forum Newbie
Posts: 5
Joined: Sun Oct 26, 2008 11:28 pm

Saving Form Info

Post 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?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Saving Form Info

Post 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']; ?>' />
ununium
Forum Newbie
Posts: 5
Joined: Sun Oct 26, 2008 11:28 pm

Re: Saving Form Info

Post by ununium »

Thank you so very much. Worked like a charm :)
ununium
Forum Newbie
Posts: 5
Joined: Sun Oct 26, 2008 11:28 pm

Re: Saving Form Info

Post by ununium »

By any chance is there a similar method for radio buttons or check boxes?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Saving Form Info

Post 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.
Post Reply