Async validation to external email provider
Hi,
MktoForms2.whenReady(function (mktoForm) {
mktoForm.onValidate(extendedEmailValidation);//Validate form
//Extended Validation
async function extendedEmailValidation(nativeValid) {
if (!nativeValid) return;
mktoForm.submittable(true);
var currentValues = mktoForm.getValues();
var emailvalid = await emailValidation(currentValues['email']); //Ajax call to external provider
if ( !emailvalid ) {
mktoForm.submittable(false);
}
}
});
const emailValidation = function (email) {
return new Promise( (resolve) => {
jQuery.get( 'https://externalemailprovider....../'+email, function( data ) {
if ( typeof data === 'undefined' || typeof data.validation === 'undefined' ) { return resolve(false); }
if ( data.validation != 'Valid' ) { return resolve(false); }
return resolve(true);
});
});
}
I would like to know if it's possible to call a promise or an async function inside the onValidate Marketo api method . The idea is once the user has filled out the form, check against an external API some fields, such as email or phone. The idea is similar to the above code.
Thank you for your help.
David