albertcht / invisible-recaptcha

An invisible reCAPTCHA package for Laravel, Lumen, CI or native PHP.
MIT License
603 stars 162 forks source link

invisible recaptcha with Jquery Validation #38

Closed garbinmarcelo closed 7 years ago

garbinmarcelo commented 7 years ago

How to use with jquery validation (https://jqueryvalidation.org/)? I'm using with this package for laravel https://github.com/proengsoft/laravel-jsvalidation

I try this, however the form or captcha is triggered before even validating all the fields.

_submitEvent = function() {
        $('form').valid();
            _submitForm();
    }

I would like the captcha (and the correct one would be) to be triggered only when all the form inputs are valid. The package is fantastic, but I'd like to use it with Jquery Validation.

Any ideas to help me?

albertcht commented 7 years ago

Hi @marcelogarbin , sorry for responding late. In version 1.7, I add a further function you can call before captcha validation. See: https://github.com/albertcht/invisible-recaptcha#take-control-of-submit-function So you can try to do like this:

_beforeSubmit = function() {
    $('form').valid();
    // return true if your form validation is success, otherwise return false
    return false;
}
garbinmarcelo commented 7 years ago

@albertcht Thank's for your respost. I'm still testing. But I believe it will work as expected. When I'm done, I'll give you some feedback. I think I'll finish it by tomorrow.

garbinmarcelo commented 7 years ago

Problem solved. Using the function to resolve conflicts between the 2 packages (laravel-jsvalidation and invisible-recaptcha): https://github.com/albertcht/invisible-recaptcha#take-control-of-submit-function

$(document).ready(function() {
    //g-recaptcha invisible
    if($('#_g-recaptcha').length > 0){
        _beforeSubmit = function() {
            if($('form').valid())
                return true;

            return false;
        }
    }
});

Thank's @albertcht