0
我对PHP不太擅长,所以我在将RECAPTCHA与现有验证集成时遇到了问题。将Recaptcha与现有表单验证集成
$post = $_POST;
$samples = Array();
if(isset($post['business_samples'])) {
foreach($post['business_samples'] as $sample) {
$samples[] = $sample;
}
} else {
$tmp = explode("\n", $post['samples']);
foreach($tmp as $sample) {
$samples[] = $sample;
}
}
$errors = Array();
if(empty($post['contact_name'])) {
$errors[] = "You must provide a valid contact name.";
}
if(isset($post['business_samples'])) {
if(empty($post['company_name'])) {
$errors[] = "You must provide a valid company name.";
}
}
if(empty($post['company_size'])) {
$errors[] = "You must provide a valid company size.";
}
if(empty($post['address'])) {
$errors[] = "You must provide a valid address.";
}
if(empty($post['city'])) {
$errors[] = "You must provide a valid city.";
}
if(empty($post['state'])) {
$errors[] = "You must provide a valid state.";
}
if(empty($post['zip'])) {
$errors[] = "You must provide a valid zip.";
}
if(count($errors) != 0) {
$json = '{"success":false, "errors": [';
foreach($errors as $error) {
$json .= '"'.$error.'",';
}
$json .= '""]}';
echo $json;
exit;
}
这应该是超出现有代码上方的形式。
?>
<?php require_once('recaptchalib.php');
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$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
}
?>
帮助将非常感激。
它似乎把错误放在我想要的地方,但现在它只是得到错误“reCAPTCHA错误:不正确的captcha-sol”并不重要,如果答案是对的或错误的。我错过了什么? – john
我认为这可能与您的表单有关,请在[pastie](http://pastie.org)上发布您的表单代码或类似内容。 – Nexerus