如何使 reCAPTCHA 成为必填字段? [英] How can I make reCAPTCHA a required field?

查看:571
本文介绍了如何使 reCAPTCHA 成为必填字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Google reCAPTCHA,并且能够将 CAPTCHA 组件添加到表单内的页面中.但是当我提交表单时,没有进行验证以检查 CAPTCHA 是否已解决.

I'm using Google reCAPTCHA and have been able to add the CAPTCHA component to my page inside a form. But when I submit the form there's no validation taking place to check if the CAPTCHA has been solved.

如何在提交表单时验证 CAPTCHA 组件已解决?或者,换句话说,我如何使我的 CAPTCHA 组件成为必需?

How do I validate that the CAPTCHA component has been solved when submitting my form? Or, in other words, how do I make my CAPTCHA component required?

推荐答案

如果你想使用原生的 html5 弹出窗口,这里是解决方案

if you want to use the native html5 popups, than here is the solution

JavaScript:

JavaScript:

window.onload = function() {
    var $recaptcha = document.querySelector('#g-recaptcha-response');

    if($recaptcha) {
        $recaptcha.setAttribute("required", "required");
    }
};

CSS:

#g-recaptcha-response {
    display: block !important;
    position: absolute;
    margin: -78px 0 0 0 !important;
    width: 302px !important;
    height: 76px !important;
    z-index: -999999;
    opacity: 0;
}

这篇关于如何使 reCAPTCHA 成为必填字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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