How to retain values in form if validation fails
Moderator: General Moderators
-
shubham.amola
- Forum Newbie
- Posts: 8
- Joined: Mon Jan 19, 2009 11:57 pm
How to retain values in form if validation fails
hii..i ve made a registration form. When user click the submit button all feild values will be checked from the database. If the entered email id is already in the database then it will go back to the registration form with error message. But the problem is wen it goes back to page user has to enter the values again which i dont want to. I want the values to be there so that user can enter only email id and he dnt ve to fill other fields. So any suggestions???
Re: How to retain values in form if validation fails
When the form is submitted, you can have the form submit to itself, and handle any processing before the form is displayed. That way, if the form needs to be re-displayed, you can simply access the values in the $_POST array. If the form is fine and processing succeeds, just redirect to the next page.
Cheers
Cheers
-
mattpointblank
- Forum Contributor
- Posts: 304
- Joined: Tue Dec 23, 2008 6:29 am
Re: How to retain values in form if validation fails
Yep. Set form fields like so:
<input name="email" value="<?php echo @$_POST['email']; ?>" type="text" />
(the @ sign means only display if it exists, so it doesn't show a warning message if they haven't submitted it yet.
<input name="email" value="<?php echo @$_POST['email']; ?>" type="text" />
(the @ sign means only display if it exists, so it doesn't show a warning message if they haven't submitted it yet.
Re: How to retain values in form if validation fails
?mattpointblank wrote:Yep. Set form fields like so:
<input name="email" value="<?php echo @$_POST['email']; ?>" type="text" />
(the @ sign means only display if it exists, so it doesn't show a warning message if they haven't submitted it yet.
If not submitted the var is empty.
-
mattpointblank
- Forum Contributor
- Posts: 304
- Joined: Tue Dec 23, 2008 6:29 am
Re: How to retain values in form if validation fails
Exactly, hence the @ sign, so if they get sent back to the page, it will show what they typed.
Re: How to retain values in form if validation fails
I don't get an error message either way but maybe I've missed the point as usual.mattpointblank wrote:Exactly, hence the @ sign, so if they get sent back to the page, it will show what they typed.
-
mattpointblank
- Forum Contributor
- Posts: 304
- Joined: Tue Dec 23, 2008 6:29 am
Re: How to retain values in form if validation fails
I guess it depends on your settings, but on some servers I get a "$_POST is not set" message when I load the page first time.
-
shubham.amola
- Forum Newbie
- Posts: 8
- Joined: Mon Jan 19, 2009 11:57 pm
Re: How to retain values in form if validation fails
itz done..thnx 4r ur help
Re: How to retain values in form if validation fails
Ok, well good to know. thxmattpointblank wrote:I guess it depends on your settings, but on some servers I get a "$_POST is not set" message when I load the page first time.