php - 将 reCAPTCHA 响应更改为alert(),而不是加载新页面

标签 php recaptcha

我正在使用 reCAPTCHA,如果 CATPCHA 被错误地填写为 alert();,我想显示响应,而不是加载新页面。我怎样才能做到这一点?

这是表单操作:

<form id="form" method="POST" action="verify.php">

在 verify.php 文件中使用此内容:

<?php
  require_once('recaptchalib.php');
  $privatekey = "(my 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
  }
  ?>

最佳答案

在表单提交上调用您的方法,例如--

<form id="form" method="POST" action="verify.php" onsubmit="mymethod()" >

或者使用jquery,类似的东西--

<script>

    $("form").submit(function() {
      if ($("input:first").val() == "correct") {
        $("span").text("Validated...").show();
        return true;
      }
      $("span").text("Not valid!").show().fadeOut(1000);
      return false;
    });
</script>

关于php - 将 reCAPTCHA 响应更改为alert(),而不是加载新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11259510/

相关文章:

php - 如何替换上传文件文件名中的空格

php - HTML 复选框表单和 HTTP URL

recaptcha - 使用 reCAPTCHA v3 处理错误

browser - 击败验证码绕过的策略

javascript - 如何正确连接reCAPTCHA?

php - 更改放置在 DIV 中的 recaptcha 表单的背景颜色

php - 我想在 codeigniter session 中保存用户和管理员数据,但我无法将两者都保存到 user_data。那我该怎么办?

Java 代码等价于以下 php 代码

php - throw 是如何工作的?

CSS - reCAPTCHA 图像宽度