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>
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.
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).
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With