Google reCAPTCHA data-callback not working
48,190
Change your script to...
<script type="text/javascript">
function recaptcha_callback(){
alert("callback working");
$('.button').prop("disabled", false);
}
</script>
By placing your function inside the document.ready
event, it is not in the global scope and therefore unreachable by the captcha control.
Related videos on Youtube
![roshambo](https://i.stack.imgur.com/R7Bz4.jpg?s=256&g=1)
Author by
roshambo
Updated on July 09, 2022Comments
-
roshambo almost 2 years
I have built a email newsletter signup form which posts into mailchimp from my website. I have Google reCAPTCHA added to the form and have a data-callback to enable the submit button as it is initially disabled. This was working fine in all browsers last night and did tests with success & signed off on it..and went home. I got in this morning and found the subscribe button will not enable / data-callback does not work? Strange..
Callback
<div class="g-recaptcha" data-callback="recaptcha_callback" data-sitekey="xxxxx"></div>
Input button at bottom of form
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button" disabled>
Scripts
<script src='https://www.google.com/recaptcha/api.js'></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { function recaptcha_callback(){ alert("callback working"); $('.button').prop("disabled", false); } )}; </script>
-
John Lehmann about 6 yearsRelated question stackoverflow.com/q/44567543/317110
-
-
Gsuz almost 6 yearsIs this a proper solution for recaptcha? I mean does the recaptcha_callback code only run when the recaptcha is successfully validated?
-
m-albert over 5 years@Gsuz, the
data-callback="recaptcha_callback"
in the original question specifies therecaptcha_callback
function as the callback. -
Lukas over 2 years@Gsuz Yes. Source: developers.google.com/recaptcha/docs/display#render_param