2012-12-16 275 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是否爲空。