I have successfully implemented the new Google INVISIBLE reCaptcha on several sites, however it conflicts with jQuery validate (), so that js validation is no longer executed when submitting a button / form, and reCaptcha instantly starts. If the user forgets to fill out the requried form field, he will have to wait for the server to respond and return to it next time.
jQuery.validate () supports the callback, but because it is hardcoded inside the CMS inner class, is there a way that I can somehow change it (for example, from the front-end theme, in the load document, when the confirmation code is already displayed)?
Or another idea would be to somehow delay the captcha callback so that the validation step could get a chance to run.
Thanks!
jQuery Form validation: (hard-coded in the kernel, cannot be changed if I do not edit the main file or extend the class / clone function - not optimal)
<script type="text/javascript"> $(document).ready(function(){ $("form[name=comment_form]").validate({ rules: { body: { required: true, minlength: 1 }, authorEmail: { required: true, email: true } }, wrapper: "li", errorLabelContainer: "#comment_error_list", invalidHandler: function(form, validator) { $('html,body').animate({ scrollTop: $('#comment_error_list').offset().top }, { duration: 250, easing: 'swing'}); }, submitHandler: function(form){ $('button[type=submit], input[type=submit]').attr('disabled', 'disabled'); form.submit(); } }); }); </script>
reCaptcha explicit render:
<script type='text/javascript'> var renderInvisibleReCaptcha = function() { for (var i = 0; i < document.forms.length; ++i) { var form = document.forms[i]; var holder = form.querySelector('.invisible-recaptcha'); if (null === holder) continue; (function(frm){ var holderId = grecaptcha.render(holder, { 'sitekey': 'my-key-here', 'badge': 'inline', 'size': 'invisible', 'callback': function (recaptchaToken) {HTMLFormElement.prototype.submit.call(frm);}, 'expired-callback': function(){grecaptcha.reset(holderId);} }); frm.onsubmit = function (evt){evt.preventDefault();grecaptcha.execute(holderId);}; })(form); } }; </script>