Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invisible reCAPTCHA - Missing required parameters: sitekey

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?

Here is code I use:

<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();
    });
};

EXAMPLE OF HTML:

<button 
    type="submit" 
    id="submitReviewButton"
    class="btn btn-lg btn-submit btn--green g-recaptcha"
 >
    {{ "review.submit_your_review"|trans }}
</button>
like image 357
jureispro Avatar asked Mar 08 '18 13:03

jureispro


People also ask

What is data Sitekey in reCAPTCHA?

The Site Key is used to render the reCAPTCHA within a page, and the Secret Key is used for server-side validation. The keys are unique to the domain for which they are registered.

What does missing required parameters reCAPTCHA mean?

When customers are logging in they are periodically seeing the error "missing required parameters recaptcha!" it appears the error is occuring when a customer attempts a login quickly (using saved credentials).


1 Answers

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>

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

like image 86
Roshana Pitigala Avatar answered Oct 12 '22 02:10

Roshana Pitigala