Recaptcha invisible ajax + jquery validation

Hello guys
I added recaptcha to my jquery validation of callback form. But neither validation nor captcha work now. I can send blank from.
As I understand I should check captcha (result) inside success function? Tried but can’t do it correctly. Maybe I should do smth more and youcan give some pieces of advice. Thanks a lot

jQuery(document).ready(function($) {
    $('.myform').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'; }
        $.ajax({
       type: "POST",
       url: "/reCaptcha.php",
       data: form.serialize(),
       dataType: "json", 
       error:function(){
           grecaptcha.reset(); },
       success:function(result){
         if(errors.length > 0) {
            alert('You didn't fill:\n\n' + errors);
            return false;
         }else{  $('.submit-button').val('Sending');
                 $('.submit-button').attr('disabled', 'disabled');
            return true;         
         } 
        } 
});

recaptcha.php

 jQuery(document).ready(function($) { 
    $('.myform').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'; } 
        $.ajax({ 
       type: "POST", 
       url: "/reCaptcha.php", 
       data: form.serialize(), 
       dataType: "json",  
       error:function(){ 
           grecaptcha.reset(); }, 
       success:function(result){ 
         if(errors.length > 0) { 
            alert('You didn't fill:\n\n' + errors); 
            return false; 
         }else{  $('.submit-button').val('Sending'); 
                 $('.submit-button').attr('disabled', 'disabled'); 
            return true;          
         }  
        }

Why not validate then just send the results to verification (If you’re using one) or send form, for reCaptcha isn’t going to allow a non-human to pass through anyways?

I know there’s no JSON, but this is what I’m talking about :

    $token = filter_input(INPUT_POST, 'token', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    if (!empty($token)) {
        if (hash_equals($_SESSION['token'], $token)) {
            /* The Following to get response back from Google recaptcah */
            $url = "https://www.google.com/recaptcha/api/siteverify";

            $remoteServer = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_URL);
            $response = file_get_contents($url . "?secret=" . PRIVATE_KEY . "&response=" . \htmlspecialchars($_POST['g-recaptcha-response']) . "&remoteip=" . $remoteServer);
            $recaptcha_data = json_decode($response);
            /* The actual check of the recaptcha */
            if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) {
                $data['name'] = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
                $data['email'] = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
                $data['phone'] = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
                $data['website'] = filter_input(INPUT_POST, 'website', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
                $data['reason'] = filter_input(INPUT_POST, 'reason', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
                $data['comments'] = filter_input(INPUT_POST, 'comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

                $send = new Email($data);
            } else {
                $success = "You're not a human!"; // Not of a production server:
            }
        } else {
            // Log this as a warning and keep an eye on these attempts
        }
    }

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