reCaptcha3 and timeout solution

If reCaptcha3 token is generated on page load then it’s not practical as it times out in a few minutes, therefore the form submission will fail. Better to generate it on form submission like that.

var webQueryForm = $('#webQuery');
webQueryForm.submit(function(event) {
  e.preventDefault();
  grecaptcha.execute('MYSITEKEY(PUBLIC)', {
     action: 'contact'
     }).then(function(token) {
     $('#recaptchaToken').val(token);
    webQueryForm.submit();
  });
});

source: https://jsfiddle.net/skobaljic/rL6fux5w/2/

Leave a comment

Design a site like this with WordPress.com
Get started