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 ...";
}
?>
203
42
Other php-forum
phpmailer class & pop.gmail.com?
Code: <?php
$mail->IsSMTP();
$mail->Host = "pop.gmail.com";
Delete records not in top 15
Hi,
I'm creating a hall of fame page in my game and the page will only display the top 15 sco
Credit card verification
I have a client who wants to process credit card transactions from his web site rather than the goin
retrieving images from mysql database using php
So I've been trying to figure out how to store images in a mysql database, and as far as i can tell
Undefined offset when using a flat file with pipe symbols
Hi, I've got a flat file/text file which I'm currently using as a member database for my site (not a
utf8_general_ci error ??
I have all kinds of data to be inserted in database table
//I am getting this error
Yo
single page with referrer to show correct page
I have a simple website with a couple of different pages. I would like to be able to in a div tag w
Converting RGB values to HEX
Code: <?PHP
$file_handle = fopen("colors/rgb.csv", "r");
wh
help with contest script
I would like to code a contest script to my site but i don't know how. Could someone just give me pu
I would like "for" to wait 5 sec
I would like my 'for' loop to wait 5 sec before second iteration.
for ($i=0; $i<10