UndefinedOffset / silverstripe-nocaptcha

A spam protector and form field using Google's reCAPTCHA v2 or optionally a foundation v3 implementation
BSD 3-Clause "New" or "Revised" License
31 stars 37 forks source link

Wrong form submitted when multiple captcha used on same page #55

Open gurucomkz opened 4 years ago

gurucomkz commented 4 years ago

When 2 forms on a page both with invisible captcha, I see that only one of them is submitted regardless of which form I actually fill in. I.e. I fill in form 1 but form 2 is being submitted to the server. Found that var form is not retained for window['Nocaptcha-'+_noCaptchaFields[i]].

For a workaround, had to use another wrapper function to ensure the form var keeps its value.

window['Nocaptcha-'+_noCaptchaFields[i]]=(function(form){
    return function(token) {
        return new Promise(function(resolve, reject) {
            if(typeof jQuery!='undefined' && typeof jQuery.fn.validate!='undefined' && superHandler) {
                superHandler(form);
            }else {
                form.submit();
            }

            resolve();
        });
    }
})(form);