开发者

recaptcha ajax validation

开发者 https://www.devze.com 2023-03-22 14:34 出处:网络
i found this tutorial about how to validate recaptcha with jquery tutorial and i wonder where should i put the php code to send the email?

i found this tutorial about how to validate recaptcha with jquery tutorial

and i wonder where should i put the php code to send the email?

i just paste this here to show the code.. can somebody help me pls?

<?php
require_once('inc/recaptchalib.php');
$publickey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // you got this from the signup page
$privatekey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<title>Validating reCaptcha with jQuery and AJAX</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="jquery-1.2.3.js"></script>
<script type="text/javascript">
function validateCaptcha()
{
    challengeField = $("input#recaptcha_challenge_field").val();
    responseField = $("input#recaptcha_response_field").val();
    //alert(challengeField);
    //alert(responseField);
    //return false;
    var html = $.ajax({
    type: "POST",
    url: "ajax.recaptcha.php",
    data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
    async: false
    }).responseText;

    if(html == "success")
    {
        $("#captchaStatus").html("Success. Submitting form.");
        return false;
        // Uncomment the following line in your application
        //return true;
    }
    else
    {
        $("#captchaStatus").html("Your captcha is incorrect. Please try again");
        Recaptcha.reload();
        return false;
    }
}
</script>
<style>
#login form
{
    width: 320px;
}
</style>
</head>
<body class="login" onKeyPress="keyCheck(event)">
<div id="login">
<form name="loginform" id="loginform" action="#" method="post" onSubmit="return validateCaptcha()">
    <p>
        <label>Name<br />
        <input type="text" id="name" name="name" class="input" value="" size="20" tabindex="20" /></label>
    </p>
    <p><?php echo recaptcha_get_html($publickey);?></p>
    <p style="color: red;" id="captchaStatus">&nbsp;</p>
    <input type="submit" name="Submit" value="Submit">
</form>
</div>
</body>
</html>

<?php
require_once('inc/recaptchalib.php');
$publi开发者_如何学Gockey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // you got this from the signup page
$privatekey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";

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

if ($resp->is_valid) {
    ?>success<?
}
else
{
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
}


You should put your code to send the email near the end of your code inside of:

if ($resp->is_valid) {
    ?>success<?
}

Replace ?>success<? with whatever you're using to send the email.

0

精彩评论

暂无评论...
验证码 换一张
取 消