Hi there,
I have a form but i need it so when a user fills in the form and makes a mistake the values are still there
so if user adds there address and clicks submit but his email is wrong that user doesnt have to fill out his address in the form again.
ANy ideas
Thanks
Alex
forms in php
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
It's just a case of using the form field's value attribute:
Have a read in the manual on sessions so that you can keep the data stored for the duration of that user's time on your website.
http://uk2.php.net/manual/en/ref.session.php
Code: Select all
<input type="text" name="email" value="<?php echo $email; ?>" />http://uk2.php.net/manual/en/ref.session.php
feyd | Please use
Obviously you cannot do this on the first posting because the $_POST array elements will not exist so you will need to either create them or use conditional code output
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
When you post the form all the values in the fields are in the $_POST array.
when you validate the form and redisplay it you need to set the value to be the $_POST value.Code: Select all
print "<input type=\"text\" name=\"surname\" size=\"20\" value=$_POST['surname']>* Surname cannot be blank"Code: Select all
if (!$_POST['surname'])
{
$surname = "";
$errmsg = "";
}
If($_POST['surname'] == "")
{
$surname=$_POST['surname'];
$errmsg = "* Surname cannot be blank";
}
print "<input type=\"text\" name=\"surname\" size=\"20\" value=$surname>$errmsg";feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]you want to sanitize all user-submitted data though...
Code: Select all
$surname = sanitize($_POST['surname']); // sanitize is just a figurative function (not real) - look up php data sanitization on google