2012-12-16 246 views
1

好的,我的联系表单(http://jshjohnson.com/new/contact.php)的工作方式应该像它应该的那样ReCaptcha错误(通常在你输入的单词不正确)在页面加载时显示。在页面加载时出现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 = "[email protected]"; 
$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._%+-][email protected][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

谢谢你的抬头 – jshjohnson

+0

@jshjohnson它仍然在编辑历史:“6LdLX9oSAAAAAHHHaxAd0PkR6yKyqgOR-8Bec-la”。你现在必须完全得到一把新钥匙。 – Chloe

回答

0

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

​​

为了您的PHP,你总是检查它是否有效与

if (!$resp->is_valid) { 

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