ReCaptcha "incorrect-captcha-sol"页面加载时显示错误



好的,我的联系表格(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();
}
  }
 ?>

任何想法??

您必须删除或忽略该错误。在 Rails 中,它是

  flash[:recaptcha_error] = nil

对于您的 PHP,您始终检查它是否有效

if (!$resp->is_valid) {

然后打印错误与$resp->error.因此,即使在第一次页面加载时尚未键入任何内容,它也可能会认为它是无效的并打印错误。相反,请在验证验证码之前检查recaptcha_response_field是否为空。

相关内容

最新更新