nup - that sounds about right.....ok........So this is the skeleton that we had from before...
PHP Code:
if($_POST['form_submitted'])
{
//check for errors
if(no_errors)
{
//send the email
}
//
else
{
//display the errors
//and display the form again
}
}
else
{
//the form has not been submitted
// display the form
}
After the 1st line where we check if the form has been submitted, we need to get the values that the user has entered, in order to validate them (and later use them to send in the email).
PHP Code:
//get the vars from the form
$name= strip_tags(trim($_POST['name']));
$email = strip_tags(trim($_POST['email']));
$phone= strip_tags(trim($_POST['phone']));
We have used trim() and strip_tags() to just tidy up the input a little.
Ok, as we go through each of the fields validating them, we will store any errors in an array (just makes it easier to output the errors later).
PHP Code:
//inititialise an error array
$errors = array();
Now we are ready to validate our input:
PHP Code:
if(!is_numeric($phone))
{
$errors[] = 'Phone number must be a number';
}
Ok, so I suggest that you now go off and do some reading on regular_expressions and php form validation to have a crack at the other fields......
Bookmarks