Form submit fix + default styles
This commit is contained in:
@ -1,3 +0,0 @@
|
|||||||
@import 'nib'
|
|
||||||
|
|
||||||
@require 'common'
|
|
||||||
|
@ -29,57 +29,59 @@ define('public', ['mailpoet', 'jquery', 'jquery-validation'],
|
|||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
// setup form validation
|
// setup form validation
|
||||||
$('form.mailpoet_form').validate({
|
$('form.mailpoet_form').each(function() {
|
||||||
submitHandler: function(form) {
|
$(this).validate({
|
||||||
var data = $(form).serializeArray() || {};
|
submitHandler: function(form) {
|
||||||
|
var data = $(form).serializeArray() || {};
|
||||||
|
|
||||||
// clear messages
|
// clear messages
|
||||||
$(form).find('.mailpoet_message').html('');
|
$(form).find('.mailpoet_message').html('');
|
||||||
|
|
||||||
// check if we're on the same domain
|
// check if we're on the same domain
|
||||||
if(isSameDomain(MailPoetForm.ajax_url) === false) {
|
if(isSameDomain(MailPoetForm.ajax_url) === false) {
|
||||||
// non ajax post request
|
// non ajax post request
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// ajax request
|
// ajax request
|
||||||
MailPoet.Ajax.post({
|
MailPoet.Ajax.post({
|
||||||
url: MailPoetForm.ajax_url,
|
url: MailPoetForm.ajax_url,
|
||||||
token: MailPoetForm.token,
|
token: MailPoetForm.token,
|
||||||
endpoint: 'subscribers',
|
endpoint: 'subscribers',
|
||||||
action: 'save',
|
action: 'save',
|
||||||
data: formatData(data),
|
data: formatData(data),
|
||||||
onSuccess: function(response) {
|
onSuccess: function(response) {
|
||||||
if(response !== true) {
|
if(response !== true) {
|
||||||
// errors
|
// errors
|
||||||
$.each(response, function(index, error) {
|
$.each(response, function(index, error) {
|
||||||
$(form)
|
$(form)
|
||||||
.find('.mailpoet_message')
|
.find('.mailpoet_message')
|
||||||
.append('<p class="mailpoet_validate_error">'+
|
.append('<p class="mailpoet_validate_error">'+
|
||||||
error+
|
error+
|
||||||
'</p>');
|
'</p>');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// successfully subscribed
|
// successfully subscribed
|
||||||
if(response.page !== undefined) {
|
if(response.page !== undefined) {
|
||||||
// go to page
|
// go to page
|
||||||
window.location.href = response.page;
|
window.location.href = response.page;
|
||||||
} else if(response.message !== undefined) {
|
} else if(response.message !== undefined) {
|
||||||
// display success message
|
// display success message
|
||||||
$(form)
|
$(form)
|
||||||
.find('.mailpoet_message')
|
.find('.mailpoet_message')
|
||||||
.html('<p class="mailpoet_validate_success">'+
|
.html('<p class="mailpoet_validate_success">'+
|
||||||
response.message+
|
response.message+
|
||||||
'</p>');
|
'</p>');
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset form
|
||||||
|
$(form).trigger('reset');
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset form
|
|
||||||
$(form).trigger('reset');
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,9 @@ class Widget extends \WP_Widget {
|
|||||||
$this->id_base
|
$this->id_base
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$form_id = $this->id_base.'_'.$this->number;
|
||||||
|
$form_type = 'widget';
|
||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
|
|
||||||
// before widget
|
// before widget
|
||||||
@ -73,12 +76,14 @@ class Widget extends \WP_Widget {
|
|||||||
// title
|
// title
|
||||||
$output .= $before_title.$title.$after_title;
|
$output .= $before_title.$title.$after_title;
|
||||||
|
|
||||||
// form
|
// container
|
||||||
$form_id = $this->id_base.'_'.$this->number;
|
|
||||||
$form_type = 'widget';
|
|
||||||
|
|
||||||
$output .= '<div class="mailpoet_form mailpoet_form_'.$form_type.'">';
|
$output .= '<div class="mailpoet_form mailpoet_form_'.$form_type.'">';
|
||||||
|
|
||||||
|
// styles
|
||||||
|
$styles = '.mailpoet_validate_success { color:#468847; }';
|
||||||
|
$styles .= '.mailpoet_validate_error { color:#B94A48; }';
|
||||||
|
$output .= '<style type="text/css">'.$styles.'</style>';
|
||||||
|
|
||||||
$output .= '<form '.
|
$output .= '<form '.
|
||||||
'id="'.$form_id.'" '.
|
'id="'.$form_id.'" '.
|
||||||
'method="post" '.
|
'method="post" '.
|
||||||
|
Reference in New Issue
Block a user