如何合并此PHP脚本以生成一条错误消息?

时间:2011-10-21 00:45:54

标签: php merge submit recaptcha

我正在尝试合并多个字符串,虽然它似乎只是抛出一个错误。

// 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);
}

1 个答案:

答案 0 :(得分:0)

之后:

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

把这个:

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 />';
}