Form errors in an array
Posted on
16th Feb 2014 07:03 pm by
admin
I'm processing a form and putting the errors in an array. empty($errors) doesn't seem to do the trick when trying to check to see if the array is empty. Is my understanding of empty()incorrect? Each item is the array is either a string, the error message, or FALSE.
Can anyone help me figure out how to move into my if statement?
Code: <?php
// check fields
$errors = array();
$errors['the_date'] = (empty($the_date)) ? '<span class="error">Please choose a date.</span>' : FALSE;
$errors['first_name'] = (empty($first_name)) ? '<span class="error">Please fill in your first name.</span>' : FALSE;
$errors['last_name'] = (empty($last_name)) ? '<span class="error">Please fill in your last name.</span>' : FALSE;
$errors['email'] = (empty($email) || !preg_match("/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*(([,]|[,])s*w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*)*$/", $email)) ? '<span class="error">Please fill in a valid email address.</span>' : FALSE;
$errors['phone'] = (empty($phone)) ? '<span class="error">Please provide your phone number.</span>' : FALSE;
$errors['emergency_contact'] = (empty($emergency_contact)) ? '<span class="error">Please provide an emergency contact.</span>' : FALSE;
$errors['emergency_phone'] = (empty($emergency_phone)) ? '<span class="error">Please provide an emergency phone number.</span>' : FALSE;
$errors['major_interest'] = (empty($major_interest)) ? '<span class="error">Please pick a major of interest.</span>' : FALSE;
$errors['activity1'] = (empty($activity1)) ? '<span class="error">Please select a morning activity.</span>' : FALSE;
$errors['activity2'] = (empty($activity2)) ? '<span class="error">Please select a morning activity.</span>' : FALSE;
$errors['activity3'] = (empty($activity3)) ? '<span class="error">Please select an afternoon activity.</span>' : FALSE;
$errors['activity4'] = (empty($activity4)) ? '<span class="error">Please select an afternoon activity.</span>' : FALSE;
$errors['interests'] = (empty($interests)) ? '<span class="error">Please list your interests.</span>' : FALSE;
$errors['accomodations'] = (empty($accomodations)) ? '<span class="error">Please answer.</span>' : FALSE;
$errors['acknowledgement'] = (!(strcmp($acknowledgement, 'I understand') == 0)) ? '<span class="error">Please type the indicated response.</span>' : FALSE;
// does the email exist? did they already register?
$errors['checkEmail'] = checkEmail($email);
//print_r($errors);
if (empty($errors))
{
header('Location: thankyou.php');
exit();
//$sql = "INSERT INTO ...";
}
?>
No comments posted yet
Your Answer:
Login to answer
203
42
Other forums
Multi image upload
I have a gallery to build and want to build a dynamic upload form to allow for $var number of fields
CURL XML Request [From C to PHP]
Hi,
I need some help converting this into something that will work with PHP.
Code: #
Storing the referrer in session... problems with tabs
Hello All
I am currently working on an ERP project based on the MVC methodology, when a user
Unexpected T_Variable ?
Hi all,
I dont really know what I am doing!! I know I'm doing something wrong, and I know its on
Wordpress IE issue
So I am trying to add the background shadow to my wordpress page. It works fine in Firefox but does
How do I create a 2D game "camera" to follow player?
In J2ME programming I'm targeting MIDP 2.0 devices.
I'm using gamecanvas and I was thinking t
include problem
I have my root folder as:
Code: $root = $_SERVER["SITE_HTMLROOT"]; // the server root<
Add_Months not Easy to Understand
Oracle is number 1, very fast and very easy. But....
OK, I think but have a problem, only 1 pro
first few characters only
hi, does anyone know how to use PHP to take the first few words of a text and limit them? i have see
Sales orders ans reservations not taken into account on MPS / MRP
Hello,
I am implementing the MPS / MRP and I have the following problem:
I ha