好的,我的联系表单(http://jshjohnson.com/new/contact.php)可以正常工作但是ReCaptcha错误(通常在输入错误的单词时出现)会显示在页面加载上。
我已经设置了一个名为message的空变量,该变量应该停止,但遗憾的是它没有。
<?php
include("functions.php");
require_once('recaptchalib.php');
$publickey = "6LdLX9oSAAAAALZawj-uldWrjsI0zYcR-w_r_sNh";
$privatekey = "<removed>";
$resp = recaptcha_check_answer($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
$recaptcha_form = recaptcha_get_html($publickey);
$message = "";
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
$message = "The reCAPTCHA wasn't entered correctly. Go back and try it again.
(reCAPTCHA said: " . $resp->error . ")";
} else {
// ADD YOUR CODE HERE to handle a successful ReCAPTCHA submission
// e.g. Validate the data
$myemail = "contact@jshjohnson.com";
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$fullname = $firstname . " " . $surname;
$email = $_POST['email'];
$contact = $_POST['message'];
$website = $_POST['website'];
$subject = "Website Contact";
if($firstname == '') {
$message = 'Please type your first name' ;
} else if ($surname == '') {
$message = 'Please type your surname';
} else if ($email == '') {
$message = 'Please type your email';
if (preg_match("/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/", $email)) {
$message = "Email address is valid";
} else {
$message = "Email address is invalid";
}
} else if ($contact == '') {
$message = 'Please type your message';
} else {
/* Let's prepare the message for the e-mail */
$contact = "Hello!
Josh Johnson Web Design contact form has been submitted by:
Name:* $fullname
E-mail:* $email
Website: $website
Budget: £
Message:*
$contact
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $contact);
/* Redirect visitor to the thank you page */
header('Location: index.php');
exit();
}
}
?>
任何想法??
答案 0 :(得分:0)
您必须删除或忽略该错误。在Rails中,它是
flash[:recaptcha_error] = nil
对于您的PHP,您始终会检查它是否有效
if (!$resp->is_valid) {
然后使用$resp->error
打印错误。因此,即使在第一页加载时没有输入任何内容,它也可能认为它无效并打印错误。相反,在验证验证码之前,请检查recaptcha_response_field
是否为空。