@@ -14,136 +14,136 @@ |
||
| 14 | 14 | class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * opening div tag for a form |
|
| 19 | - * |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - public function layout_form_begin() |
|
| 23 | - { |
|
| 24 | - return EEH_HTML::div( |
|
| 25 | - '', |
|
| 26 | - $this->_form_section->html_id(), |
|
| 27 | - $this->_form_section->html_class(), |
|
| 28 | - $this->_form_section->html_style() |
|
| 29 | - ); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Lays out the row for the input, including label and errors |
|
| 36 | - * |
|
| 37 | - * @param EE_Form_Input_Base $input |
|
| 38 | - * @return string |
|
| 39 | - * @throws \EE_Error |
|
| 40 | - */ |
|
| 41 | - public function layout_input($input) |
|
| 42 | - { |
|
| 43 | - $html = ''; |
|
| 44 | - // set something unique for the id |
|
| 45 | - $html_id = (string) $input->html_id() !== '' |
|
| 46 | - ? (string) $input->html_id() |
|
| 47 | - : spl_object_hash($input); |
|
| 48 | - // and add a generic input type class |
|
| 49 | - $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
| 50 | - if ($input instanceof EE_Hidden_Input) { |
|
| 51 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 52 | - } elseif ($input instanceof EE_Submit_Input) { |
|
| 53 | - $html .= EEH_HTML::div( |
|
| 54 | - $input->get_html_for_input(), |
|
| 55 | - $html_id . '-submit-dv', |
|
| 56 | - "{$input->html_class()}-submit-dv {$html_class}" |
|
| 57 | - ); |
|
| 58 | - } elseif ($input instanceof EE_Select_Input) { |
|
| 59 | - $html .= EEH_HTML::div( |
|
| 60 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 61 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 62 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 63 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 64 | - $html_id . '-input-dv', |
|
| 65 | - "{$input->html_class()}-input-dv {$html_class}" |
|
| 66 | - ); |
|
| 67 | - } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
| 68 | - $html .= EEH_HTML::div( |
|
| 69 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
| 70 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 71 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 72 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 73 | - $html_id . '-input-dv', |
|
| 74 | - "{$input->html_class()}-input-dv {$html_class}" |
|
| 75 | - ); |
|
| 76 | - } else { |
|
| 77 | - $html .= EEH_HTML::div( |
|
| 78 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 79 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 80 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 81 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 82 | - $html_id . '-input-dv', |
|
| 83 | - "{$input->html_class()}-input-dv {$html_class}" |
|
| 84 | - ); |
|
| 85 | - } |
|
| 86 | - return $html; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * |
|
| 93 | - * _display_label_for_option_type_question |
|
| 94 | - * Gets the HTML for the 'label', which is just text for this (because labels |
|
| 95 | - * should be for each input) |
|
| 96 | - * |
|
| 97 | - * @param EE_Form_Input_With_Options_Base $input |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
| 101 | - { |
|
| 102 | - if ($input->display_html_label_text()) { |
|
| 103 | - $html_label_text = $input->html_label_text(); |
|
| 104 | - $label_html = EEH_HTML::div( |
|
| 105 | - $input->required() |
|
| 106 | - ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
| 107 | - : $html_label_text, |
|
| 108 | - $input->html_label_id(), |
|
| 109 | - $input->required() |
|
| 110 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 111 | - : $input->html_label_class(), |
|
| 112 | - $input->html_label_style(), |
|
| 113 | - $input->html_other_attributes() |
|
| 114 | - ); |
|
| 115 | - // if no content was provided to EEH_HTML::div() above (ie: an empty label), |
|
| 116 | - // then we need to close the div manually |
|
| 117 | - if (empty($html_label_text)) { |
|
| 118 | - $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class()); |
|
| 119 | - } |
|
| 120 | - return $label_html; |
|
| 121 | - } |
|
| 122 | - return ''; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Lays out a row for the subsection |
|
| 129 | - * |
|
| 130 | - * @param EE_Form_Section_Proper $form_section |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function layout_subsection($form_section) |
|
| 134 | - { |
|
| 135 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * closing div tag for a form |
|
| 142 | - * |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function layout_form_end() |
|
| 146 | - { |
|
| 147 | - return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
| 148 | - } |
|
| 17 | + /** |
|
| 18 | + * opening div tag for a form |
|
| 19 | + * |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + public function layout_form_begin() |
|
| 23 | + { |
|
| 24 | + return EEH_HTML::div( |
|
| 25 | + '', |
|
| 26 | + $this->_form_section->html_id(), |
|
| 27 | + $this->_form_section->html_class(), |
|
| 28 | + $this->_form_section->html_style() |
|
| 29 | + ); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Lays out the row for the input, including label and errors |
|
| 36 | + * |
|
| 37 | + * @param EE_Form_Input_Base $input |
|
| 38 | + * @return string |
|
| 39 | + * @throws \EE_Error |
|
| 40 | + */ |
|
| 41 | + public function layout_input($input) |
|
| 42 | + { |
|
| 43 | + $html = ''; |
|
| 44 | + // set something unique for the id |
|
| 45 | + $html_id = (string) $input->html_id() !== '' |
|
| 46 | + ? (string) $input->html_id() |
|
| 47 | + : spl_object_hash($input); |
|
| 48 | + // and add a generic input type class |
|
| 49 | + $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
| 50 | + if ($input instanceof EE_Hidden_Input) { |
|
| 51 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 52 | + } elseif ($input instanceof EE_Submit_Input) { |
|
| 53 | + $html .= EEH_HTML::div( |
|
| 54 | + $input->get_html_for_input(), |
|
| 55 | + $html_id . '-submit-dv', |
|
| 56 | + "{$input->html_class()}-submit-dv {$html_class}" |
|
| 57 | + ); |
|
| 58 | + } elseif ($input instanceof EE_Select_Input) { |
|
| 59 | + $html .= EEH_HTML::div( |
|
| 60 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 61 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 62 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 63 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 64 | + $html_id . '-input-dv', |
|
| 65 | + "{$input->html_class()}-input-dv {$html_class}" |
|
| 66 | + ); |
|
| 67 | + } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
| 68 | + $html .= EEH_HTML::div( |
|
| 69 | + EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
| 70 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 71 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 72 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 73 | + $html_id . '-input-dv', |
|
| 74 | + "{$input->html_class()}-input-dv {$html_class}" |
|
| 75 | + ); |
|
| 76 | + } else { |
|
| 77 | + $html .= EEH_HTML::div( |
|
| 78 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 79 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 80 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 81 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 82 | + $html_id . '-input-dv', |
|
| 83 | + "{$input->html_class()}-input-dv {$html_class}" |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | + return $html; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * |
|
| 93 | + * _display_label_for_option_type_question |
|
| 94 | + * Gets the HTML for the 'label', which is just text for this (because labels |
|
| 95 | + * should be for each input) |
|
| 96 | + * |
|
| 97 | + * @param EE_Form_Input_With_Options_Base $input |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
| 101 | + { |
|
| 102 | + if ($input->display_html_label_text()) { |
|
| 103 | + $html_label_text = $input->html_label_text(); |
|
| 104 | + $label_html = EEH_HTML::div( |
|
| 105 | + $input->required() |
|
| 106 | + ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
| 107 | + : $html_label_text, |
|
| 108 | + $input->html_label_id(), |
|
| 109 | + $input->required() |
|
| 110 | + ? 'ee-required-label ' . $input->html_label_class() |
|
| 111 | + : $input->html_label_class(), |
|
| 112 | + $input->html_label_style(), |
|
| 113 | + $input->html_other_attributes() |
|
| 114 | + ); |
|
| 115 | + // if no content was provided to EEH_HTML::div() above (ie: an empty label), |
|
| 116 | + // then we need to close the div manually |
|
| 117 | + if (empty($html_label_text)) { |
|
| 118 | + $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class()); |
|
| 119 | + } |
|
| 120 | + return $label_html; |
|
| 121 | + } |
|
| 122 | + return ''; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Lays out a row for the subsection |
|
| 129 | + * |
|
| 130 | + * @param EE_Form_Section_Proper $form_section |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function layout_subsection($form_section) |
|
| 134 | + { |
|
| 135 | + return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * closing div tag for a form |
|
| 142 | + * |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function layout_form_end() |
|
| 146 | + { |
|
| 147 | + return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
| 148 | + } |
|
| 149 | 149 | } |
@@ -46,40 +46,40 @@ discard block |
||
| 46 | 46 | ? (string) $input->html_id() |
| 47 | 47 | : spl_object_hash($input); |
| 48 | 48 | // and add a generic input type class |
| 49 | - $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
| 49 | + $html_class = sanitize_key(str_replace('_', '-', get_class($input))).'-dv'; |
|
| 50 | 50 | if ($input instanceof EE_Hidden_Input) { |
| 51 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 51 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
| 52 | 52 | } elseif ($input instanceof EE_Submit_Input) { |
| 53 | 53 | $html .= EEH_HTML::div( |
| 54 | 54 | $input->get_html_for_input(), |
| 55 | - $html_id . '-submit-dv', |
|
| 55 | + $html_id.'-submit-dv', |
|
| 56 | 56 | "{$input->html_class()}-submit-dv {$html_class}" |
| 57 | 57 | ); |
| 58 | 58 | } elseif ($input instanceof EE_Select_Input) { |
| 59 | 59 | $html .= EEH_HTML::div( |
| 60 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 61 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 62 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 63 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 64 | - $html_id . '-input-dv', |
|
| 60 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
| 61 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
| 62 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
| 63 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
| 64 | + $html_id.'-input-dv', |
|
| 65 | 65 | "{$input->html_class()}-input-dv {$html_class}" |
| 66 | 66 | ); |
| 67 | 67 | } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
| 68 | 68 | $html .= EEH_HTML::div( |
| 69 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
| 70 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 71 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 72 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 73 | - $html_id . '-input-dv', |
|
| 69 | + EEH_HTML::nl().$this->_display_label_for_option_type_question($input). |
|
| 70 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
| 71 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
| 72 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
| 73 | + $html_id.'-input-dv', |
|
| 74 | 74 | "{$input->html_class()}-input-dv {$html_class}" |
| 75 | 75 | ); |
| 76 | 76 | } else { |
| 77 | 77 | $html .= EEH_HTML::div( |
| 78 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
| 79 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
| 80 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
| 81 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
| 82 | - $html_id . '-input-dv', |
|
| 78 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
| 79 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
| 80 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
| 81 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
| 82 | + $html_id.'-input-dv', |
|
| 83 | 83 | "{$input->html_class()}-input-dv {$html_class}" |
| 84 | 84 | ); |
| 85 | 85 | } |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | $html_label_text = $input->html_label_text(); |
| 104 | 104 | $label_html = EEH_HTML::div( |
| 105 | 105 | $input->required() |
| 106 | - ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
| 106 | + ? $html_label_text.EEH_HTML::span('*', '', 'ee-asterisk') |
|
| 107 | 107 | : $html_label_text, |
| 108 | 108 | $input->html_label_id(), |
| 109 | 109 | $input->required() |
| 110 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 110 | + ? 'ee-required-label '.$input->html_label_class() |
|
| 111 | 111 | : $input->html_label_class(), |
| 112 | 112 | $input->html_label_style(), |
| 113 | 113 | $input->html_other_attributes() |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | public function layout_subsection($form_section) |
| 134 | 134 | { |
| 135 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
| 135 | + return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -12,107 +12,107 @@ |
||
| 12 | 12 | class EE_Fieldset_Section_Layout extends EE_Div_Per_Section_Layout |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * legend_class |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected $_legend_class; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * legend_text |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $_legend_text; |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * construct |
|
| 33 | - * |
|
| 34 | - * @param array $options |
|
| 35 | - */ |
|
| 36 | - public function __construct($options = array()) |
|
| 37 | - { |
|
| 38 | - foreach ($options as $key => $value) { |
|
| 39 | - $key = '_' . $key; |
|
| 40 | - if (property_exists($this, $key)) { |
|
| 41 | - $this->{$key} = $value; |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * opening div tag for a form |
|
| 50 | - * |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function layout_form_begin() |
|
| 54 | - { |
|
| 55 | - $html = EEH_HTML::nl(1) |
|
| 56 | - . '<fieldset id="' |
|
| 57 | - . $this->_form_section->html_id() |
|
| 58 | - . '" class="' |
|
| 59 | - . $this->_form_section->html_class() |
|
| 60 | - . '" style="' |
|
| 61 | - . $this->_form_section->html_style() |
|
| 62 | - . '">'; |
|
| 63 | - $html .= '<legend class="' . $this->legend_class() . '">' . $this->legend_text() . '</legend>'; |
|
| 64 | - return $html; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * closing div tag for a form |
|
| 71 | - * |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function layout_form_end() |
|
| 75 | - { |
|
| 76 | - return EEH_HTML::nl(-1) . '</fieldset>'; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param string $legend_class |
|
| 83 | - */ |
|
| 84 | - public function set_legend_class($legend_class) |
|
| 85 | - { |
|
| 86 | - $this->_legend_class = $legend_class; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function legend_class() |
|
| 95 | - { |
|
| 96 | - return $this->_legend_class; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param string $legend_text |
|
| 103 | - */ |
|
| 104 | - public function set_legend_text($legend_text) |
|
| 105 | - { |
|
| 106 | - $this->_legend_text = $legend_text; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - public function legend_text() |
|
| 115 | - { |
|
| 116 | - return $this->_legend_text; |
|
| 117 | - } |
|
| 15 | + /** |
|
| 16 | + * legend_class |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected $_legend_class; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * legend_text |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $_legend_text; |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * construct |
|
| 33 | + * |
|
| 34 | + * @param array $options |
|
| 35 | + */ |
|
| 36 | + public function __construct($options = array()) |
|
| 37 | + { |
|
| 38 | + foreach ($options as $key => $value) { |
|
| 39 | + $key = '_' . $key; |
|
| 40 | + if (property_exists($this, $key)) { |
|
| 41 | + $this->{$key} = $value; |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * opening div tag for a form |
|
| 50 | + * |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function layout_form_begin() |
|
| 54 | + { |
|
| 55 | + $html = EEH_HTML::nl(1) |
|
| 56 | + . '<fieldset id="' |
|
| 57 | + . $this->_form_section->html_id() |
|
| 58 | + . '" class="' |
|
| 59 | + . $this->_form_section->html_class() |
|
| 60 | + . '" style="' |
|
| 61 | + . $this->_form_section->html_style() |
|
| 62 | + . '">'; |
|
| 63 | + $html .= '<legend class="' . $this->legend_class() . '">' . $this->legend_text() . '</legend>'; |
|
| 64 | + return $html; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * closing div tag for a form |
|
| 71 | + * |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function layout_form_end() |
|
| 75 | + { |
|
| 76 | + return EEH_HTML::nl(-1) . '</fieldset>'; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param string $legend_class |
|
| 83 | + */ |
|
| 84 | + public function set_legend_class($legend_class) |
|
| 85 | + { |
|
| 86 | + $this->_legend_class = $legend_class; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function legend_class() |
|
| 95 | + { |
|
| 96 | + return $this->_legend_class; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param string $legend_text |
|
| 103 | + */ |
|
| 104 | + public function set_legend_text($legend_text) |
|
| 105 | + { |
|
| 106 | + $this->_legend_text = $legend_text; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + public function legend_text() |
|
| 115 | + { |
|
| 116 | + return $this->_legend_text; |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | public function __construct($options = array()) |
| 37 | 37 | { |
| 38 | 38 | foreach ($options as $key => $value) { |
| 39 | - $key = '_' . $key; |
|
| 39 | + $key = '_'.$key; |
|
| 40 | 40 | if (property_exists($this, $key)) { |
| 41 | 41 | $this->{$key} = $value; |
| 42 | 42 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | . '" style="' |
| 61 | 61 | . $this->_form_section->html_style() |
| 62 | 62 | . '">'; |
| 63 | - $html .= '<legend class="' . $this->legend_class() . '">' . $this->legend_text() . '</legend>'; |
|
| 63 | + $html .= '<legend class="'.$this->legend_class().'">'.$this->legend_text().'</legend>'; |
|
| 64 | 64 | return $html; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function layout_form_end() |
| 75 | 75 | { |
| 76 | - return EEH_HTML::nl(-1) . '</fieldset>'; |
|
| 76 | + return EEH_HTML::nl(-1).'</fieldset>'; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -7,80 +7,80 @@ |
||
| 7 | 7 | class EE_Admin_Two_Column_Layout extends EE_Two_Column_Layout |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * Overriding the parent table layout to include <tbody> tags |
|
| 12 | - * |
|
| 13 | - * @param array $additional_args |
|
| 14 | - * @return string |
|
| 15 | - */ |
|
| 16 | - public function layout_form_begin($additional_args = array()) |
|
| 17 | - { |
|
| 18 | - $this->_form_section->set_html_class($this->_form_section->html_class() . ' form-table'); |
|
| 19 | - return parent::layout_form_begin($additional_args); |
|
| 20 | - } |
|
| 10 | + /** |
|
| 11 | + * Overriding the parent table layout to include <tbody> tags |
|
| 12 | + * |
|
| 13 | + * @param array $additional_args |
|
| 14 | + * @return string |
|
| 15 | + */ |
|
| 16 | + public function layout_form_begin($additional_args = array()) |
|
| 17 | + { |
|
| 18 | + $this->_form_section->set_html_class($this->_form_section->html_class() . ' form-table'); |
|
| 19 | + return parent::layout_form_begin($additional_args); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Lays out a row for the subsection |
|
| 26 | - * |
|
| 27 | - * @param EE_Form_Section_Proper $form_section |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function layout_subsection($form_section) |
|
| 31 | - { |
|
| 32 | - if ($form_section instanceof EE_Form_Section_Proper |
|
| 33 | - || $form_section instanceof EE_Form_Section_HTML |
|
| 34 | - ) { |
|
| 35 | - return EEH_HTML::no_row($form_section->get_html()); |
|
| 36 | - } |
|
| 37 | - return ''; |
|
| 38 | - } |
|
| 24 | + /** |
|
| 25 | + * Lays out a row for the subsection |
|
| 26 | + * |
|
| 27 | + * @param EE_Form_Section_Proper $form_section |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function layout_subsection($form_section) |
|
| 31 | + { |
|
| 32 | + if ($form_section instanceof EE_Form_Section_Proper |
|
| 33 | + || $form_section instanceof EE_Form_Section_HTML |
|
| 34 | + ) { |
|
| 35 | + return EEH_HTML::no_row($form_section->get_html()); |
|
| 36 | + } |
|
| 37 | + return ''; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Lays out the row for the input, including label and errors |
|
| 44 | - * |
|
| 45 | - * @param EE_Form_Input_Base $input |
|
| 46 | - * @return string |
|
| 47 | - * @throws EE_Error |
|
| 48 | - */ |
|
| 49 | - public function layout_input($input) |
|
| 50 | - { |
|
| 51 | - if ($input->get_display_strategy() instanceof EE_Text_Area_Display_Strategy |
|
| 52 | - || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
|
| 53 | - || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
|
| 54 | - ) { |
|
| 55 | - $input->set_html_class($input->html_class() . ' large-text'); |
|
| 56 | - } |
|
| 57 | - if ($input instanceof EE_Text_Area_Input) { |
|
| 58 | - $input->set_rows(4); |
|
| 59 | - $input->set_cols(60); |
|
| 60 | - } |
|
| 61 | - $input_html = $input->get_html_for_input(); |
|
| 62 | - // maybe add errors and help text ? |
|
| 63 | - $input_html .= $input->get_html_for_errors() !== '' |
|
| 64 | - ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
| 65 | - : ''; |
|
| 66 | - $input_html .= $input->get_html_for_help() !== '' |
|
| 67 | - ? EEH_HTML::nl() . $input->get_html_for_help() |
|
| 68 | - : ''; |
|
| 69 | - // overriding parent to add wp admin specific things. |
|
| 70 | - $html = ''; |
|
| 71 | - if ($input instanceof EE_Hidden_Input) { |
|
| 72 | - $html .= EEH_HTML::no_row($input->get_html_for_input()); |
|
| 73 | - } else { |
|
| 74 | - $html .= EEH_HTML::tr( |
|
| 75 | - EEH_HTML::th( |
|
| 76 | - $input->get_html_for_label(), |
|
| 77 | - '', |
|
| 78 | - '', |
|
| 79 | - '', |
|
| 80 | - 'scope="row"' |
|
| 81 | - ) . EEH_HTML::td($input_html) |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - return $html; |
|
| 85 | - } |
|
| 42 | + /** |
|
| 43 | + * Lays out the row for the input, including label and errors |
|
| 44 | + * |
|
| 45 | + * @param EE_Form_Input_Base $input |
|
| 46 | + * @return string |
|
| 47 | + * @throws EE_Error |
|
| 48 | + */ |
|
| 49 | + public function layout_input($input) |
|
| 50 | + { |
|
| 51 | + if ($input->get_display_strategy() instanceof EE_Text_Area_Display_Strategy |
|
| 52 | + || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
|
| 53 | + || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
|
| 54 | + ) { |
|
| 55 | + $input->set_html_class($input->html_class() . ' large-text'); |
|
| 56 | + } |
|
| 57 | + if ($input instanceof EE_Text_Area_Input) { |
|
| 58 | + $input->set_rows(4); |
|
| 59 | + $input->set_cols(60); |
|
| 60 | + } |
|
| 61 | + $input_html = $input->get_html_for_input(); |
|
| 62 | + // maybe add errors and help text ? |
|
| 63 | + $input_html .= $input->get_html_for_errors() !== '' |
|
| 64 | + ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
| 65 | + : ''; |
|
| 66 | + $input_html .= $input->get_html_for_help() !== '' |
|
| 67 | + ? EEH_HTML::nl() . $input->get_html_for_help() |
|
| 68 | + : ''; |
|
| 69 | + // overriding parent to add wp admin specific things. |
|
| 70 | + $html = ''; |
|
| 71 | + if ($input instanceof EE_Hidden_Input) { |
|
| 72 | + $html .= EEH_HTML::no_row($input->get_html_for_input()); |
|
| 73 | + } else { |
|
| 74 | + $html .= EEH_HTML::tr( |
|
| 75 | + EEH_HTML::th( |
|
| 76 | + $input->get_html_for_label(), |
|
| 77 | + '', |
|
| 78 | + '', |
|
| 79 | + '', |
|
| 80 | + 'scope="row"' |
|
| 81 | + ) . EEH_HTML::td($input_html) |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + return $html; |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public function layout_form_begin($additional_args = array()) |
| 17 | 17 | { |
| 18 | - $this->_form_section->set_html_class($this->_form_section->html_class() . ' form-table'); |
|
| 18 | + $this->_form_section->set_html_class($this->_form_section->html_class().' form-table'); |
|
| 19 | 19 | return parent::layout_form_begin($additional_args); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
| 53 | 53 | || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
| 54 | 54 | ) { |
| 55 | - $input->set_html_class($input->html_class() . ' large-text'); |
|
| 55 | + $input->set_html_class($input->html_class().' large-text'); |
|
| 56 | 56 | } |
| 57 | 57 | if ($input instanceof EE_Text_Area_Input) { |
| 58 | 58 | $input->set_rows(4); |
@@ -61,10 +61,10 @@ discard block |
||
| 61 | 61 | $input_html = $input->get_html_for_input(); |
| 62 | 62 | // maybe add errors and help text ? |
| 63 | 63 | $input_html .= $input->get_html_for_errors() !== '' |
| 64 | - ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
| 64 | + ? EEH_HTML::nl().$input->get_html_for_errors() |
|
| 65 | 65 | : ''; |
| 66 | 66 | $input_html .= $input->get_html_for_help() !== '' |
| 67 | - ? EEH_HTML::nl() . $input->get_html_for_help() |
|
| 67 | + ? EEH_HTML::nl().$input->get_html_for_help() |
|
| 68 | 68 | : ''; |
| 69 | 69 | // overriding parent to add wp admin specific things. |
| 70 | 70 | $html = ''; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | '', |
| 79 | 79 | '', |
| 80 | 80 | 'scope="row"' |
| 81 | - ) . EEH_HTML::td($input_html) |
|
| 81 | + ).EEH_HTML::td($input_html) |
|
| 82 | 82 | ); |
| 83 | 83 | } |
| 84 | 84 | return $html; |
@@ -3,88 +3,88 @@ |
||
| 3 | 3 | class EE_Admin_One_Column_Layout extends EE_Form_Section_Layout_Base |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - /** |
|
| 7 | - * Starts the form section |
|
| 8 | - * |
|
| 9 | - * @param array $additional_args |
|
| 10 | - * @return string |
|
| 11 | - */ |
|
| 12 | - public function layout_form_begin($additional_args = array()) |
|
| 13 | - { |
|
| 14 | - return EEH_HTML::table( |
|
| 15 | - '', |
|
| 16 | - $this->_form_section->html_id(), |
|
| 17 | - $this->_form_section->html_class() . ' form-table', |
|
| 18 | - $this->_form_section->html_style() |
|
| 19 | - ) . EEH_HTML::tbody(); |
|
| 20 | - } |
|
| 6 | + /** |
|
| 7 | + * Starts the form section |
|
| 8 | + * |
|
| 9 | + * @param array $additional_args |
|
| 10 | + * @return string |
|
| 11 | + */ |
|
| 12 | + public function layout_form_begin($additional_args = array()) |
|
| 13 | + { |
|
| 14 | + return EEH_HTML::table( |
|
| 15 | + '', |
|
| 16 | + $this->_form_section->html_id(), |
|
| 17 | + $this->_form_section->html_class() . ' form-table', |
|
| 18 | + $this->_form_section->html_style() |
|
| 19 | + ) . EEH_HTML::tbody(); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Ends the form section |
|
| 25 | - * |
|
| 26 | - * @param array $additional_args |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function layout_form_end($additional_args = array()) |
|
| 30 | - { |
|
| 31 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex($this->_form_section->html_id()); |
|
| 32 | - } |
|
| 23 | + /** |
|
| 24 | + * Ends the form section |
|
| 25 | + * |
|
| 26 | + * @param array $additional_args |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function layout_form_end($additional_args = array()) |
|
| 30 | + { |
|
| 31 | + return EEH_HTML::tbodyx() . EEH_HTML::tablex($this->_form_section->html_id()); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Lays out the row for the input, including label and errors |
|
| 37 | - * |
|
| 38 | - * @param EE_Form_Input_Base $input |
|
| 39 | - * @return string |
|
| 40 | - * @throws EE_Error |
|
| 41 | - */ |
|
| 42 | - public function layout_input($input) |
|
| 43 | - { |
|
| 44 | - if ($input->get_display_strategy() instanceof EE_Text_Area_Display_Strategy |
|
| 45 | - || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
|
| 46 | - || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
|
| 47 | - ) { |
|
| 48 | - $input->set_html_class($input->html_class() . ' large-text'); |
|
| 49 | - } |
|
| 50 | - $input_html = $input->get_html_for_input(); |
|
| 51 | - // maybe add errors and help text ? |
|
| 52 | - $input_html .= $input->get_html_for_errors() !== '' |
|
| 53 | - ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
| 54 | - : ''; |
|
| 55 | - $input_html .= $input->get_html_for_help() !== '' |
|
| 56 | - ? EEH_HTML::nl() . $input->get_html_for_help() |
|
| 57 | - : ''; |
|
| 58 | - // overriding parent to add wp admin specific things. |
|
| 59 | - $html = ''; |
|
| 60 | - if ($input instanceof EE_Hidden_Input) { |
|
| 61 | - $html .= EEH_HTML::no_row($input->get_html_for_input()); |
|
| 62 | - } else { |
|
| 63 | - $html .= EEH_HTML::tr( |
|
| 64 | - EEH_HTML::td( |
|
| 65 | - $input->get_html_for_label() |
|
| 66 | - . EEH_HTML::nl() |
|
| 67 | - . $input_html |
|
| 68 | - ) |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - return $html; |
|
| 72 | - } |
|
| 35 | + /** |
|
| 36 | + * Lays out the row for the input, including label and errors |
|
| 37 | + * |
|
| 38 | + * @param EE_Form_Input_Base $input |
|
| 39 | + * @return string |
|
| 40 | + * @throws EE_Error |
|
| 41 | + */ |
|
| 42 | + public function layout_input($input) |
|
| 43 | + { |
|
| 44 | + if ($input->get_display_strategy() instanceof EE_Text_Area_Display_Strategy |
|
| 45 | + || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
|
| 46 | + || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
|
| 47 | + ) { |
|
| 48 | + $input->set_html_class($input->html_class() . ' large-text'); |
|
| 49 | + } |
|
| 50 | + $input_html = $input->get_html_for_input(); |
|
| 51 | + // maybe add errors and help text ? |
|
| 52 | + $input_html .= $input->get_html_for_errors() !== '' |
|
| 53 | + ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
| 54 | + : ''; |
|
| 55 | + $input_html .= $input->get_html_for_help() !== '' |
|
| 56 | + ? EEH_HTML::nl() . $input->get_html_for_help() |
|
| 57 | + : ''; |
|
| 58 | + // overriding parent to add wp admin specific things. |
|
| 59 | + $html = ''; |
|
| 60 | + if ($input instanceof EE_Hidden_Input) { |
|
| 61 | + $html .= EEH_HTML::no_row($input->get_html_for_input()); |
|
| 62 | + } else { |
|
| 63 | + $html .= EEH_HTML::tr( |
|
| 64 | + EEH_HTML::td( |
|
| 65 | + $input->get_html_for_label() |
|
| 66 | + . EEH_HTML::nl() |
|
| 67 | + . $input_html |
|
| 68 | + ) |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + return $html; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Lays out a row for the subsection |
|
| 77 | - * |
|
| 78 | - * @param EE_Form_Section_Proper $form_section |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - public function layout_subsection($form_section) |
|
| 82 | - { |
|
| 83 | - if ($form_section instanceof EE_Form_Section_Proper |
|
| 84 | - || $form_section instanceof EE_Form_Section_HTML |
|
| 85 | - ) { |
|
| 86 | - return EEH_HTML::no_row($form_section->get_html()); |
|
| 87 | - } |
|
| 88 | - return ''; |
|
| 89 | - } |
|
| 75 | + /** |
|
| 76 | + * Lays out a row for the subsection |
|
| 77 | + * |
|
| 78 | + * @param EE_Form_Section_Proper $form_section |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + public function layout_subsection($form_section) |
|
| 82 | + { |
|
| 83 | + if ($form_section instanceof EE_Form_Section_Proper |
|
| 84 | + || $form_section instanceof EE_Form_Section_HTML |
|
| 85 | + ) { |
|
| 86 | + return EEH_HTML::no_row($form_section->get_html()); |
|
| 87 | + } |
|
| 88 | + return ''; |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | return EEH_HTML::table( |
| 15 | 15 | '', |
| 16 | 16 | $this->_form_section->html_id(), |
| 17 | - $this->_form_section->html_class() . ' form-table', |
|
| 17 | + $this->_form_section->html_class().' form-table', |
|
| 18 | 18 | $this->_form_section->html_style() |
| 19 | - ) . EEH_HTML::tbody(); |
|
| 19 | + ).EEH_HTML::tbody(); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function layout_form_end($additional_args = array()) |
| 30 | 30 | { |
| 31 | - return EEH_HTML::tbodyx() . EEH_HTML::tablex($this->_form_section->html_id()); |
|
| 31 | + return EEH_HTML::tbodyx().EEH_HTML::tablex($this->_form_section->html_id()); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -45,15 +45,15 @@ discard block |
||
| 45 | 45 | || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
| 46 | 46 | || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
| 47 | 47 | ) { |
| 48 | - $input->set_html_class($input->html_class() . ' large-text'); |
|
| 48 | + $input->set_html_class($input->html_class().' large-text'); |
|
| 49 | 49 | } |
| 50 | 50 | $input_html = $input->get_html_for_input(); |
| 51 | 51 | // maybe add errors and help text ? |
| 52 | 52 | $input_html .= $input->get_html_for_errors() !== '' |
| 53 | - ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
| 53 | + ? EEH_HTML::nl().$input->get_html_for_errors() |
|
| 54 | 54 | : ''; |
| 55 | 55 | $input_html .= $input->get_html_for_help() !== '' |
| 56 | - ? EEH_HTML::nl() . $input->get_html_for_help() |
|
| 56 | + ? EEH_HTML::nl().$input->get_html_for_help() |
|
| 57 | 57 | : ''; |
| 58 | 58 | // overriding parent to add wp admin specific things. |
| 59 | 59 | $html = ''; |
@@ -12,117 +12,117 @@ |
||
| 12 | 12 | { |
| 13 | 13 | |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * This is a flag indicating whether to use '<br>' tags after each input in the layout |
|
| 17 | - * strategy. |
|
| 18 | - * |
|
| 19 | - * @var bool |
|
| 20 | - */ |
|
| 21 | - protected $_use_break_tags = true; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * EE_No_Layout constructor. |
|
| 27 | - * |
|
| 28 | - * @param array $options Currently if this has a 'use_break_tags' key that is used to set the _use_break_tags |
|
| 29 | - * property on the class. |
|
| 30 | - */ |
|
| 31 | - public function __construct($options = array()) |
|
| 32 | - { |
|
| 33 | - $this->_use_break_tags = is_array($options) && isset($options['use_break_tags']) |
|
| 34 | - ? filter_var($options['use_break_tags'], FILTER_VALIDATE_BOOLEAN) |
|
| 35 | - : $this->_use_break_tags; |
|
| 36 | - parent::__construct(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Add line break at beginning of form |
|
| 43 | - * |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - public function layout_form_begin() |
|
| 47 | - { |
|
| 48 | - return EEH_HTML::nl(1); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Lays out the row for the input, including label and errors |
|
| 55 | - * |
|
| 56 | - * @param EE_Form_Input_Base $input |
|
| 57 | - * @return string |
|
| 58 | - * @throws \EE_Error |
|
| 59 | - */ |
|
| 60 | - public function layout_input($input) |
|
| 61 | - { |
|
| 62 | - $html = ''; |
|
| 63 | - if ($input instanceof EE_Hidden_Input) { |
|
| 64 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 65 | - } elseif ($input instanceof EE_Submit_Input) { |
|
| 66 | - $html .= $this->br(); |
|
| 67 | - $html .= $input->get_html_for_input(); |
|
| 68 | - } elseif ($input instanceof EE_Select_Input) { |
|
| 69 | - $html .= $this->br(); |
|
| 70 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
| 71 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
| 72 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 73 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
| 74 | - $html .= $this->br(); |
|
| 75 | - } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
| 76 | - $html .= $this->br(); |
|
| 77 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
| 78 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 79 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
| 80 | - } else { |
|
| 81 | - $html .= $this->br(); |
|
| 82 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
| 83 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
| 84 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 85 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
| 86 | - } |
|
| 87 | - $html .= EEH_HTML::nl(-1); |
|
| 88 | - return $html; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Lays out a row for the subsection |
|
| 95 | - * |
|
| 96 | - * @param EE_Form_Section_Proper $form_section |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - public function layout_subsection($form_section) |
|
| 100 | - { |
|
| 101 | - // d( $form_section ); |
|
| 102 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Add line break at end of form. |
|
| 109 | - * |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function layout_form_end() |
|
| 113 | - { |
|
| 114 | - return EEH_HTML::nl(-1); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * This returns a break tag or an empty string depending on the value of the `_use_break_tags` property. |
|
| 121 | - * |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - protected function br() |
|
| 125 | - { |
|
| 126 | - return $this->_use_break_tags ? EEH_HTML::br() : ''; |
|
| 127 | - } |
|
| 15 | + /** |
|
| 16 | + * This is a flag indicating whether to use '<br>' tags after each input in the layout |
|
| 17 | + * strategy. |
|
| 18 | + * |
|
| 19 | + * @var bool |
|
| 20 | + */ |
|
| 21 | + protected $_use_break_tags = true; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * EE_No_Layout constructor. |
|
| 27 | + * |
|
| 28 | + * @param array $options Currently if this has a 'use_break_tags' key that is used to set the _use_break_tags |
|
| 29 | + * property on the class. |
|
| 30 | + */ |
|
| 31 | + public function __construct($options = array()) |
|
| 32 | + { |
|
| 33 | + $this->_use_break_tags = is_array($options) && isset($options['use_break_tags']) |
|
| 34 | + ? filter_var($options['use_break_tags'], FILTER_VALIDATE_BOOLEAN) |
|
| 35 | + : $this->_use_break_tags; |
|
| 36 | + parent::__construct(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Add line break at beginning of form |
|
| 43 | + * |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + public function layout_form_begin() |
|
| 47 | + { |
|
| 48 | + return EEH_HTML::nl(1); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Lays out the row for the input, including label and errors |
|
| 55 | + * |
|
| 56 | + * @param EE_Form_Input_Base $input |
|
| 57 | + * @return string |
|
| 58 | + * @throws \EE_Error |
|
| 59 | + */ |
|
| 60 | + public function layout_input($input) |
|
| 61 | + { |
|
| 62 | + $html = ''; |
|
| 63 | + if ($input instanceof EE_Hidden_Input) { |
|
| 64 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 65 | + } elseif ($input instanceof EE_Submit_Input) { |
|
| 66 | + $html .= $this->br(); |
|
| 67 | + $html .= $input->get_html_for_input(); |
|
| 68 | + } elseif ($input instanceof EE_Select_Input) { |
|
| 69 | + $html .= $this->br(); |
|
| 70 | + $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
| 71 | + $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
| 72 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 73 | + $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
| 74 | + $html .= $this->br(); |
|
| 75 | + } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
| 76 | + $html .= $this->br(); |
|
| 77 | + $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
| 78 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 79 | + $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
| 80 | + } else { |
|
| 81 | + $html .= $this->br(); |
|
| 82 | + $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
| 83 | + $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
| 84 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 85 | + $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
| 86 | + } |
|
| 87 | + $html .= EEH_HTML::nl(-1); |
|
| 88 | + return $html; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Lays out a row for the subsection |
|
| 95 | + * |
|
| 96 | + * @param EE_Form_Section_Proper $form_section |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + public function layout_subsection($form_section) |
|
| 100 | + { |
|
| 101 | + // d( $form_section ); |
|
| 102 | + return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Add line break at end of form. |
|
| 109 | + * |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function layout_form_end() |
|
| 113 | + { |
|
| 114 | + return EEH_HTML::nl(-1); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * This returns a break tag or an empty string depending on the value of the `_use_break_tags` property. |
|
| 121 | + * |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + protected function br() |
|
| 125 | + { |
|
| 126 | + return $this->_use_break_tags ? EEH_HTML::br() : ''; |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -61,28 +61,28 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $html = ''; |
| 63 | 63 | if ($input instanceof EE_Hidden_Input) { |
| 64 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 64 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
| 65 | 65 | } elseif ($input instanceof EE_Submit_Input) { |
| 66 | 66 | $html .= $this->br(); |
| 67 | 67 | $html .= $input->get_html_for_input(); |
| 68 | 68 | } elseif ($input instanceof EE_Select_Input) { |
| 69 | 69 | $html .= $this->br(); |
| 70 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
| 71 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
| 72 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 73 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
| 70 | + $html .= EEH_HTML::nl(1).$input->get_html_for_label(); |
|
| 71 | + $html .= EEH_HTML::nl().$input->get_html_for_errors(); |
|
| 72 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
| 73 | + $html .= EEH_HTML::nl().$input->get_html_for_help(); |
|
| 74 | 74 | $html .= $this->br(); |
| 75 | 75 | } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
| 76 | 76 | $html .= $this->br(); |
| 77 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
| 78 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 79 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
| 77 | + $html .= EEH_HTML::nl().$input->get_html_for_errors(); |
|
| 78 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
| 79 | + $html .= EEH_HTML::nl().$input->get_html_for_help(); |
|
| 80 | 80 | } else { |
| 81 | 81 | $html .= $this->br(); |
| 82 | - $html .= EEH_HTML::nl(1) . $input->get_html_for_label(); |
|
| 83 | - $html .= EEH_HTML::nl() . $input->get_html_for_errors(); |
|
| 84 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
| 85 | - $html .= EEH_HTML::nl() . $input->get_html_for_help(); |
|
| 82 | + $html .= EEH_HTML::nl(1).$input->get_html_for_label(); |
|
| 83 | + $html .= EEH_HTML::nl().$input->get_html_for_errors(); |
|
| 84 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
| 85 | + $html .= EEH_HTML::nl().$input->get_html_for_help(); |
|
| 86 | 86 | } |
| 87 | 87 | $html .= EEH_HTML::nl(-1); |
| 88 | 88 | return $html; |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | public function layout_subsection($form_section) |
| 100 | 100 | { |
| 101 | 101 | // d( $form_section ); |
| 102 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
| 102 | + return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -9,41 +9,41 @@ |
||
| 9 | 9 | class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @param null $validation_error_message |
|
| 14 | - */ |
|
| 15 | - public function __construct($validation_error_message = null) |
|
| 16 | - { |
|
| 17 | - if (! $validation_error_message) { |
|
| 18 | - $validation_error_message = __("Only digits are allowed.", "event_espresso"); |
|
| 19 | - } |
|
| 20 | - parent::__construct($validation_error_message); |
|
| 21 | - } |
|
| 12 | + /** |
|
| 13 | + * @param null $validation_error_message |
|
| 14 | + */ |
|
| 15 | + public function __construct($validation_error_message = null) |
|
| 16 | + { |
|
| 17 | + if (! $validation_error_message) { |
|
| 18 | + $validation_error_message = __("Only digits are allowed.", "event_espresso"); |
|
| 19 | + } |
|
| 20 | + parent::__construct($validation_error_message); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param $normalized_value |
|
| 27 | - */ |
|
| 28 | - public function validate($normalized_value) |
|
| 29 | - { |
|
| 30 | - // this should have already been detected by the normalization strategy |
|
| 31 | - } |
|
| 25 | + /** |
|
| 26 | + * @param $normalized_value |
|
| 27 | + */ |
|
| 28 | + public function validate($normalized_value) |
|
| 29 | + { |
|
| 30 | + // this should have already been detected by the normalization strategy |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @return array |
|
| 37 | - */ |
|
| 38 | - public function get_jquery_validation_rule_array() |
|
| 39 | - { |
|
| 40 | - return array( |
|
| 41 | - 'number'=>true, |
|
| 42 | - 'step' => 1, |
|
| 43 | - 'messages' => array( |
|
| 44 | - 'number' => $this->get_validation_error_message(), |
|
| 45 | - 'step' => $this->get_validation_error_message() |
|
| 46 | - ) |
|
| 47 | - ); |
|
| 48 | - } |
|
| 35 | + /** |
|
| 36 | + * @return array |
|
| 37 | + */ |
|
| 38 | + public function get_jquery_validation_rule_array() |
|
| 39 | + { |
|
| 40 | + return array( |
|
| 41 | + 'number'=>true, |
|
| 42 | + 'step' => 1, |
|
| 43 | + 'messages' => array( |
|
| 44 | + 'number' => $this->get_validation_error_message(), |
|
| 45 | + 'step' => $this->get_validation_error_message() |
|
| 46 | + ) |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | public function __construct($validation_error_message = null) |
| 16 | 16 | { |
| 17 | - if (! $validation_error_message) { |
|
| 17 | + if ( ! $validation_error_message) { |
|
| 18 | 18 | $validation_error_message = __("Only digits are allowed.", "event_espresso"); |
| 19 | 19 | } |
| 20 | 20 | parent::__construct($validation_error_message); |
@@ -11,245 +11,245 @@ |
||
| 11 | 11 | class EE_Conditionally_Required_Validation_Strategy extends EE_Validation_Strategy_Base |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Array describing conditions necessary to make the input required. |
|
| 16 | - * This is used to derive a jquery dependency expression (see http://jqueryvalidation.org/required-method) |
|
| 17 | - * or jquery callback; and server-side logic to determine if the field is necessary. |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - protected $requirement_conditions; |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @param string $validation_error_message |
|
| 26 | - * @param array $requirement_conditions |
|
| 27 | - */ |
|
| 28 | - public function __construct($validation_error_message = null, $requirement_conditions = array()) |
|
| 29 | - { |
|
| 30 | - if (! $validation_error_message) { |
|
| 31 | - $validation_error_message = __("This field is required.", "event_espresso"); |
|
| 32 | - } |
|
| 33 | - $this->set_requirement_conditions($requirement_conditions); |
|
| 34 | - parent::__construct($validation_error_message); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * just checks the field isn't blank, provided the requirement conditions |
|
| 41 | - * indicate this input is still required |
|
| 42 | - * |
|
| 43 | - * @param $normalized_value |
|
| 44 | - * @return bool |
|
| 45 | - * @throws \EE_Error |
|
| 46 | - * @throws \EE_Validation_Error |
|
| 47 | - */ |
|
| 48 | - public function validate($normalized_value) |
|
| 49 | - { |
|
| 50 | - if (( |
|
| 51 | - $normalized_value === '' |
|
| 52 | - || $normalized_value === null |
|
| 53 | - || $normalized_value === array() |
|
| 54 | - ) |
|
| 55 | - && $this->_input_is_required_server_side() |
|
| 56 | - ) { |
|
| 57 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
| 58 | - } else { |
|
| 59 | - return true; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return array |
|
| 67 | - * @throws \EE_Error |
|
| 68 | - */ |
|
| 69 | - public function get_jquery_validation_rule_array() |
|
| 70 | - { |
|
| 71 | - return array( |
|
| 72 | - 'required'=> $this->_get_jquery_requirement_value(), |
|
| 73 | - 'messages' => array( |
|
| 74 | - 'required' => $this->get_validation_error_message() |
|
| 75 | - ) |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Sets the "required conditions". This should be an array, its top-level key |
|
| 81 | - * is the name of a field, its value is an array. This 2nd level array has two items: |
|
| 82 | - * the first is the operator (for now only '=' is accepted), and teh 2nd argument is the |
|
| 83 | - * the value the field should be in order to make the field required. |
|
| 84 | - * Eg array( 'payment_type' => array( '=', 'credit_card' ). |
|
| 85 | - * |
|
| 86 | - * @param array $requirement_conditions |
|
| 87 | - */ |
|
| 88 | - public function set_requirement_conditions($requirement_conditions) |
|
| 89 | - { |
|
| 90 | - $this->requirement_conditions = (array) $requirement_conditions; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Gets the array that describes when the related input should be required. |
|
| 95 | - * see set_requirement_conditions for a description of how it should be formatted |
|
| 96 | - * @return array |
|
| 97 | - */ |
|
| 98 | - public function get_requirement_conditions() |
|
| 99 | - { |
|
| 100 | - return $this->requirement_conditions; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * gets jQuery dependency expression used for client-side validation |
|
| 107 | - * Its possible this could also return a javascript callback used for determining |
|
| 108 | - * if the input is required or not. That is not yet implemented, however. |
|
| 109 | - * |
|
| 110 | - * @return string see http://jqueryvalidation.org/required-method for format |
|
| 111 | - * @throws \EE_Error |
|
| 112 | - */ |
|
| 113 | - protected function _get_jquery_requirement_value() |
|
| 114 | - { |
|
| 115 | - $requirement_value = ''; |
|
| 116 | - $conditions = $this->get_requirement_conditions(); |
|
| 117 | - if (! is_array($conditions)) { |
|
| 118 | - EE_Error::throw_exception_if_debugging( |
|
| 119 | - sprintf( |
|
| 120 | - __('Input requirement conditions must be an array. You provided %1$s', 'event_espresso'), |
|
| 121 | - $this->_input->name() |
|
| 122 | - ), |
|
| 123 | - __FILE__, |
|
| 124 | - __FUNCTION__, |
|
| 125 | - __LINE__ |
|
| 126 | - ); |
|
| 127 | - return true; |
|
| 128 | - } |
|
| 129 | - if (count($conditions) > 1) { |
|
| 130 | - EE_Error::throw_exception_if_debugging( |
|
| 131 | - sprintf( |
|
| 132 | - __('Required Validation Strategy does not yet support multiple conditions. You should add it! The related input is %1$s', 'event_espresso'), |
|
| 133 | - $this->_input->name() |
|
| 134 | - ), |
|
| 135 | - __FILE__, |
|
| 136 | - __FUNCTION__, |
|
| 137 | - __LINE__ |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - foreach ($conditions as $input_path => $op_and_value) { |
|
| 141 | - $input = $this->_input->find_section_from_path($input_path); |
|
| 142 | - if (! $input instanceof EE_Form_Input_Base) { |
|
| 143 | - EE_Error::throw_exception_if_debugging( |
|
| 144 | - sprintf( |
|
| 145 | - __('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
|
| 146 | - $this->_input->name(), |
|
| 147 | - $input_path |
|
| 148 | - ), |
|
| 149 | - __FILE__, |
|
| 150 | - __FUNCTION__, |
|
| 151 | - __LINE__ |
|
| 152 | - ); |
|
| 153 | - return false; |
|
| 154 | - } |
|
| 155 | - list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
| 156 | - // ok now the jquery dependency expression depends on the input's display strategy. |
|
| 157 | - if (! $input->get_display_strategy() instanceof EE_Select_Display_Strategy) { |
|
| 158 | - EE_Error::throw_exception_if_debugging( |
|
| 159 | - sprintf( |
|
| 160 | - __('Required Validation Strategy can only depend on another input which uses the EE_Select_Display_Strategy, but you specified a field "%1$s" that uses display strategy "%2$s". If you need others, please add support for it! The related input is %3$s', 'event_espresso'), |
|
| 161 | - $input->name(), |
|
| 162 | - get_class($input->get_display_strategy()), |
|
| 163 | - $this->_input->name() |
|
| 164 | - ), |
|
| 165 | - __FILE__, |
|
| 166 | - __FUNCTION__, |
|
| 167 | - __LINE__ |
|
| 168 | - ); |
|
| 169 | - } |
|
| 170 | - $requirement_value = $input->html_id(true) . ' option[value="' . $value . '"]:selected'; |
|
| 171 | - } |
|
| 172 | - return $requirement_value; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Returns whether or not this input is required based on the _requirement_conditions |
|
| 179 | - * (not whether or not the input passes validation. That's for the validate method |
|
| 180 | - * to decide) |
|
| 181 | - * |
|
| 182 | - * @return boolean |
|
| 183 | - * @throws \EE_Error |
|
| 184 | - */ |
|
| 185 | - protected function _input_is_required_server_side() |
|
| 186 | - { |
|
| 187 | - $meets_all_requirements = true; |
|
| 188 | - $conditions = $this->get_requirement_conditions(); |
|
| 189 | - foreach ($conditions as $input_path => $op_and_value) { |
|
| 190 | - $input = $this->_input->find_section_from_path($input_path); |
|
| 191 | - if (! $input instanceof EE_Form_Input_Base) { |
|
| 192 | - EE_Error::throw_exception_if_debugging( |
|
| 193 | - sprintf( |
|
| 194 | - __('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
|
| 195 | - $this->_input->name(), |
|
| 196 | - $input_path |
|
| 197 | - ), |
|
| 198 | - __FILE__, |
|
| 199 | - __FUNCTION__, |
|
| 200 | - __LINE__ |
|
| 201 | - ); |
|
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
| 205 | - switch ($op) { |
|
| 206 | - case '=': |
|
| 207 | - default: |
|
| 208 | - $meets_all_requirements = $input->normalized_value() === $value; |
|
| 209 | - } |
|
| 210 | - if (! $meets_all_requirements) { |
|
| 211 | - break; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - return $meets_all_requirements; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Verifies this is an array with keys 0 and 1, where key 0 is a usable |
|
| 221 | - * operator (initially just '=') and key 1 is something that can be cast to a string |
|
| 222 | - * |
|
| 223 | - * @param array $op_and_value |
|
| 224 | - * @return array |
|
| 225 | - * @throws \EE_Error |
|
| 226 | - */ |
|
| 227 | - protected function _validate_op_and_value($op_and_value) |
|
| 228 | - { |
|
| 229 | - if (! isset($op_and_value[0], $op_and_value[1])) { |
|
| 230 | - EE_Error::throw_exception_if_debugging( |
|
| 231 | - sprintf( |
|
| 232 | - __('Required Validation Strategy conditions array\'s value must be an array with two elements: an operator, and a value. It didn\'t. The related input is %1$s', 'event_espresso'), |
|
| 233 | - $this->_input->name() |
|
| 234 | - ), |
|
| 235 | - __FILE__, |
|
| 236 | - __FUNCTION__, |
|
| 237 | - __LINE__ |
|
| 238 | - ); |
|
| 239 | - } |
|
| 240 | - $operator = $op_and_value[0]; |
|
| 241 | - $value = (string) $op_and_value[1]; |
|
| 242 | - if ($operator !== '=') { |
|
| 243 | - EE_Error::throw_exception_if_debugging( |
|
| 244 | - sprintf( |
|
| 245 | - __('Required Validation Strategy conditions can currently only use the equals operator. If you need others, please add support for it! The related input is %1$s', 'event_espresso'), |
|
| 246 | - $this->_input->name() |
|
| 247 | - ), |
|
| 248 | - __FILE__, |
|
| 249 | - __FUNCTION__, |
|
| 250 | - __LINE__ |
|
| 251 | - ); |
|
| 252 | - } |
|
| 253 | - return array( $operator, $value ); |
|
| 254 | - } |
|
| 14 | + /** |
|
| 15 | + * Array describing conditions necessary to make the input required. |
|
| 16 | + * This is used to derive a jquery dependency expression (see http://jqueryvalidation.org/required-method) |
|
| 17 | + * or jquery callback; and server-side logic to determine if the field is necessary. |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + protected $requirement_conditions; |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @param string $validation_error_message |
|
| 26 | + * @param array $requirement_conditions |
|
| 27 | + */ |
|
| 28 | + public function __construct($validation_error_message = null, $requirement_conditions = array()) |
|
| 29 | + { |
|
| 30 | + if (! $validation_error_message) { |
|
| 31 | + $validation_error_message = __("This field is required.", "event_espresso"); |
|
| 32 | + } |
|
| 33 | + $this->set_requirement_conditions($requirement_conditions); |
|
| 34 | + parent::__construct($validation_error_message); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * just checks the field isn't blank, provided the requirement conditions |
|
| 41 | + * indicate this input is still required |
|
| 42 | + * |
|
| 43 | + * @param $normalized_value |
|
| 44 | + * @return bool |
|
| 45 | + * @throws \EE_Error |
|
| 46 | + * @throws \EE_Validation_Error |
|
| 47 | + */ |
|
| 48 | + public function validate($normalized_value) |
|
| 49 | + { |
|
| 50 | + if (( |
|
| 51 | + $normalized_value === '' |
|
| 52 | + || $normalized_value === null |
|
| 53 | + || $normalized_value === array() |
|
| 54 | + ) |
|
| 55 | + && $this->_input_is_required_server_side() |
|
| 56 | + ) { |
|
| 57 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
| 58 | + } else { |
|
| 59 | + return true; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return array |
|
| 67 | + * @throws \EE_Error |
|
| 68 | + */ |
|
| 69 | + public function get_jquery_validation_rule_array() |
|
| 70 | + { |
|
| 71 | + return array( |
|
| 72 | + 'required'=> $this->_get_jquery_requirement_value(), |
|
| 73 | + 'messages' => array( |
|
| 74 | + 'required' => $this->get_validation_error_message() |
|
| 75 | + ) |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Sets the "required conditions". This should be an array, its top-level key |
|
| 81 | + * is the name of a field, its value is an array. This 2nd level array has two items: |
|
| 82 | + * the first is the operator (for now only '=' is accepted), and teh 2nd argument is the |
|
| 83 | + * the value the field should be in order to make the field required. |
|
| 84 | + * Eg array( 'payment_type' => array( '=', 'credit_card' ). |
|
| 85 | + * |
|
| 86 | + * @param array $requirement_conditions |
|
| 87 | + */ |
|
| 88 | + public function set_requirement_conditions($requirement_conditions) |
|
| 89 | + { |
|
| 90 | + $this->requirement_conditions = (array) $requirement_conditions; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Gets the array that describes when the related input should be required. |
|
| 95 | + * see set_requirement_conditions for a description of how it should be formatted |
|
| 96 | + * @return array |
|
| 97 | + */ |
|
| 98 | + public function get_requirement_conditions() |
|
| 99 | + { |
|
| 100 | + return $this->requirement_conditions; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * gets jQuery dependency expression used for client-side validation |
|
| 107 | + * Its possible this could also return a javascript callback used for determining |
|
| 108 | + * if the input is required or not. That is not yet implemented, however. |
|
| 109 | + * |
|
| 110 | + * @return string see http://jqueryvalidation.org/required-method for format |
|
| 111 | + * @throws \EE_Error |
|
| 112 | + */ |
|
| 113 | + protected function _get_jquery_requirement_value() |
|
| 114 | + { |
|
| 115 | + $requirement_value = ''; |
|
| 116 | + $conditions = $this->get_requirement_conditions(); |
|
| 117 | + if (! is_array($conditions)) { |
|
| 118 | + EE_Error::throw_exception_if_debugging( |
|
| 119 | + sprintf( |
|
| 120 | + __('Input requirement conditions must be an array. You provided %1$s', 'event_espresso'), |
|
| 121 | + $this->_input->name() |
|
| 122 | + ), |
|
| 123 | + __FILE__, |
|
| 124 | + __FUNCTION__, |
|
| 125 | + __LINE__ |
|
| 126 | + ); |
|
| 127 | + return true; |
|
| 128 | + } |
|
| 129 | + if (count($conditions) > 1) { |
|
| 130 | + EE_Error::throw_exception_if_debugging( |
|
| 131 | + sprintf( |
|
| 132 | + __('Required Validation Strategy does not yet support multiple conditions. You should add it! The related input is %1$s', 'event_espresso'), |
|
| 133 | + $this->_input->name() |
|
| 134 | + ), |
|
| 135 | + __FILE__, |
|
| 136 | + __FUNCTION__, |
|
| 137 | + __LINE__ |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + foreach ($conditions as $input_path => $op_and_value) { |
|
| 141 | + $input = $this->_input->find_section_from_path($input_path); |
|
| 142 | + if (! $input instanceof EE_Form_Input_Base) { |
|
| 143 | + EE_Error::throw_exception_if_debugging( |
|
| 144 | + sprintf( |
|
| 145 | + __('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
|
| 146 | + $this->_input->name(), |
|
| 147 | + $input_path |
|
| 148 | + ), |
|
| 149 | + __FILE__, |
|
| 150 | + __FUNCTION__, |
|
| 151 | + __LINE__ |
|
| 152 | + ); |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 155 | + list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
| 156 | + // ok now the jquery dependency expression depends on the input's display strategy. |
|
| 157 | + if (! $input->get_display_strategy() instanceof EE_Select_Display_Strategy) { |
|
| 158 | + EE_Error::throw_exception_if_debugging( |
|
| 159 | + sprintf( |
|
| 160 | + __('Required Validation Strategy can only depend on another input which uses the EE_Select_Display_Strategy, but you specified a field "%1$s" that uses display strategy "%2$s". If you need others, please add support for it! The related input is %3$s', 'event_espresso'), |
|
| 161 | + $input->name(), |
|
| 162 | + get_class($input->get_display_strategy()), |
|
| 163 | + $this->_input->name() |
|
| 164 | + ), |
|
| 165 | + __FILE__, |
|
| 166 | + __FUNCTION__, |
|
| 167 | + __LINE__ |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | + $requirement_value = $input->html_id(true) . ' option[value="' . $value . '"]:selected'; |
|
| 171 | + } |
|
| 172 | + return $requirement_value; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Returns whether or not this input is required based on the _requirement_conditions |
|
| 179 | + * (not whether or not the input passes validation. That's for the validate method |
|
| 180 | + * to decide) |
|
| 181 | + * |
|
| 182 | + * @return boolean |
|
| 183 | + * @throws \EE_Error |
|
| 184 | + */ |
|
| 185 | + protected function _input_is_required_server_side() |
|
| 186 | + { |
|
| 187 | + $meets_all_requirements = true; |
|
| 188 | + $conditions = $this->get_requirement_conditions(); |
|
| 189 | + foreach ($conditions as $input_path => $op_and_value) { |
|
| 190 | + $input = $this->_input->find_section_from_path($input_path); |
|
| 191 | + if (! $input instanceof EE_Form_Input_Base) { |
|
| 192 | + EE_Error::throw_exception_if_debugging( |
|
| 193 | + sprintf( |
|
| 194 | + __('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
|
| 195 | + $this->_input->name(), |
|
| 196 | + $input_path |
|
| 197 | + ), |
|
| 198 | + __FILE__, |
|
| 199 | + __FUNCTION__, |
|
| 200 | + __LINE__ |
|
| 201 | + ); |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
| 205 | + switch ($op) { |
|
| 206 | + case '=': |
|
| 207 | + default: |
|
| 208 | + $meets_all_requirements = $input->normalized_value() === $value; |
|
| 209 | + } |
|
| 210 | + if (! $meets_all_requirements) { |
|
| 211 | + break; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + return $meets_all_requirements; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Verifies this is an array with keys 0 and 1, where key 0 is a usable |
|
| 221 | + * operator (initially just '=') and key 1 is something that can be cast to a string |
|
| 222 | + * |
|
| 223 | + * @param array $op_and_value |
|
| 224 | + * @return array |
|
| 225 | + * @throws \EE_Error |
|
| 226 | + */ |
|
| 227 | + protected function _validate_op_and_value($op_and_value) |
|
| 228 | + { |
|
| 229 | + if (! isset($op_and_value[0], $op_and_value[1])) { |
|
| 230 | + EE_Error::throw_exception_if_debugging( |
|
| 231 | + sprintf( |
|
| 232 | + __('Required Validation Strategy conditions array\'s value must be an array with two elements: an operator, and a value. It didn\'t. The related input is %1$s', 'event_espresso'), |
|
| 233 | + $this->_input->name() |
|
| 234 | + ), |
|
| 235 | + __FILE__, |
|
| 236 | + __FUNCTION__, |
|
| 237 | + __LINE__ |
|
| 238 | + ); |
|
| 239 | + } |
|
| 240 | + $operator = $op_and_value[0]; |
|
| 241 | + $value = (string) $op_and_value[1]; |
|
| 242 | + if ($operator !== '=') { |
|
| 243 | + EE_Error::throw_exception_if_debugging( |
|
| 244 | + sprintf( |
|
| 245 | + __('Required Validation Strategy conditions can currently only use the equals operator. If you need others, please add support for it! The related input is %1$s', 'event_espresso'), |
|
| 246 | + $this->_input->name() |
|
| 247 | + ), |
|
| 248 | + __FILE__, |
|
| 249 | + __FUNCTION__, |
|
| 250 | + __LINE__ |
|
| 251 | + ); |
|
| 252 | + } |
|
| 253 | + return array( $operator, $value ); |
|
| 254 | + } |
|
| 255 | 255 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public function __construct($validation_error_message = null, $requirement_conditions = array()) |
| 29 | 29 | { |
| 30 | - if (! $validation_error_message) { |
|
| 30 | + if ( ! $validation_error_message) { |
|
| 31 | 31 | $validation_error_message = __("This field is required.", "event_espresso"); |
| 32 | 32 | } |
| 33 | 33 | $this->set_requirement_conditions($requirement_conditions); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | { |
| 115 | 115 | $requirement_value = ''; |
| 116 | 116 | $conditions = $this->get_requirement_conditions(); |
| 117 | - if (! is_array($conditions)) { |
|
| 117 | + if ( ! is_array($conditions)) { |
|
| 118 | 118 | EE_Error::throw_exception_if_debugging( |
| 119 | 119 | sprintf( |
| 120 | 120 | __('Input requirement conditions must be an array. You provided %1$s', 'event_espresso'), |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | foreach ($conditions as $input_path => $op_and_value) { |
| 141 | 141 | $input = $this->_input->find_section_from_path($input_path); |
| 142 | - if (! $input instanceof EE_Form_Input_Base) { |
|
| 142 | + if ( ! $input instanceof EE_Form_Input_Base) { |
|
| 143 | 143 | EE_Error::throw_exception_if_debugging( |
| 144 | 144 | sprintf( |
| 145 | 145 | __('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | ); |
| 153 | 153 | return false; |
| 154 | 154 | } |
| 155 | - list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
| 155 | + list($op, $value) = $this->_validate_op_and_value($op_and_value); |
|
| 156 | 156 | // ok now the jquery dependency expression depends on the input's display strategy. |
| 157 | - if (! $input->get_display_strategy() instanceof EE_Select_Display_Strategy) { |
|
| 157 | + if ( ! $input->get_display_strategy() instanceof EE_Select_Display_Strategy) { |
|
| 158 | 158 | EE_Error::throw_exception_if_debugging( |
| 159 | 159 | sprintf( |
| 160 | 160 | __('Required Validation Strategy can only depend on another input which uses the EE_Select_Display_Strategy, but you specified a field "%1$s" that uses display strategy "%2$s". If you need others, please add support for it! The related input is %3$s', 'event_espresso'), |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | __LINE__ |
| 168 | 168 | ); |
| 169 | 169 | } |
| 170 | - $requirement_value = $input->html_id(true) . ' option[value="' . $value . '"]:selected'; |
|
| 170 | + $requirement_value = $input->html_id(true).' option[value="'.$value.'"]:selected'; |
|
| 171 | 171 | } |
| 172 | 172 | return $requirement_value; |
| 173 | 173 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $conditions = $this->get_requirement_conditions(); |
| 189 | 189 | foreach ($conditions as $input_path => $op_and_value) { |
| 190 | 190 | $input = $this->_input->find_section_from_path($input_path); |
| 191 | - if (! $input instanceof EE_Form_Input_Base) { |
|
| 191 | + if ( ! $input instanceof EE_Form_Input_Base) { |
|
| 192 | 192 | EE_Error::throw_exception_if_debugging( |
| 193 | 193 | sprintf( |
| 194 | 194 | __('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | ); |
| 202 | 202 | return false; |
| 203 | 203 | } |
| 204 | - list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
| 204 | + list($op, $value) = $this->_validate_op_and_value($op_and_value); |
|
| 205 | 205 | switch ($op) { |
| 206 | 206 | case '=': |
| 207 | 207 | default: |
| 208 | 208 | $meets_all_requirements = $input->normalized_value() === $value; |
| 209 | 209 | } |
| 210 | - if (! $meets_all_requirements) { |
|
| 210 | + if ( ! $meets_all_requirements) { |
|
| 211 | 211 | break; |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | protected function _validate_op_and_value($op_and_value) |
| 228 | 228 | { |
| 229 | - if (! isset($op_and_value[0], $op_and_value[1])) { |
|
| 229 | + if ( ! isset($op_and_value[0], $op_and_value[1])) { |
|
| 230 | 230 | EE_Error::throw_exception_if_debugging( |
| 231 | 231 | sprintf( |
| 232 | 232 | __('Required Validation Strategy conditions array\'s value must be an array with two elements: an operator, and a value. It didn\'t. The related input is %1$s', 'event_espresso'), |
@@ -250,6 +250,6 @@ discard block |
||
| 250 | 250 | __LINE__ |
| 251 | 251 | ); |
| 252 | 252 | } |
| 253 | - return array( $operator, $value ); |
|
| 253 | + return array($operator, $value); |
|
| 254 | 254 | } |
| 255 | 255 | } |
@@ -13,53 +13,53 @@ |
||
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param string $validation_error_message |
|
| 18 | - */ |
|
| 19 | - public function __construct($validation_error_message = null) |
|
| 20 | - { |
|
| 21 | - if (! $validation_error_message) { |
|
| 22 | - $validation_error_message = __("This field is required.", "event_espresso"); |
|
| 23 | - } |
|
| 24 | - parent::__construct($validation_error_message); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * @param string $validation_error_message |
|
| 18 | + */ |
|
| 19 | + public function __construct($validation_error_message = null) |
|
| 20 | + { |
|
| 21 | + if (! $validation_error_message) { |
|
| 22 | + $validation_error_message = __("This field is required.", "event_espresso"); |
|
| 23 | + } |
|
| 24 | + parent::__construct($validation_error_message); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * just checks the field isn't blank, provided the requirement conditions |
|
| 31 | - * indicate this input is still required |
|
| 32 | - * |
|
| 33 | - * @param $normalized_value |
|
| 34 | - * @return bool |
|
| 35 | - * @throws \EE_Error |
|
| 36 | - * @throws \EE_Validation_Error |
|
| 37 | - */ |
|
| 38 | - public function validate($normalized_value) |
|
| 39 | - { |
|
| 40 | - if ($normalized_value === '' |
|
| 41 | - || $normalized_value === null |
|
| 42 | - || $normalized_value === array() |
|
| 43 | - ) { |
|
| 44 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
| 45 | - } else { |
|
| 46 | - return true; |
|
| 47 | - } |
|
| 48 | - } |
|
| 29 | + /** |
|
| 30 | + * just checks the field isn't blank, provided the requirement conditions |
|
| 31 | + * indicate this input is still required |
|
| 32 | + * |
|
| 33 | + * @param $normalized_value |
|
| 34 | + * @return bool |
|
| 35 | + * @throws \EE_Error |
|
| 36 | + * @throws \EE_Validation_Error |
|
| 37 | + */ |
|
| 38 | + public function validate($normalized_value) |
|
| 39 | + { |
|
| 40 | + if ($normalized_value === '' |
|
| 41 | + || $normalized_value === null |
|
| 42 | + || $normalized_value === array() |
|
| 43 | + ) { |
|
| 44 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
| 45 | + } else { |
|
| 46 | + return true; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return array |
|
| 54 | - * @throws \EE_Error |
|
| 55 | - */ |
|
| 56 | - public function get_jquery_validation_rule_array() |
|
| 57 | - { |
|
| 58 | - return array( |
|
| 59 | - 'required'=> true, |
|
| 60 | - 'messages' => array( |
|
| 61 | - 'required' => $this->get_validation_error_message() |
|
| 62 | - ) |
|
| 63 | - ); |
|
| 64 | - } |
|
| 52 | + /** |
|
| 53 | + * @return array |
|
| 54 | + * @throws \EE_Error |
|
| 55 | + */ |
|
| 56 | + public function get_jquery_validation_rule_array() |
|
| 57 | + { |
|
| 58 | + return array( |
|
| 59 | + 'required'=> true, |
|
| 60 | + 'messages' => array( |
|
| 61 | + 'required' => $this->get_validation_error_message() |
|
| 62 | + ) |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | public function __construct($validation_error_message = null) |
| 20 | 20 | { |
| 21 | - if (! $validation_error_message) { |
|
| 21 | + if ( ! $validation_error_message) { |
|
| 22 | 22 | $validation_error_message = __("This field is required.", "event_espresso"); |
| 23 | 23 | } |
| 24 | 24 | parent::__construct($validation_error_message); |
@@ -10,52 +10,52 @@ |
||
| 10 | 10 | class EE_Text_Validation_Strategy extends EE_Validation_Strategy_Base |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - protected $_regex = null; |
|
| 14 | - /** |
|
| 15 | - * |
|
| 16 | - * @param string $validation_error_message |
|
| 17 | - * @param string $regex a PHP regex; the javascript regex will be derived from this |
|
| 18 | - */ |
|
| 19 | - public function __construct($validation_error_message = null, $regex = null) |
|
| 20 | - { |
|
| 21 | - $this->_regex = $regex; |
|
| 22 | - parent::__construct($validation_error_message); |
|
| 23 | - } |
|
| 13 | + protected $_regex = null; |
|
| 14 | + /** |
|
| 15 | + * |
|
| 16 | + * @param string $validation_error_message |
|
| 17 | + * @param string $regex a PHP regex; the javascript regex will be derived from this |
|
| 18 | + */ |
|
| 19 | + public function __construct($validation_error_message = null, $regex = null) |
|
| 20 | + { |
|
| 21 | + $this->_regex = $regex; |
|
| 22 | + parent::__construct($validation_error_message); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param $normalized_value |
|
| 27 | - */ |
|
| 28 | - public function validate($normalized_value) |
|
| 29 | - { |
|
| 30 | - if ($this->_regex && $normalized_value) { |
|
| 31 | - if (! preg_match($this->_regex, $normalized_value)) { |
|
| 32 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'regex'); |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - } |
|
| 25 | + /** |
|
| 26 | + * @param $normalized_value |
|
| 27 | + */ |
|
| 28 | + public function validate($normalized_value) |
|
| 29 | + { |
|
| 30 | + if ($this->_regex && $normalized_value) { |
|
| 31 | + if (! preg_match($this->_regex, $normalized_value)) { |
|
| 32 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'regex'); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return array |
|
| 39 | - */ |
|
| 40 | - public function get_jquery_validation_rule_array() |
|
| 41 | - { |
|
| 42 | - if ($this->_regex !== null) { |
|
| 43 | - return array( 'regex'=> $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) ); |
|
| 44 | - } else { |
|
| 45 | - return array(); |
|
| 46 | - } |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * @return array |
|
| 39 | + */ |
|
| 40 | + public function get_jquery_validation_rule_array() |
|
| 41 | + { |
|
| 42 | + if ($this->_regex !== null) { |
|
| 43 | + return array( 'regex'=> $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) ); |
|
| 44 | + } else { |
|
| 45 | + return array(); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Translates a PHP regex into a javscript regex (eg, PHP needs separate delimieters, whereas |
| 51 | 51 | * javscript does not |
| 52 | 52 | * @return string |
| 53 | 53 | */ |
| 54 | - public function regex_js() |
|
| 55 | - { |
|
| 56 | - // first character must be the delimiter |
|
| 57 | - $delimeter = $this->_regex[0]; |
|
| 58 | - $last_occurence_of_delimieter = strrpos($this->_regex, $delimeter); |
|
| 59 | - return substr($this->_regex, 1, $last_occurence_of_delimieter - 1); |
|
| 60 | - } |
|
| 54 | + public function regex_js() |
|
| 55 | + { |
|
| 56 | + // first character must be the delimiter |
|
| 57 | + $delimeter = $this->_regex[0]; |
|
| 58 | + $last_occurence_of_delimieter = strrpos($this->_regex, $delimeter); |
|
| 59 | + return substr($this->_regex, 1, $last_occurence_of_delimieter - 1); |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function validate($normalized_value) |
| 29 | 29 | { |
| 30 | 30 | if ($this->_regex && $normalized_value) { |
| 31 | - if (! preg_match($this->_regex, $normalized_value)) { |
|
| 31 | + if ( ! preg_match($this->_regex, $normalized_value)) { |
|
| 32 | 32 | throw new EE_Validation_Error($this->get_validation_error_message(), 'regex'); |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | public function get_jquery_validation_rule_array() |
| 41 | 41 | { |
| 42 | 42 | if ($this->_regex !== null) { |
| 43 | - return array( 'regex'=> $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) ); |
|
| 43 | + return array('regex'=> $this->regex_js(), 'messages' => array('regex' => $this->get_validation_error_message())); |
|
| 44 | 44 | } else { |
| 45 | 45 | return array(); |
| 46 | 46 | } |