0

I have a problem with the form I'm using in my webpage.

It allows the recaptcha but It also sends the email without validating the fields in the recaptcha box. This form is using Ajax and PHP.

I've pasted the code next:

<br> <br> <div id="fields">

<form action="javascript:alert('success!');">
<label>Nombre</label><INPUT class="textbox" type="text" name="name" value=""><br />

<label>eMail</label><INPUT class="textbox" type="text" name="email" value=""><br />

<label>Asunto</label><INPUT class="textbox" type="text" name="subject" value=""><br />

<label>Mensaje</label><TEXTAREA class="textbox" NAME="message" ROWS="5" COLS="25"></TEXTAREA><br />

<?php

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "6LekPAQAAAAAAFoAJRfRtd9vmlzA9m-********";
$privatekey = "6LekPAQAAAAAAFqNcNsrnZba0-ZMg-********";

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

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid) {
                echo "Bien escrito!";
        } else {
                # set the error code so that we can display it
                $error = $resp->error;
        }
}
echo recaptcha_get_html($publickey, $error);
?>
    <br/>

<label>&nbsp;</label><INPUT class="button" type="submit" name="submit" value="Enviar">
</form>
</div>

</fieldset> 

Thanks a lot.

David.

4

1 回答 1

1

问题是您需要在再次显示表单之前检查 reCAPTCHA。PHP 代码会出现在表单的第一行之上,最好是在生成任何 HTML 之前,这样用户就可以被重定向到感谢页面。

于 2009-01-30T18:00:10.200 回答