By using promise, token value of g-recaptcha-response will be returned after callback then, then execute defined _submitForm above with param t which will be transfered to _submitEvent.
In your page containing form using recaptcha
/**
* Use this to check mandatory field in form
* @return mixed
* false, submission should halted
* true, continue submission
*/
_beforeSubmit = function(){};
/**
* Main event submission
*/
_submitEvent = function(token){
// Flag to avoid Bubble
if (window['_submitEvent_hited']){
console.log('Hit, exiting..');
return !1;
}
window['_submitEvent_hited'] = true;
var postdata = [];
// Collect post data
$form.find('[name]').each(function(){
var $el = $(this),
name = $el.attr('name')
;
postdata[name] = $el.val();
});
if (token)
postdata['g-recaptcha-response'] = token;
// Do your xhr here...
// $.ajax({.....})
/*
$.ajax({
method: "POST",
url: $form.attr('action'),
data: postdata,
dataType: "json",
cache: !1
})
.done(function(data){
console.log('xhr: done');
})
.fail(function(r){
console.log('xhr: fail');
})
.always(function(r){
// Dont forget to reset this state
window['_submitEvent_hited'] = null;
});
*/
};
This patch is work-around in form using ajax.
Patch applied on: InvisibleReCaptcha.php::renderFooterJS#L131
Notes:
grecaptcha.execute().then(function(token){_submitForm(token)});
By using promise, token value of
g-recaptcha-response
will be returned after callbackthen
, then execute defined_submitForm
above with paramt
which will be transfered to_submitEvent
.In your page containing form using recaptcha