ReCaptcha:如何在发送验证码时自动提交表单 [英] ReCaptcha: How to autosubmit the form when the captcha was send

查看:181
本文介绍了ReCaptcha:如何在发送验证码时自动提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ReCaptcha在页面上加载一些额外的数据。我希望在输入ReCaptcha时自动提交表单。所以我不需要额外的提交按钮。问题是recaptcha在iframe中加载了它的内容,所以有点困难。

I want to use ReCaptcha to load some extra data on the page. I want the form to be auto submitted when the ReCaptcha was entered. So that I don't need the extra submit button. The problem is that recaptcha loads its content inside an iframe, so its a bit difficult.

目前我有这样的表格:

<form action="javascript:getInfo(grecaptcha.getResponse(widget1));" >
      <div id="captcha"></div>
      <br>
      <input type="submit" value="Submit">
</form>

如何在提交外部表单的recaptcha提交中获得类似事件监听器的内容?

How do I get something like an Event-Listener on the recaptcha submit which submits the outer form?

推荐答案

这听起来像是一种有趣的技巧。它会减少用户的点击和击键。这是你如何做到这一点,通过听取成功的验证码响应,你将能够跟进所需的行动。这是一个示例和一些文档。 https://developers.google.com/recaptcha/docs/display#example

That's sounds like an interesting technique. It would cut down on the clicking and key strokes for the user. Here is how you could do that, by listening for the successful captcha response you would be able to follow up with the desired action. Here is an example and some documentation. https://developers.google.com/recaptcha/docs/display#example

var RC2KEY = 'sitekey';

function reCaptchaVerify(response) {
  if (response === document.querySelector('.g-recaptcha-response').value) {
    document.forms['form-name'].submit();
  }
}

function reCaptchaExpired() {
  /* do something when it expires */
}

function reCaptchaCallback() {
  grecaptcha.render('id', {
    'sitekey': RC2KEY,
    'callback': reCaptchaVerify,
    'expired-callback': reCaptchaExpired
  });
}

<script src='https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit'></script>

这篇关于ReCaptcha:如何在发送验证码时自动提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆