[英]Google Recaptcha V3 - Widget Id when loading captcha through URL
I am implementing the Recaptcha V3 on my site, and I could not find a proper way to reset the token if my request has failed.我正在我的网站上实施 Recaptcha V3,如果我的请求失败,我找不到重置令牌的正确方法。
Following the documentation, to load the recaptcha I need to include the following script on my page:按照文档,要加载重新验证码,我需要在我的页面上包含以下脚本:
<script src='https://www.google.com/recaptcha/api.js?render=MY_KEY'></script>
Also I am binding the captcha token to a field, to validate on my back end when the customer choose to send an e-mail:此外,我将验证码令牌绑定到一个字段,以便在客户选择发送电子邮件时在我的后端进行验证:
grecaptcha.ready(function() {
grecaptcha.execute('MY_KEY', {
action : 'homepage'
}).then(function(token) {
$("#recaptcha").val(token);
});
});
So I have mainly two steps:所以我主要有两个步骤:
If some error occur during the second step, I was unable to find a way to reset the current captcha on the page, since it was already validated if I try again it is no longer valid.如果在第二步中发生某些错误,我将无法找到重置页面上当前验证码的方法,因为如果我再次尝试它已被验证,它就不再有效。
I have tried the grecaptcha.reset()
, but without the widgetId
the following message appears: Uncaught Error: No reCAPTCHA clients exist.
我已经尝试了
grecaptcha.reset()
,但没有widgetId
出现以下消息: Uncaught Error: No reCAPTCHA clients exist.
How can I get the widget id when rendering through the script?通过脚本渲染时如何获取小部件 ID?
As I understand from Recaptcha V3 you have to call execute again try to do it like this正如我从 Recaptcha V3 中了解到的,您必须再次调用 execute 尝试这样做
let createNewToken = () => {
grecaptcha.ready(function() {
grecaptcha.execute('code', {action: 'homepage'}).then(function(token) {
console.log(token);
});
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.