0

如果你能帮助我,我真的很感激。

我有一个以这个按钮结尾的表单:

<button type="submit" value="Create" name="new">Create</button>

然后 PHP 使用以下方法对其进行处理:

if(isset($_POST['new']) && $_POST['new'] == "Create")

所以我正在尝试向其中添加 reCAPTCHA,并且我有这段代码:

<?php
require_once('recaptchalib.php'); // reCAPTCHA Library
$pubkey = ""; // Public API Key
$privkey = ""; // Private API Key

if ($_POST['doVerify']) {
  $verify = recaptcha_check_answer($privkey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
  if ($verify->is_valid) {
    # Enter Success Code
     //process form
  }
  else {
    # Enter Failure Code
    echo "You did not enter the correct words.  Please try again.";
  }
}
?>

但我不知道如何链接它们。

谢谢指教!

4

2 回答 2

0

做就是了:

<?php
require_once('recaptchalib.php'); // reCAPTCHA Library
$pubkey = ""; // Public API Key
$privkey = ""; // Private API Key

if(isset($_POST['new']) && $_POST['new'] == "Create") {
  if ($_POST['doVerify']) {
    $verify = recaptcha_check_answer($privkey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
    if ($verify->is_valid) {
      # Enter Success Code
      //process form
    }
    else {
      # Enter Failure Code
      echo "You did not enter the correct words.  Please try again.";
    }
  }
}
?>

如果表单的其余部分没有通过验证,验证 CAPTCHA 没什么意义,对吧?

于 2013-08-03T05:30:42.617 回答
0

让你的“php代码”的文件名是"capt.php"

将表单的操作更改为"capt.php"

例如: action =“capt.php”

享受!

于 2013-08-03T06:36:19.860 回答