错误消息我们检测到您的站点未验证reCAPTCHA解决方案。这是在您的站点上正确使用reCAPTCHA所必需的。我创建了这段reCaptcha代码,它工作得很好,但我不知道如何验证它,我以为它是用函数grecaptcha.getResponse();
验证的,但事实并非如此。显然,recaptcha在网站上运行良好,但我只是在谷歌管理中看到了下一条消息:
要求: javascript 1.不要在表单中使用,只能在表单中使用action="file.php"
函数。
<!DOCTYPE>
<html>
<head >
<title></title>
<script src='https://www.google.com/recaptcha/api.js'></script>
<script type="text/javascript">
function get_action() {
var v = grecaptcha.getResponse();
console.log("Resp" + v );
if (v == '') {
document.getElementById('captcha').innerHTML = "You can't leave Captcha Code empty";
return false;
}
else {
document.getElementById('captcha').innerHTML = "Captcha completed";
return true;
}
}
</script>
</head>
<body>
<form id="form1" onsubmit="return get_action();">
<div>
<div class="g-recaptcha" data-sitekey="6LdNIlAUAAAAADS_uVMUayu5Z8C0tw_jspdntbYl"></div>
</div>
<input type="submit" value="Button" />
<div id="captcha"></div>
</form>
</body>
</html>
你能帮我吗?请。我将非常感谢我如何验证它,因为我在提交时需要使用javascript函数onsubmit="return get_action();"
而不是action="file.php"
*?:
发布于 2018-04-01 06:35:00
这就是我的建议。
1.)将查询字符串附加到reCPATCHA脚本。此外,为了获得更好的性能,防止渲染阻塞,可以将async defer
属性添加到<script ...>
。为了正确起见,您应该将脚本移到DOM中的<form>
之后。...</form> <script src='https://www.google.com/recaptcha/api.js?onload=recaptchaRender' async defer></script>
。
2.)添加一个名为recaptchaRender()
的新函数。来处理你对谷歌的验证,并卸载对你的回调get_action
的响应。将RECAPTCHA_SITE_KEY
to替换为您的谷歌网站密钥。
function recaptchaRender{
grecaptcha.render( 'reCaptchSubmit', {
'sitekey': 'RECAPTCHA_SITE_KEY',
'callback': get_action
});
}
3.)将id="reCaptchSubmit"
添加到您的提交按钮。
4.)从表单元素中删除onsubmit="return get_action();"
。
从本质上说,你错过了你的脚本和Google之间的身份验证。这不会处理表单验证,但至少会让您转到呈现回调get_action()
,在那里您可以处理验证--可能需要重命名为更相关的名称,如validateForm()
等
https://stackoverflow.com/questions/49592772
复制相似问题