Zachary Gover Zachary Gover - 5 months ago 12
PHP Question

How to merge this PHP script to make one error message?

I am trying to merge multiple strings although it just seems to throw an error.

// Regex Tests
$error_message = "";

// Expressions
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($email_exp, $email_from)) {
$error_message + 'The Email Address you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp, $first_name)) {
$error_message + 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp, $last_name)) {
$error_message + 'The Last Name you entered does not appear to be valid.<br />';
}
if(!empty($error_message)) {
formError($error_message);
}

Answer

After this:

if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 }

Put this:

require_once('php/recaptchalib.php');
$privatekey = "enter private key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
    $error_message .= 'The reCAPTCHA wasn't entered correctly. Go back and try it again.<br />';
}
Comments