...

View Full Version : Keeping Form Values After Error Message



zfred09
12-23-2006, 09:32 PM
Ok I have multiple forms (for registration) and if someone were to fill out all the information but have an error in what they entered, how do I keep the form values they entered in the form after they get an error message? Basically so they don't have to re-type all their information after one little error.

whizard
12-23-2006, 09:43 PM
Send the values and the error back to the form page, and display the error message(s) above the correct field(s) and use the 'default' attribute in each input field to display the value.

Or where you looking for a more concrete example?

Dan

Brandoe85
12-23-2006, 09:45 PM
In the value attribute in the html check if it's been set:


<input type="text" name="first" value="<?php echo (isset($_POST['first'])) ? $_POST['first'] : ''; ?>"


Good luck;

zfred09
12-23-2006, 09:56 PM
What does the default value attribute do?

whizard
12-23-2006, 10:00 PM
My bad, I meant 'value', not 'default'...

Mental lapse
Dan

zfred09
12-23-2006, 10:03 PM
It's aight, I don't really get how the isset works or how to implement it.

Brandoe85
12-23-2006, 10:05 PM
In the value attribute in the html check if it's been set:


<input type="text" name="first" value="<?php echo (isset($_POST['first'])) ? $_POST['first'] : ''; ?>"
Good luck;

That is how you implement it. If the $_POST var is set, then you know the form has been submitted, if it hasn't you know that you do not need to display the $_POST value, because it doesn't have a value.

Notice, $_POST['first'] relate to the name in your input field...see?

zfred09
12-23-2006, 10:15 PM
Ya I understand now, I got it working, in my processing file I just used the value sent by the form and assigned it to a session variable, and then in my form I put value="<?php echo ("$sessionvar"); ?>". Thanks for your help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum