出于安全原因,我尝试在我的联系表单中添加隐形recaptcha。
我在控制台中收到此错误:
未捕获的TypeError:document.getElementById(...)。submit不是 功能
我哪里错了?
必要的属性是类名' g-recaptcha',data-sitekey属性中的站点键,以及用于处理data-callback属性中验证码完成的JavaScript回调的名称
Google ReCaptcha documentation。
以下是详细信息:
HTML
Apple LLVM 8.1
JS
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(data) {
document.getElementById("contact").submit();
}
</script>
</head>
<body>
<p class="contacts__form-title">Title</p>
<form action="results.php" class="js-form" id="contact" method="post" name="contact">
<div class="form-group">
<input class="form-field js-field-name" placeholder="Your name" required="" type="text"> <span class="form-validation"></span> <span class="form-invalid-icon"><i aria-hidden="true" class="mdi mdi-close"></i></span>
</div>
<div class="form-group">
<input class="form-field js-field-email" placeholder="Your e-mail" required="" type="email"> <span class="form-validation"></span> <span class="form-invalid-icon"><i aria-hidden="true" class="mdi mdi-close"></i></span>
</div>
<div class="form-group">
<textarea class="form-field js-field-message" placeholder="Type the message here" required=""></textarea> <span class="form-validation"></span> <span class="form-invalid-icon"><i aria-hidden="true" class="mdi mdi-close"></i></span>
</div><button class="site-btn site-btn--form g-recaptcha" data-badge="invisible" data-callback="onSubmit" data-sitekey="6LdZIzkUAAAAAKLqsuoYZIh2cZqy3s0nwhkZpEC9" type="submit" value="Send">Send</button>
</form>
<script src="assets/js/jquery-2.2.4.min.js"></script>
</body>
</html>