2009-08-12 16 views
8

Próbuję dodać reCAPTCHA do mojej strony, ale wciąż otrzymuję błąd incorrect-captcha-sol po przesłaniu odpowiedzi.Potrzebujesz pomocy z reCAPTCHA - ciągle otrzymujesz nieprawidłowe captcha-sol

Czy ktoś może mi powiedzieć, czy mam rację, wykonując następujące czynności?

Mam ogólny plik index.php, który zawiera contact.php. W contact.php mam wstawiony następujący kod:

require_once('recaptchalib.php'); 
$publickey = "XXXX"; 
$privatekey = "XXXX"; 

//the response from reCAPTCHA 
$resp = null; 
//the error code from reCAPTCHA, if any 
$error = null; 

if ($_POST['submit']) { 
    $message = $_POST['message_txt']; 
    $name = $_POST['name_txt']; 
    $email = $_POST['email_txt']; 

$emailBody = $message; 
$to = 'xx'; 
$from = $name.' <'.$email.'>'; 
$subject = 'XX Website Enquiry'; 
$headers = 'From: '.$from; 

$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); 

if ($resp->is_valid) { 
    echo 'captcha correct'; 
    if (mail($to,$subject,$emailBody,$headers)) { 
     //echo 'mail sent'; 
     $confirmation = 'sent'; 
    } 
    else { 
     //echo 'mail not sent'; 
     $confirmation = 'error'; 
    } 
} else { 
    # set the error code so that we can display it. You could also use 
    # die ("reCAPTCHA failed"), but using the error message is 
    # more user friendly 

    $error = $resp->error; 

    echo $error; 
} 

}

w moim html włożeniu CAPTCHA tak:

<form name="contactForm" method="post" action="index.php?id=contact&action=submit#contact"> 
    <tr><td>Name</td><td><div align="right"> 
     <input type="text" name="name_txt" class="input"> 
     </div></td></tr> 
    <tr><td>Email</td><td><div align="right"> 
     <input type="text" name="email_txt" class="input"> 
    </div></td></tr> 
    <tr><td height="10"></td></tr> 
    <tr><td colspan="2">Message</td></tr> 
    <tr><td colspan="2"><textarea name="message_txt" class="textarea" style="width:200px; height:100px"></textarea></td></tr> 
    <tr><td colspan="2"><?php echo recaptcha_get_html($publickey, $error); ?></td></tr> 
    <tr><td colspan="2" style="padding-top:10px;"><input type="image" src="images/header_06.gif" name="submit" value="submit"></td></tr> 
    </form> 

nie widzę, że robię coś złego, ale doceniłby każdą konstruktywną krytykę.

TIA

Odpowiedz

19

Rozwiązałem to, że jest jednym z najbardziej niezwykłych rzeczy mam natknąć, moja składnia była poprzednio:

<table> 
<form> 
<tr><td></td></tr> 
</form> 
</table> 

Zmieniłem go to:

<form> 
<table> 
<tr><td></td></tr> 
</table> 
</form> 

Z tego powodu, nagle recaptcha_response_field i recaptcha_challenge_field przywracają wartości do formularza.

Nie mogę myśleć, dlaczego tak jest, ponieważ wszystkie zmienne z formularza MY zostały wysłane przed zmianą.

Dziękuję wszystkim za wskazówki.

7

jeśli Piszesz czek dwa razy - na przykład raz z javascript i php raz przez drugi zawiedzie jako API pozwala tylko rozwiązanie, aby powrócić ważny raz.

nadzieję, że pomoże, Josh

0

Czy na pewno wpisywania poprawnych słów?

ten wynosi od recaptcha website :

Line 1  "true" or "false". True if the reCAPTCHA was successful 
Line 2 if Line 1 is false, then this string will be an error code. reCAPTCHA can 
    display the error to the user (through the error parameter of api.recaptcha.net/challenge). 
    Implementations should not depend on error code names, 
as they may change in the future. 


    Example: If your response looks like this: 

    false 
    **incorrect-captcha-sol** 

    ... you can add '&error=incorrect-captcha-sol' to the challenge request URL, 
and the user will get an error code. 
5

Dzieje się tak, ponieważ forma nie może być na zewnątrz tr ..... musi znajdować się na zewnątrz stołu ..... formularz nie może być wstawiony do tabeli, może być wstawiony do td .

2

W moim przypadku, błąd było ustawić formę bez podania:

method = "post"

Cheers!

Powiązane problemy