Error Checking
Posted: Thu Jan 22, 2009 8:09 am
Hello DevNet,
Yes I have caused myself yet another head ache. Anyways what I have included in my web form is some simple error checking using 'if' statements. However when there is a value missed out it echos the message onto a new page. How can I get my error messages to appear on the same page somewehere specific??
Yes I have caused myself yet another head ache. Anyways what I have included in my web form is some simple error checking using 'if' statements. However when there is a value missed out it echos the message onto a new page. How can I get my error messages to appear on the same page somewehere specific??
Code: Select all
//Error Checking for certain form fields that are required.
if (empty($_POST['fname'])) { $errors[] = 'Please enter your first name';}
if (empty($_POST['lname'])) { $errors[] = 'Please enter your last name';}
if (empty($_POST['fromemail'])) { $errors[] = 'Please enter your email address';}
else if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_POST['fromemail'])) { $errors[] = 'Please enter a valid e-mail address';}
if (empty($_POST['location'])) { $errors[] = 'Please enter your place of residence';}
if (empty($_POST['notice'])) { $errors[] = 'Please enter your required period of notice';}
if (empty($_POST['current_salary'])) { $errors[] = 'Please enter your current salary';}
if (empty($_POST['working_location'])) { $errors[] = 'Please enter your current working location';}
if (empty($_POST['strengths'])) { $errors[] = 'Please enter your strengths';}
if (empty($_POST['qualifications'])) { $errors[] = 'Please list your qualifications';}
if (empty($_POST['comments'])) { $errors[] = 'Please add some additional comments that could strengthen your application';} else if (strlen ($_POST['comments']) > 255) { $errors[] = 'Your comment is too long';}
if (count($errors) == 0) {
}else{ echo $errors[0];}
//Error Checking End