data-callback function not working in Invisible reCAPTCHA.

11,448 views
Skip to first unread message

Arjun M K

unread,
Jan 17, 2017, 5:43:20 AM1/17/17
to reCAPTCHA
I have implemented Invisible reCAPTCHA in a site for a register form.When I click the the submit button the reCAPTCHA will appear and after the verification it doesn't call the callback function.
This is the script.
{literal}

  <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    
 <script>
     function onSuccess = function(token) {
     document.getElementById("registerform").submit();
    }
     </script>

       {/literal}

 <form action="" method="post" name="registerform" id="registerform"  onsubmit="javascript: return checkRegFormFields(this);">
.
.
.
.
.
  <td colspan="2" class="button-row">
                <button class="btn main-button btn-danger no-bdrs btn-block btn-lg g-recaptcha" data-sitekey="mysitekey" data-callback="onSuccess"  title="Submit">  Submit </button>
  </td>

sman...@brevardmusic.org

unread,
Mar 12, 2017, 1:46:48 PM3/12/17
to reCAPTCHA
If you're experiencing the same issue as I am your data-callback function is getting called correctly, but the form submission is failing.  (If you replace that form submission line with an alert, you should successfully see the alert.)  Something happens when the recaptcha function is called that blocks the form from being submitted afterward.  I have no idea how you're supposed to submit the form after successfully passing the recaptcha, which is what led me to your post.  Hopefully someone comes along who knows how to get past this issue.

I am using the exact code from Google's developer page in the "Invoking the invisible reCAPTCHA challenge after client side validation." section.  The validation works, but the form never gets submitted.

sman...@brevardmusic.org

unread,
Mar 12, 2017, 6:08:06 PM3/12/17
to reCAPTCHA
Turns out my code was failing because the id of the button was set as "submit" which made the submit call fail.  Changing the id of the button to anything else fixed the issue.  Not sure if this will help you or not.


On Tuesday, January 17, 2017 at 5:43:20 AM UTC-5, Arjun M K wrote:

j...@cloudaccess.net

unread,
Apr 3, 2017, 7:19:49 AM4/3/17
to reCAPTCHA
I had a same problem, form submit is disabled somehow.

Any update on this #Google.

Eduardo Kortright

unread,
Apr 7, 2017, 3:11:12 PM4/7/17
to reCAPTCHA
Same problem here.  The callback function is being called, but the form will not submit.  It will submit with no problems if you use the visible reCaptcha.

Eduardo Kortright

unread,
Apr 11, 2017, 12:55:07 PM4/11/17
to reCAPTCHA
I finally figured out the problem with my implementation.  Hopefully this will help others having similar problems.

First, my form has an <input type="submit"> tag for the submit button.  The form had an explicit name attribute for the input (name="submit").  This was conflicting with the submit() method on the form.  I tried removing the name attribute completely, but I think the type="submit" must be making the name default to "submit" as before.  So I just gave the tag an explicit name attribute with a name other than "submit".  After that, the form submission started working.

Second, the callback specified on the submit button will run after the reCAPTCHA is successfully solved, so if you depend on the callback to do any validation, you must call 
grecaptcha.reset()
if the validation fails.  That will make the user solve the reCAPTCHA again, but otherwise the user would never be able to submit the form after making corrections.
Message has been deleted

andres....@bairesdev.com

unread,
Jun 2, 2017, 8:21:32 PM6/2/17
to reCAPTCHA
I am also using the exact code published here and it's not working. Clicking on Submit does nothing.
https://developers.google.com/recaptcha/docs/invisible

The button is a standard button (no input submit) and has no id. What am I missing?

sman...@brevardmusic.org wrote :

andres....@bairesdev.com

unread,
Jun 6, 2017, 7:09:41 AM6/6/17
to reCAPTCHA
Well, I managed to solve it. The problem was that you have to enable Invisible Captcha in Google's captcha admin page, and both keys are different. I've been trying in vain to use the standard keys. Later I also noticed that there's a message in the corner warning me that invisible captcha was not enabled on that site.

Miles M

unread,
Jul 21, 2017, 5:43:37 AM7/21/17
to reCAPTCHA
Yes, this is definitely the correct solution, you can't use you v2 site key, you have to register a new one if your going to use the "invisible" version.  Thank you, Andres.
Reply all
Reply to author
Forward
0 new messages