看不见的reCAPTCHA-缺少必需的参数:sitekey [英] Invisible reCAPTCHA - Missing required parameters: sitekey

查看:849
本文介绍了看不见的reCAPTCHA-缺少必需的参数:sitekey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有类g-recaptcha的按钮为每个表单动态加载Invisible reCAPTCHA.

I am loading Invisible reCAPTCHA dynamically for every form with button that has class g-recaptcha .

我遇到的问题是验证码没有正确加载,我不确定为什么.我遵循了验证码网站上的文档,但不确定如何以及为什么会收到此错误:

Problem that I have is that captcha is not loading correctly and I am not sure why. I followed documentation on captcha website and I am not sure how and why I got this error:

Uncaught Error: Missing required parameters: sitekey

有人知道问题出在哪里吗?

Does someone knows where is the problem?

这是我使用的代码:

<script src='https://www.google.com/recaptcha/api.js?onload=onloadCallback&hl={{  app.request.locale|default(defaultLang) }}' async defer></script>

JS

var onloadCallback = function () {
    $("button.g-recaptcha").each(function () {
        var el = $(this);
        //SITE_KEY is actually hard coded string.
        //It is string that google provided. I just remove it for security reasons...
        grecaptcha.render($(el).attr("id"), {
            "sitekey": SITE_KEY,  
            "size": "invisible",
            "badge": "inline",
            "callback": function (token) {
                $(el).parent().find(".g-recaptcha-response").val(token);
                $(el).closest("form").submit();
            }
        }, true);
    });

    $("button.g-recaptcha").click(function(event) {
        event.preventDefault();
        grecaptcha.execute();
    });
};

HTML示例:

<button 
    type="submit" 
    id="submitReviewButton"
    class="btn btn-lg btn-submit btn--green g-recaptcha"
 >
    {{ "review.submit_your_review"|trans }}
</button>

推荐答案

您在这里缺少重要的部分. api小部件必须显式呈现.只需将render=explicit添加到recaptcha api脚本.

You are missing an important part here. The api widget must rendered explicitly. Just add render=explicit to recaptcha api script.

<script src='https://www.google.com/recaptcha/api.js?
onload=onloadCallback
&render=explicit
&hl={{app.request.locale|default(defaultLang) }}' async defer>
</script>

阅读Google文档( reCAPTCHA V2 | reCAPTCHA-显式呈现reCAPTCHA小部件).

Read the Google doc (reCAPTCHA V2 | reCAPTCHA - Explicitly render the reCAPTCHA widget).

这篇关于看不见的reCAPTCHA-缺少必需的参数:sitekey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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