I have implemented the use of setInterval
in my recaptcha javascript code to address the issue of forms being very long, causing the token to expire and forcing users to refill the form entirely.
While I am satisfied with how the current code functions, there is one drawback - it takes 10 seconds for the token to load initially. Additionally, if a user completes filling out an input field and submits it within those 10 seconds, a recaptcha error occurs.
Is there a way to modify the code so that the initial load does not require the use of setInterval
, but subsequent loads occur at 10-second intervals?
Appreciate your assistance on this matter.
setInterval(function(){
grecaptcha.ready(function() {
grecaptcha.execute('<?php echo RECAPTCHA_SITE_KEY; ?>', {action: 'this_form'}).then(function(token) {
$('#token').val(token);
$('#action').val('this_form');
});
});
}, 10000);