Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google reCAPTCHA fail for second time submit

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.

like image 237
user3538235 Avatar asked Jun 23 '15 06:06

user3538235


People also ask

How do I fix Google reCAPTCHA verification failed?

Help for reCAPTCHA usersMake sure your browser is fully updated (see minimum browser requirements) Check that JavaScript is enabled in your browser. Try disabling plugins that might conflict with reCAPTCHA.

What does Google reCAPTCHA verification failed Please try again later mean?

It looks like you may have the W3 Total Cache plugin activated on your site. In many cases, caching and minification can result in the reCAPTCHA script being loaded incorrectly.

Why does my reCAPTCHA keep failing?

If reCAPTCHA is not working in your browser, then this issue may arise due to several reasons that include: You are using an older version of your web browser. VPN or proxy service is interrupting with reCAPTCHA. The browser is infected with malware like a browser hijacker, trojan, adware tool, etc.

Why I am getting captcha again and again?

Reasons why you might get multiple CAPTCHAs:Your computer could be infected and be attacking other computers and websites without your knowledge. This is rare but possible. Make sure your antivirus is up to date and your computer is malware-free.


2 Answers

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

like image 59
Shailendra2014 Avatar answered Sep 27 '22 19:09

Shailendra2014


Those who have the same problem and meet this topic during research; If you experience problem when you render the captcha automatically, try to render it explicitly. In order to do this, add following code inside body tag.

<script src="https://www.google.com/recaptcha/api.js?onload=recaptchaCallback&render=explicit&hl=tr" async defer></script>
  1.                         var recaptchaCallback = function () {
                               //  alert("grecaptcha is ready!");
                                grecaptcha.render("YOUR HTML DIV ID", {
                             'sitekey': 'YOUR SITE KEY', 
                                });
                            };
    
  2. I'm using AJAX to check registration form and get response. So I have added reset function to my AJAX response.

    $('#frmRegistration').submit(function () { $.ajax({ url: "_ajax/_ajaxRegistration.php", type: "POST", data: $('#frmRegistration').serialize(), success: function (reply) { $('#resultRegistration').html(reply); grecaptcha.reset(); } }); });

Reference Google reCaptcha explicit render.

like image 28
leg0las Avatar answered Sep 27 '22 20:09

leg0las