【发布时间】:2017-09-05 00:08:17
【问题描述】:
我正在尝试实现新的 Google Invisible Recaptcha,但由于某种原因,我还不知道自动 html 表单验证和所需的属性似乎无法与 Recaptcha 一起工作。我猜这是因为 onSubmit() 函数回调。有人可以让我知道如何解决这个问题吗?提前致谢。
以下是我使用 Google Invisible Recaptcha 实现的表单。数据站点密钥已被有意删除。
<html>
<head>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(token) {
document.getElementById("contactForm").submit();
}
</script>
</head>
<body>
<form id="contactForm" action="#" method="POST">
<p>Leave a Message</p>
<label for="inputName">Name</label>
<input type="text" name="Name" id="inputName" placeholder="Name" required> <br>
<label for="inputEmail">Email</label>
<input type="email" name="Email" id="inputEmail" placeholder="Email Id" required> <br>
<label for="inputMessage">Message</label>
<input type="text" name="Message" id="inputMessage" placeholder="Message" required><br/>
<button class="g-recaptcha" type="submit" data-sitekey="//site-key" data-badge="bottomleft" data-callback='onSubmit'>Submit</button>
<button type="reset">Reset</button>
</form>
</body>
</html>
【问题讨论】:
-
您确定使用站点密钥和秘密确认吗??
-
是的,我使用了正确的站点密钥和密钥。这不是我第一次使用 Google Captcha。当我尝试使用他们新的 v2 Invisible Captcha 时遇到了这个问题。
-
需要调用 grecaptcha.execute() 方法。试试this例子
标签: javascript html captcha recaptcha