Google reCAPTCHA fail for second time submit

user3538235 picture user3538235 · Jun 23, 2015 · Viewed 9.5k times · Source

I implement the reCAPTCHA in this tutorial,

https://codeforgeek.com/2014/12/google-recaptcha-tutorial/

which work well for the first time submit. The problems I have are:

  1. I send the captcha with other form data e.g. username , email etc.... so if captcha is correct but other not , the user will send it again, but the second time it return "{ "success": false }"

  2. if I idle it for ~2 min , it will session expire and if I select the box it pop up alert and warning something like " can not refresh : invalid parameter", and I can not select the box again

How to fix those problem? Thanks a lot.

Answer

Shailendra2014 picture Shailendra2014 · Jun 23, 2015

Google reCAPTCHA gives these two functions: I always use this in all my AJAX powered forms.

grecaptcha.getResponse()

grecaptcha.reset();

For both of your problems, use the second function whenever you need in your JavaScript code.

Remember this works if you have only one CAPTCHA in your page. If you have more than two CAPTCHAs use their IDs as explained in Google Docs

https://developers.google.com/recaptcha/docs/display#js_api