diff --git a/assets/js/src/public.js b/assets/js/src/public.js index ca97653ed9..186025c280 100644 --- a/assets/js/src/public.js +++ b/assets/js/src/public.js @@ -31,7 +31,7 @@ function( }); form.parsley().on('form:submit', function(parsley) { - var data = form.serializeObject() || {}; + var form_data = form.serializeObject() || {}; // check if we're on the same domain if(isSameDomain(MailPoetForm.ajax_url) === false) { // non ajax post request @@ -40,10 +40,11 @@ function( // ajax request MailPoet.Ajax.post({ url: MailPoetForm.ajax_url, - token: data.token, + api_version: form_data.api_version, + token: form_data.token, endpoint: 'subscribers', action: 'subscribe', - data: data + data: form_data.data }).fail(function(response) { form.find('.mailpoet_validate_error').html( response.errors.map(function(error) { diff --git a/lib/Form/Block/Text.php b/lib/Form/Block/Text.php index 2ce0b4ad81..e8e08c76c1 100644 --- a/lib/Form/Block/Text.php +++ b/lib/Form/Block/Text.php @@ -19,7 +19,7 @@ class Text extends Base { $html .= 'subscribe($data); - + $api = new API(); + $api->getRequestData($_REQUEST); + $form_id = (!empty($_REQUEST['data']['form_id'])) ? $_REQUEST['data']['form_id']: false; + $response = $api->processRoute(); if($response->status !== APIResponse::STATUS_OK) { Url::redirectBack(array( - 'mailpoet_error' => isset($data['form_id']) ? $data['form_id'] : true, + 'mailpoet_error' => ($form_id) ? $form_id : true, 'mailpoet_success' => null )); } else { - if(isset($response->meta['redirect_url'])) { - Url::redirectTo($response->meta['redirect_url']); - } else { - Url::redirectBack(array( - 'mailpoet_success' => $form_id, - 'mailpoet_error' => null - )); - } + (isset($response->meta['redirect_url'])) ? + Url::redirectTo($response->meta['redirect_url']) : + Url::redirectBack( + array( + 'mailpoet_success' => $form_id, + 'mailpoet_error' => null + ) + ); } } } \ No newline at end of file diff --git a/views/form/widget.html b/views/form/widget.html index 4a8a8f24c4..bbe0062345 100644 --- a/views/form/widget.html +++ b/views/form/widget.html @@ -13,8 +13,9 @@ class="mailpoet_form mailpoet_form_<%= form_type %>" novalidate > - + +