1

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

有任何想法吗??

4

1 回答 1

0

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

  flash[:recaptcha_error] = nil

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

if (!$resp->is_valid) {

然后用 打印错误$resp->error。因此,即使在第一页加载时没有输入任何内容,它也可能认为它无效并打印错误。相反, recaptcha_response_field在验证 CAPTCHA 之前检查是否为空。

于 2014-02-11T05:11:25.010 回答