css 将reCaptcha V2集成到网站中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css 将reCaptcha V2集成到网站中相关的知识,希望对你有一定的参考价值。

// disables form submit button until reCaptcha callback and adds grey button class
jQuery(document).ready(function ($) {
    $('#Submit').attr('disabled', 'disabled').addClass('grey_button');
});

/*
 * Validates reCaptcha response and ensures qform validation is true before submitting the form
 * Disabled submit button should prevent this function from even running.
 */
jQuery(document).ready(function ($) {
    $('#myform').submit(function () {
        var v = grecaptcha.getResponse();
        if (v.length === 0) {
            //reCaptcha not verified
            document.getElementById('captcha').innerHTML = "Please complete captcha";
            return false;
        }
        else {
            //reCaptcha verified
            console.log("reCaptcha verified");
            return true;
        }
    });
});


// reCaptcha response callback to remove possible captcha error html and enable submit button
function clearError() {
    document.getElementById('captcha').innerHTML = "";
    $('#Submit').removeAttr("disabled").removeClass('grey_button');
}
<!-- Place this at the end of your HEAD tag -->
<script src='https://www.google.com/recaptcha/api.js'></script>

<!-- Place this at the end of your form tag but before the submit button -->
<div class="g-recaptcha" id="recaptcha" data-sitekey="your_client_key" data-callback="clearError"></div>
<span id="captcha" style="color:red;"></span>
.grey_button {
    background-color: #c0c0c0 !important;
}

以上是关于css 将reCaptcha V2集成到网站中的主要内容,如果未能解决你的问题,请参考以下文章

如何将 Google Recaptcha v2 实施到限制访问 Google Recaptcha 的 Web 应用程序

将 reCAPTCHA v2 添加到我的 PHP 文件中

使用 ng-recaptcha 将 Google reCaptcha v3 集成到 Angular 应用程序中

通过 jQuery + Ajax 将带有 Google reCaptcha v2 令牌的图像文件发送到 PHP

ReCaptcha v2 客户端事件

在同一页面上验证多个 recaptcha (V2)