Merge pull request #1740 from mailpoet/form-loading
Subscription form loading on submit [MAILPOET-1567]
This commit is contained in:
@@ -54,6 +54,7 @@ function ( // eslint-disable-line func-names
|
||||
formData.data.recaptcha = window.grecaptcha.getResponse(formData.recaptcha);
|
||||
}
|
||||
|
||||
form.addClass('mailpoet_form_sending');
|
||||
// ajax request
|
||||
MailPoet.Ajax.post({
|
||||
url: window.MailPoetForm.ajax_url,
|
||||
@@ -62,49 +63,54 @@ function ( // eslint-disable-line func-names
|
||||
endpoint: 'subscribers',
|
||||
action: 'subscribe',
|
||||
data: formData.data
|
||||
}).fail(function (response) { // eslint-disable-line func-names
|
||||
form.find('.mailpoet_validate_error').html(
|
||||
response.errors.map(function (error) { // eslint-disable-line func-names
|
||||
return error.message;
|
||||
}).join('<br />')
|
||||
).show();
|
||||
}).done(function (response) { // eslint-disable-line func-names
|
||||
if (window.grecaptcha && formData.recaptcha) {
|
||||
window.grecaptcha.reset(formData.recaptcha);
|
||||
}
|
||||
return response;
|
||||
}).done(function (response) { // eslint-disable-line func-names
|
||||
// successfully subscribed
|
||||
if (
|
||||
response.meta !== undefined
|
||||
})
|
||||
.fail(function handleFailedPost(response) {
|
||||
form.find('.mailpoet_validate_error').html(
|
||||
response.errors.map(function buildErrorMessage(error) {
|
||||
return error.message;
|
||||
}).join('<br />')
|
||||
).show();
|
||||
})
|
||||
.done(function handleRecaptcha(response) {
|
||||
if (window.grecaptcha && formData.recaptcha) {
|
||||
window.grecaptcha.reset(formData.recaptcha);
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.done(function handleSuccess(response) {
|
||||
// successfully subscribed
|
||||
if (
|
||||
response.meta !== undefined
|
||||
&& response.meta.redirect_url !== undefined
|
||||
) {
|
||||
) {
|
||||
// go to page
|
||||
window.location.href = response.meta.redirect_url;
|
||||
} else {
|
||||
window.location.href = response.meta.redirect_url;
|
||||
} else {
|
||||
// display success message
|
||||
form.find('.mailpoet_validate_success').show();
|
||||
}
|
||||
form.find('.mailpoet_validate_success').show();
|
||||
}
|
||||
|
||||
// reset form
|
||||
form.trigger('reset');
|
||||
// reset validation
|
||||
parsley.reset();
|
||||
// reset captcha
|
||||
if (window.grecaptcha && formData.recaptcha) {
|
||||
window.grecaptcha.reset(formData.recaptcha);
|
||||
}
|
||||
// reset form
|
||||
form.trigger('reset');
|
||||
// reset validation
|
||||
parsley.reset();
|
||||
// reset captcha
|
||||
if (window.grecaptcha && formData.recaptcha) {
|
||||
window.grecaptcha.reset(formData.recaptcha);
|
||||
}
|
||||
|
||||
// resize iframe
|
||||
if (
|
||||
window.frameElement !== null
|
||||
// resize iframe
|
||||
if (
|
||||
window.frameElement !== null
|
||||
&& MailPoet !== undefined
|
||||
&& MailPoet.Iframe
|
||||
) {
|
||||
MailPoet.Iframe.autoSize(window.frameElement);
|
||||
}
|
||||
});
|
||||
|
||||
) {
|
||||
MailPoet.Iframe.autoSize(window.frameElement);
|
||||
}
|
||||
})
|
||||
.always(function subscribeFormAlways() {
|
||||
form.removeClass('mailpoet_form_sending');
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user