Custom fields

- added listing of custom fields in form editor
- ability to delete a custom field
- mades changes to the form editor in order to accomodate for the new custom fields system
- fix form editor bugs
- cleanup
This commit is contained in:
Jonathan Labreuille
2015-11-05 18:35:12 +01:00
parent 5473f94e24
commit b12f7f29de
16 changed files with 394 additions and 202 deletions

View File

@@ -9,12 +9,12 @@ abstract class Base {
protected static function getInputValidationRules($block) {
$rules = array();
if($block['field'] === 'email') {
if($block['name'] === 'email') {
$rules[] = 'required';
$rules[] = 'custom[email]';
}
if($block['field'] === 'list') {
if($block['name'] === 'list') {
$rules[] = 'required';
}
@@ -83,7 +83,7 @@ abstract class Base {
// return field name depending on block data
protected static function getFieldName($block = array()) {
return $block['field'];
return $block['id'];
}
protected static function getFieldLabel($block = array()) {

View File

@@ -18,7 +18,7 @@ class Export {
// generate url to load iframe's content
$iframe_url = add_query_arg(array(
'mailpoet_page' => 'mailpoet_form_iframe',
'mailpoet_form' => $form['form']
'mailpoet_form' => $form['id']
), site_url());
// generate iframe
@@ -30,7 +30,7 @@ class Export {
'class="mailpoet_form_iframe" '.
'vspace="0" '.
'tabindex="0" '.
//'style="position: static; top: 0pt; margin: 0px; border-style: none; height: 330px; left: 0pt; visibility: visible;" '. // TODO: need to find a solution for Height.
'onload="javascript:(this.style.height = this.contentWindow.document.body.scrollHeight + \'px\');"'.
'marginwidth="0" '.
'marginheight="0" '.
'hspace="0" '.
@@ -40,7 +40,7 @@ class Export {
case 'php':
$output = array(
'$form_widget = new \MailPoet\Form\Widget();',
'echo $form_widget->widget(array(\'form\' => '.(int)$form['form'].', \'form_type\' => \'php\'));'
'echo $form_widget->widget(array(\'form\' => '.(int)$form['id'].', \'form_type\' => \'php\'));'
);
return join("\n", $output);
break;
@@ -77,14 +77,14 @@ class Export {
$form_widget = new Widget();
$output[] = $form_widget->widget(array(
'form' => (int)$form['form'],
'form' => (int)$form['id'],
'form_type' => 'php'
));
return join("\n", $output);
break;
case 'shortcode':
return '[mailpoet_form id="'.(int)$form['form'].'"]';
return '[mailpoet_form id="'.(int)$form['id'].'"]';
break;
}
}

View File

@@ -6,6 +6,7 @@ use \MailPoet\Models\Segment;
use \MailPoet\Models\Setting;
use \MailPoet\Models\Subscriber;
use \MailPoet\Form\Renderer as FormRenderer;
use \MailPoet\Form\Util;
if(!defined('ABSPATH')) exit;
@@ -119,11 +120,11 @@ class Widget extends \WP_Widget {
*/
function widget($args, $instance = null) {
// turn $args into variables
extract($args);
extract($args);
if($instance === null) {
$instance = $args;
}
if($instance === null) {
$instance = $args;
}
$title = apply_filters(
'widget_title',
@@ -160,27 +161,27 @@ class Widget extends \WP_Widget {
'title' => $title,
'styles' => FormRenderer::renderStyles($form),
'html' => FormRenderer::renderHTML($form),
'before_widget' => $before_widget,
'after_widget' => $after_widget,
'before_title' => $before_title,
'after_title' => $after_title
'before_widget' => (!empty($before_widget) ? $before_widget : ''),
'after_widget' => (!empty($after_widget) ? $after_widget : ''),
'before_title' => (!empty($before_title) ? $before_title : ''),
'after_title' => (!empty($after_title) ? $after_title : '')
);
/*if(isset($_GET['mailpoet_form']) && (int)$_GET['mailpoet_form'] === $form['id']) {
// form messages (success / error)
$output .= '<div class="mailpoet_message">';
// success message
if(isset($_GET['mailpoet_success'])) {
$output .= '<p class="mailpoet_validate_success">'.strip_tags(urldecode($_GET['mailpoet_success']), '<a><strong><em><br><p>').'</p>';
}
// error message
if(isset($_GET['mailpoet_error'])) {
$output .= '<p class="mailpoet_validate_error">'.strip_tags(urldecode($_GET['mailpoet_error']), '<a><strong><em><br><p>').'</p>';
}
$output .= '</div>';
} else {
$output .= '<div class="mailpoet_message"></div>';
}*/
// if(isset($_GET['mailpoet_form']) && (int)$_GET['mailpoet_form'] === $form['id']) {
// // form messages (success / error)
// $output .= '<div class="mailpoet_message">';
// // success message
// if(isset($_GET['mailpoet_success'])) {
// $output .= '<p class="mailpoet_validate_success">'.strip_tags(urldecode($_GET['mailpoet_success']), '<a><strong><em><br><p>').'</p>';
// }
// // error message
// if(isset($_GET['mailpoet_error'])) {
// $output .= '<p class="mailpoet_validate_error">'.strip_tags(urldecode($_GET['mailpoet_error']), '<a><strong><em><br><p>').'</p>';
// }
// $output .= '</div>';
// } else {
// $output .= '<div class="mailpoet_message"></div>';
// }
// render form
$renderer = new Renderer();
@@ -226,7 +227,9 @@ if(isset($_GET['mailpoet_page']) && strlen(trim($_GET['mailpoet_page'])) > 0) {
if($form !== false) {
// render form
print FormRenderer::getExport('html', $form->asArray());
$output = Util\Export::get('html', $form->asArray());
// $output = do_shortcode($output);
print $output;
exit;
}
break;