Recaptcha problem

I have a problem with the form I am using in my web page.

It allows recaptcha, but it also sends an email without checking the fields in the recaptcha field. This form uses Ajax and PHP.

I pasted the following code:

<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> 

      

Many thanks.

David.

0


source to share


1 answer


The problem is that you need to validate the reCAPTCHA before you render the form again. The PHP code will go above the first line of the form, right before any HTML code is generated, so that the user can be redirected to the thank you page.



+1


source







All Articles