我有一个表单filename.php
,在其中我调用了一个 jquery 函数,我想在该 jquery 函数中包含以下 php 代码
<?php
//require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>
我怎样才能做到这一点?
编辑
我想在提交表单时定义一个变量:
<?php
//require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
$cverify = false;
} else {
// Your code here to handle a successful verification
$cverify = true;
}
?>
现在在 js 代码中,如果我有以下代码并且如果我输入正确的验证码,那么它也会警告 false
var cverify = '<?php echo json_encode($cverify); ?>';
alert(cverify);
那么单击提交按钮时如何获得检查验证?