function validate_min_lengths($fields_min_length) { global $errors; foreach ($fields_min_length as $field => $min) { $value = trim($_POST[$field]); if (has_min_length($value, $min)) { $errors[$field] = ucfirst($field) . " is to short"; } } }
function validate_min_lengths($fields_with_min_lengths) { global $errors; //Using an assoc. array foreach ($fields_with_min_lengths as $field => $min) { $value = trim($_POST[$field]); if (has_min_length($value, $min) && $value !== "" && isset($value)) { $errors[] = fieldname_as_text($field) . " is too short"; } } }
$errors[] = "Please enter a valid email address"; } } else { $email = ""; $errors[] = "Please enter an email address"; } // if there's a subject, clean it up if (has_presence($_POST['subject'])) { $subject = htmlspecialchars($_POST['subject']); } else { $subject = ""; } // check for presence of a message if (has_presence($_POST['message'])) { // if it's at least 3 characters long if (has_min_length($_POST['message'], 3)) { $message = wordwrap(htmlspecialchars($_POST['message']), 70); } else { $message = htmlspecialchars($_POST['message']); $errors[] = "Please write more than 2 words"; } } else { $message = ""; $errors[] = "Please write a comment before trying to send the form."; } // if no errors, then assemble the email if (empty($errors)) { $to = 'David Gaskin <*****@*****.**>'; // this may cause a bug on Windows systems $subject .= " sent " . strftime("%a, %B %d at %I:%M %p", time()); $from = "{$name} <*****@*****.**>";
if (is_valid_email($_POST['user_email'])) { // assign clean, valid 'email' variable $user_email = htmlspecialchars($_POST['user_email']); $user_data['user_email'] = $user_email; } else { $user_email = htmlspecialchars($_POST['user_email']); $errors[] = "Please enter a valid email address"; } } else { $user_email = ""; $errors[] = "Please enter an email address"; } // check for presence of a password if (has_presence($_POST['user_password'])) { // make sure its at least 7 characters long if (has_min_length($_POST['user_password'], 7)) { // check for presence of a conf_password if (has_presence($_POST['conf_password'])) { // compare the two password for exactness if (is_exact($_POST['user_password'], $_POST['conf_password'])) { // passwords match $user_password = htmlspecialchars($_POST['conf_password']); $conf_password = htmlspecialchars($_POST['conf_password']); // hash protect password $hash_password = password_hash($user_password, PASSWORD_DEFAULT); $user_data['user_password'] = $hash_password; } else { $user_password = ""; $conf_password = ""; $errors[] = "Your passwords didn't match"; }