Check if reCAPTCHA has been marked

2

I am using an email form in PHP with POST method and I use Google ReCaptcha. I need to check in javascript or jQuery, if reCAPTCHA has been marked to only enable the submit button.

The current code:

var checado = false;

jQuery("#recaptcha-anchor").each(function(){
 if($(this).prop("checked")=="checked")
   checado=true;
});

if(checado=true){
 return true;
 jQuery('#submitBtn').prop('disabled', false);

}else{
 return false;    
}

NOTE: I do not have access to PHP code if it needs to be changed.

    
asked by anonymous 31.10.2017 / 16:08

1 answer

3

Translation of the response in StackOverflow in English:

Google has a call back option for when the checkbox is checked.

  

Google has a return for when the checkbox is checked.

In% of the caller of reCAPTCHA add this:

div

It will look like this:

<div class="g-recaptcha" data-callback="recaptchaCallback" data-sitekey="sua_key"></div>

Then you create your function:

 function recaptchaCallback()
 {
    jQuery('#submitBtn').prop('disabled', false);
 }

When reCAPTCHA is checked, and the box checked, callback is fired and its function is executed.

You can access the original answer in English .

Remembering that your original code has code after data-callback="nome_da_funcao" , when you use return you make an exit of your function, and the code after return is inaccessible, so it should come before return .

    
31.10.2017 / 16:45