Add reCaptcha to my validation form (jQuery+Ajax)

Hello guys

I have contact popup form and validation script from it

jQuery(document).ready(function($) { 
         $('.callback-form-container').submit(function() { 
            var formInputs = $(this).find('.validate'); 
             var errors = ''; 
             $(formInputs).each(function() { 
                if($.trim(this.value) == '') { 
                   fieldLabel = $(this).parent().find('span.label-text').html(); 
                     errors += '- ' + fieldLabel + '\n'; 
                 } 
             }); 
             if(errors.length > 0) { 
                 alert('Input boxes:\n\n' + errors); 
                 return false; 
             } 
             else 
             { 
                 $('.submit-button').val('Wait please'); 
                 $('.submit-button').attr('disabled', 'disabled'); 
                 return true              
             }            
             });          
         });  
});

captcha.php for $.ajax

 
 if(isset($_POST['g-recaptcha-response'])) { 
     $result = json_decode(file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=6Le(secret code)7O&response=$_POST["g-recaptcha-response"]&remoteip=$_SERVER["REMOTE_ADDR"]'), TRUE); 

     if($result['success'] == 1) { 
         console.log("Ok"); 

     } else { 
         grecaptcha.reset(); 
     } 
 } 

Now I need to integrate invisible reCaptcha. I already have action in my tag that why I can’t add one more and sholud add it to jQuery.
I’ve never have a deal with any captcha before.

As i understand I need 5 steps. I’ve made some attempts to change form but no result.

  1. Cancel default action (preventDefault?)
  2. Make button disabled
  3. Input boxes validation
  4. Check captcha
  5. If captcha is ok execute ajax code

Help me please to add recaptcha to my form.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.