@@ -14,9 +14,9 @@ |
||
14 | 14 | * @param array $options |
15 | 15 | */ |
16 | 16 | public function __construct($options = array()){ |
17 | - if( empty($options['default'])) { |
|
18 | - $options['default'] = esc_html__('Submit', 'event_espresso'); |
|
19 | - } |
|
17 | + if( empty($options['default'])) { |
|
18 | + $options['default'] = esc_html__('Submit', 'event_espresso'); |
|
19 | + } |
|
20 | 20 | $this->_set_display_strategy(new EE_Submit_Input_Display_Strategy()); |
21 | 21 | $this->_set_normalization_strategy(new EE_Text_Normalization()); |
22 | 22 | $this->_add_validation_strategy( new EE_Plaintext_Validation_Strategy() ); |
@@ -8,18 +8,18 @@ |
||
8 | 8 | * |
9 | 9 | * This input has a default validation strategy of plaintext (which can be removed after construction) |
10 | 10 | */ |
11 | -class EE_Submit_Input extends EE_Form_Input_Base{ |
|
11 | +class EE_Submit_Input extends EE_Form_Input_Base { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @param array $options |
15 | 15 | */ |
16 | - public function __construct($options = array()){ |
|
17 | - if( empty($options['default'])) { |
|
16 | + public function __construct($options = array()) { |
|
17 | + if (empty($options['default'])) { |
|
18 | 18 | $options['default'] = esc_html__('Submit', 'event_espresso'); |
19 | 19 | } |
20 | 20 | $this->_set_display_strategy(new EE_Submit_Input_Display_Strategy()); |
21 | 21 | $this->_set_normalization_strategy(new EE_Text_Normalization()); |
22 | - $this->_add_validation_strategy( new EE_Plaintext_Validation_Strategy() ); |
|
22 | + $this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy()); |
|
23 | 23 | parent::__construct($options); |
24 | 24 | } |
25 | 25 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,1164 +16,1164 @@ discard block |
||
16 | 16 | abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * the input's name attribute |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_html_name; |
|
25 | - |
|
26 | - /** |
|
27 | - * id for the html label tag |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_html_label_id; |
|
32 | - |
|
33 | - /** |
|
34 | - * class for teh html label tag |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $_html_label_class; |
|
39 | - |
|
40 | - /** |
|
41 | - * any additional html attributes that you may want to add |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - protected $_html_other_attributes; |
|
46 | - |
|
47 | - /** |
|
48 | - * style for teh html label tag |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_html_label_style; |
|
53 | - |
|
54 | - /** |
|
55 | - * text to be placed in the html label |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - protected $_html_label_text; |
|
60 | - |
|
61 | - /** |
|
62 | - * the full html label. If used, all other html_label_* properties are invalid |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - protected $_html_label; |
|
67 | - |
|
68 | - /** |
|
69 | - * HTML to use for help text (normally placed below form input), in a span which normally |
|
70 | - * has a class of 'description' |
|
71 | - * |
|
72 | - * @var string |
|
73 | - */ |
|
74 | - protected $_html_help_text; |
|
75 | - |
|
76 | - /** |
|
77 | - * CSS classes for displaying the help span |
|
78 | - * |
|
79 | - * @var string |
|
80 | - */ |
|
81 | - protected $_html_help_class = 'description'; |
|
82 | - |
|
83 | - /** |
|
84 | - * CSS to put in the style attribute on the help span |
|
85 | - * |
|
86 | - * @var string |
|
87 | - */ |
|
88 | - protected $_html_help_style; |
|
89 | - |
|
90 | - /** |
|
91 | - * Stores whether or not this input's response is required. |
|
92 | - * Because certain styling elements may also want to know that this |
|
93 | - * input is required etc. |
|
94 | - * |
|
95 | - * @var boolean |
|
96 | - */ |
|
97 | - protected $_required; |
|
98 | - |
|
99 | - /** |
|
100 | - * css class added to required inputs |
|
101 | - * |
|
102 | - * @var string |
|
103 | - */ |
|
104 | - protected $_required_css_class = 'ee-required'; |
|
105 | - |
|
106 | - /** |
|
107 | - * css styles applied to button type inputs |
|
108 | - * |
|
109 | - * @var string |
|
110 | - */ |
|
111 | - protected $_button_css_attributes; |
|
112 | - |
|
113 | - /** |
|
114 | - * The raw data submitted for this, like in the $_POST super global. |
|
115 | - * Generally unsafe for usage in client code |
|
116 | - * |
|
117 | - * @var mixed string or array |
|
118 | - */ |
|
119 | - protected $_raw_value; |
|
120 | - |
|
121 | - /** |
|
122 | - * Value normalized according to the input's normalization strategy. |
|
123 | - * The normalization strategy dictates whether this is a string, int, float, |
|
124 | - * boolean, or array of any of those. |
|
125 | - * |
|
126 | - * @var mixed |
|
127 | - */ |
|
128 | - protected $_normalized_value; |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Normalized default value either initially set on the input, or provided by calling |
|
133 | - * set_default(). |
|
134 | - * @var mixed |
|
135 | - */ |
|
136 | - protected $_default; |
|
137 | - |
|
138 | - /** |
|
139 | - * Strategy used for displaying this field. |
|
140 | - * Child classes must use _get_display_strategy to access it. |
|
141 | - * |
|
142 | - * @var EE_Display_Strategy_Base |
|
143 | - */ |
|
144 | - private $_display_strategy; |
|
145 | - |
|
146 | - /** |
|
147 | - * Gets all the validation strategies used on this field |
|
148 | - * |
|
149 | - * @var EE_Validation_Strategy_Base[] |
|
150 | - */ |
|
151 | - private $_validation_strategies = array(); |
|
152 | - |
|
153 | - /** |
|
154 | - * The normalization strategy for this field |
|
155 | - * |
|
156 | - * @var EE_Normalization_Strategy_Base |
|
157 | - */ |
|
158 | - private $_normalization_strategy; |
|
159 | - |
|
160 | - /** |
|
161 | - * Strategy for removing sensitive data after we're done with the form input |
|
162 | - * |
|
163 | - * @var EE_Sensitive_Data_Removal_Base |
|
164 | - */ |
|
165 | - protected $_sensitive_data_removal_strategy; |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param array $input_args { |
|
171 | - * @type string $html_name the html name for the input |
|
172 | - * @type string $html_label_id the id attribute to give to the html label tag |
|
173 | - * @type string $html_label_class the class attribute to give to the html label tag |
|
174 | - * @type string $html_label_style the style attribute to give ot teh label tag |
|
175 | - * @type string $html_label_text the text to put in the label tag |
|
176 | - * @type string $html_label the full html label. If used, |
|
177 | - * all other html_label_* args are invalid |
|
178 | - * @type string $html_help_text text to put in help element |
|
179 | - * @type string $html_help_style style attribute to give to teh help element |
|
180 | - * @type string $html_help_class class attribute to give to the help element |
|
181 | - * @type string $default default value NORMALIZED (eg, if providing the default |
|
182 | - * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
183 | - * @type EE_Display_Strategy_Base $display strategy |
|
184 | - * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
185 | - * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
186 | - * } |
|
187 | - */ |
|
188 | - public function __construct($input_args = array()) |
|
189 | - { |
|
190 | - $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
191 | - // the following properties must be cast as arrays |
|
192 | - if (isset($input_args['validation_strategies'])) { |
|
193 | - foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
194 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
195 | - $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
196 | - } |
|
197 | - } |
|
198 | - unset($input_args['validation_strategies']); |
|
199 | - } |
|
200 | - // loop thru incoming options |
|
201 | - foreach ($input_args as $key => $value) { |
|
202 | - // add underscore to $key to match property names |
|
203 | - $_key = '_' . $key; |
|
204 | - if (property_exists($this, $_key)) { |
|
205 | - $this->{$_key} = $value; |
|
206 | - } |
|
207 | - } |
|
208 | - // ensure that "required" is set correctly |
|
209 | - $this->set_required( |
|
210 | - $this->_required, isset($input_args['required_validation_error_message']) |
|
211 | - ? $input_args['required_validation_error_message'] |
|
212 | - : null |
|
213 | - ); |
|
214 | - //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
215 | - $this->_display_strategy->_construct_finalize($this); |
|
216 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
217 | - $validation_strategy->_construct_finalize($this); |
|
218 | - } |
|
219 | - if (! $this->_normalization_strategy) { |
|
220 | - $this->_normalization_strategy = new EE_Text_Normalization(); |
|
221 | - } |
|
222 | - $this->_normalization_strategy->_construct_finalize($this); |
|
223 | - //at least we can use the normalization strategy to populate the default |
|
224 | - if (isset($input_args['default'])) { |
|
225 | - $this->set_default($input_args['default']); |
|
226 | - unset($input_args['default']); |
|
227 | - } |
|
228 | - if (! $this->_sensitive_data_removal_strategy) { |
|
229 | - $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
230 | - } |
|
231 | - $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
232 | - parent::__construct($input_args); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * Sets the html_name to its default value, if none was specified in teh constructor. |
|
239 | - * Calculation involves using the name and the parent's html_name |
|
240 | - * |
|
241 | - * @throws \EE_Error |
|
242 | - */ |
|
243 | - protected function _set_default_html_name_if_empty() |
|
244 | - { |
|
245 | - if (! $this->_html_name) { |
|
246 | - $this->_html_name = $this->name(); |
|
247 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
248 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
249 | - } |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param $parent_form_section |
|
257 | - * @param $name |
|
258 | - * @throws \EE_Error |
|
259 | - */ |
|
260 | - public function _construct_finalize($parent_form_section, $name) |
|
261 | - { |
|
262 | - parent::_construct_finalize($parent_form_section, $name); |
|
263 | - if ($this->_html_label === null && $this->_html_label_text === null) { |
|
264 | - $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
265 | - } |
|
266 | - do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
273 | - * |
|
274 | - * @return EE_Display_Strategy_Base |
|
275 | - * @throws EE_Error |
|
276 | - */ |
|
277 | - protected function _get_display_strategy() |
|
278 | - { |
|
279 | - $this->ensure_construct_finalized_called(); |
|
280 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
281 | - throw new EE_Error( |
|
282 | - sprintf( |
|
283 | - __( |
|
284 | - "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
285 | - "event_espresso" |
|
286 | - ), |
|
287 | - $this->html_name(), |
|
288 | - $this->html_id() |
|
289 | - ) |
|
290 | - ); |
|
291 | - } else { |
|
292 | - return $this->_display_strategy; |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * Sets the display strategy. |
|
300 | - * |
|
301 | - * @param EE_Display_Strategy_Base $strategy |
|
302 | - */ |
|
303 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
304 | - { |
|
305 | - $this->_display_strategy = $strategy; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * Sets the sanitization strategy |
|
312 | - * |
|
313 | - * @param EE_Normalization_Strategy_Base $strategy |
|
314 | - */ |
|
315 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
316 | - { |
|
317 | - $this->_normalization_strategy = $strategy; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Gets sensitive_data_removal_strategy |
|
324 | - * |
|
325 | - * @return EE_Sensitive_Data_Removal_Base |
|
326 | - */ |
|
327 | - public function get_sensitive_data_removal_strategy() |
|
328 | - { |
|
329 | - return $this->_sensitive_data_removal_strategy; |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Sets sensitive_data_removal_strategy |
|
336 | - * |
|
337 | - * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
338 | - * @return boolean |
|
339 | - */ |
|
340 | - public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
341 | - { |
|
342 | - $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Gets the display strategy for this input |
|
349 | - * |
|
350 | - * @return EE_Display_Strategy_Base |
|
351 | - */ |
|
352 | - public function get_display_strategy() |
|
353 | - { |
|
354 | - return $this->_display_strategy; |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * Overwrites the display strategy |
|
361 | - * |
|
362 | - * @param EE_Display_Strategy_Base $display_strategy |
|
363 | - */ |
|
364 | - public function set_display_strategy($display_strategy) |
|
365 | - { |
|
366 | - $this->_display_strategy = $display_strategy; |
|
367 | - $this->_display_strategy->_construct_finalize($this); |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Gets the normalization strategy set on this input |
|
374 | - * |
|
375 | - * @return EE_Normalization_Strategy_Base |
|
376 | - */ |
|
377 | - public function get_normalization_strategy() |
|
378 | - { |
|
379 | - return $this->_normalization_strategy; |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * Overwrites the normalization strategy |
|
386 | - * |
|
387 | - * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
388 | - */ |
|
389 | - public function set_normalization_strategy($normalization_strategy) |
|
390 | - { |
|
391 | - $this->_normalization_strategy = $normalization_strategy; |
|
392 | - $this->_normalization_strategy->_construct_finalize($this); |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * Returns all teh validation strategies which apply to this field, numerically indexed |
|
399 | - * |
|
400 | - * @return EE_Validation_Strategy_Base[] |
|
401 | - */ |
|
402 | - public function get_validation_strategies() |
|
403 | - { |
|
404 | - return $this->_validation_strategies; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
411 | - * |
|
412 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
413 | - * @return void |
|
414 | - */ |
|
415 | - protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
416 | - { |
|
417 | - $validation_strategy->_construct_finalize($this); |
|
418 | - $this->_validation_strategies[] = $validation_strategy; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * Adds a new validation strategy onto the form input |
|
425 | - * |
|
426 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
427 | - * @return void |
|
428 | - */ |
|
429 | - public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
430 | - { |
|
431 | - $this->_add_validation_strategy($validation_strategy); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * The classname of the validation strategy to remove |
|
438 | - * |
|
439 | - * @param string $validation_strategy_classname |
|
440 | - */ |
|
441 | - public function remove_validation_strategy($validation_strategy_classname) |
|
442 | - { |
|
443 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
444 | - if ( |
|
445 | - $validation_strategy instanceof $validation_strategy_classname |
|
446 | - || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
447 | - ) { |
|
448 | - unset($this->_validation_strategies[$key]); |
|
449 | - } |
|
450 | - } |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
457 | - * |
|
458 | - * @param array $validation_strategy_classnames |
|
459 | - * @return bool |
|
460 | - */ |
|
461 | - public function has_validation_strategy($validation_strategy_classnames) |
|
462 | - { |
|
463 | - $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
464 | - ? $validation_strategy_classnames |
|
465 | - : array($validation_strategy_classnames); |
|
466 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
467 | - if (in_array($key, $validation_strategy_classnames)) { |
|
468 | - return true; |
|
469 | - } |
|
470 | - } |
|
471 | - return false; |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * Gets the HTML |
|
478 | - * |
|
479 | - * @return string |
|
480 | - */ |
|
481 | - public function get_html() |
|
482 | - { |
|
483 | - return $this->_parent_section->get_html_for_input($this); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * Gets the HTML for the input itself (no label or errors) according to the |
|
490 | - * input's display strategy |
|
491 | - * Makes sure the JS and CSS are enqueued for it |
|
492 | - * |
|
493 | - * @return string |
|
494 | - * @throws \EE_Error |
|
495 | - */ |
|
496 | - public function get_html_for_input() |
|
497 | - { |
|
498 | - return $this->_form_html_filter |
|
499 | - ? $this->_form_html_filter->filterHtml( |
|
500 | - $this->_get_display_strategy()->display(), |
|
501 | - $this |
|
502 | - ) |
|
503 | - : $this->_get_display_strategy()->display(); |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * @return string |
|
510 | - */ |
|
511 | - public function html_other_attributes() |
|
512 | - { |
|
513 | - return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * @param string $html_other_attributes |
|
520 | - */ |
|
521 | - public function set_html_other_attributes($html_other_attributes) |
|
522 | - { |
|
523 | - $this->_html_other_attributes = $html_other_attributes; |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * Gets the HTML for displaying the label for this form input |
|
530 | - * according to the form section's layout strategy |
|
531 | - * |
|
532 | - * @return string |
|
533 | - */ |
|
534 | - public function get_html_for_label() |
|
535 | - { |
|
536 | - return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * Gets the HTML for displaying the errors section for this form input |
|
543 | - * according to the form section's layout strategy |
|
544 | - * |
|
545 | - * @return string |
|
546 | - */ |
|
547 | - public function get_html_for_errors() |
|
548 | - { |
|
549 | - return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * Gets the HTML for displaying the help text for this form input |
|
556 | - * according to the form section's layout strategy |
|
557 | - * |
|
558 | - * @return string |
|
559 | - */ |
|
560 | - public function get_html_for_help() |
|
561 | - { |
|
562 | - return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
569 | - * and returns whether or not the form input's submitted value is value |
|
570 | - * |
|
571 | - * @return boolean |
|
572 | - */ |
|
573 | - protected function _validate() |
|
574 | - { |
|
575 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
576 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
577 | - try { |
|
578 | - $validation_strategy->validate($this->normalized_value()); |
|
579 | - } catch (EE_Validation_Error $e) { |
|
580 | - $this->add_validation_error($e); |
|
581 | - } |
|
582 | - } |
|
583 | - } |
|
584 | - if ($this->get_validation_errors()) { |
|
585 | - return false; |
|
586 | - } else { |
|
587 | - return true; |
|
588 | - } |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
595 | - * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
596 | - * |
|
597 | - * @param string $value |
|
598 | - * @return null|string |
|
599 | - */ |
|
600 | - private function _sanitize($value) |
|
601 | - { |
|
602 | - return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * Picks out the form value that relates to this form input, |
|
609 | - * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
610 | - * Returns whether or not any validation errors occurred |
|
611 | - * |
|
612 | - * @param array $req_data like $_POST |
|
613 | - * @return boolean whether or not there was an error |
|
614 | - * @throws \EE_Error |
|
615 | - */ |
|
616 | - protected function _normalize($req_data) |
|
617 | - { |
|
618 | - //any existing validation errors don't apply so clear them |
|
619 | - $this->_validation_errors = array(); |
|
620 | - try { |
|
621 | - $raw_input = $this->find_form_data_for_this_section($req_data); |
|
622 | - //super simple sanitization for now |
|
623 | - if (is_array($raw_input)) { |
|
624 | - $raw_value = array(); |
|
625 | - foreach ($raw_input as $key => $value) { |
|
626 | - $raw_value[$key] = $this->_sanitize($value); |
|
627 | - } |
|
628 | - $this->_set_raw_value($raw_value); |
|
629 | - } else { |
|
630 | - $this->_set_raw_value($this->_sanitize($raw_input)); |
|
631 | - } |
|
632 | - //we want to mostly leave the input alone in case we need to re-display it to the user |
|
633 | - $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
634 | - } catch (EE_Validation_Error $e) { |
|
635 | - $this->add_validation_error($e); |
|
636 | - } |
|
637 | - } |
|
638 | - |
|
639 | - |
|
640 | - |
|
641 | - /** |
|
642 | - * @return string |
|
643 | - */ |
|
644 | - public function html_name() |
|
645 | - { |
|
646 | - $this->_set_default_html_name_if_empty(); |
|
647 | - return $this->_html_name; |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * @return string |
|
654 | - */ |
|
655 | - public function html_label_id() |
|
656 | - { |
|
657 | - return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * @return string |
|
664 | - */ |
|
665 | - public function html_label_class() |
|
666 | - { |
|
667 | - return $this->_html_label_class; |
|
668 | - } |
|
669 | - |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * @return string |
|
674 | - */ |
|
675 | - public function html_label_style() |
|
676 | - { |
|
677 | - return $this->_html_label_style; |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * @return string |
|
684 | - */ |
|
685 | - public function html_label_text() |
|
686 | - { |
|
687 | - return $this->_html_label_text; |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * @return string |
|
694 | - */ |
|
695 | - public function html_help_text() |
|
696 | - { |
|
697 | - return $this->_html_help_text; |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * @return string |
|
704 | - */ |
|
705 | - public function html_help_class() |
|
706 | - { |
|
707 | - return $this->_html_help_class; |
|
708 | - } |
|
709 | - |
|
710 | - |
|
711 | - |
|
712 | - /** |
|
713 | - * @return string |
|
714 | - */ |
|
715 | - public function html_help_style() |
|
716 | - { |
|
717 | - return $this->_html_style; |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
724 | - * Please note that almost all client code should instead use the normalized_value; |
|
725 | - * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
726 | - * mostly by escaping quotes) |
|
727 | - * Note, we do not store the exact original value sent in the user's request because |
|
728 | - * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
729 | - * in which case, we would have stored the malicious content to our database. |
|
730 | - * |
|
731 | - * @return string |
|
732 | - */ |
|
733 | - public function raw_value() |
|
734 | - { |
|
735 | - return $this->_raw_value; |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * Returns a string safe to usage in form inputs when displaying, because |
|
742 | - * it escapes all html entities |
|
743 | - * |
|
744 | - * @return string |
|
745 | - */ |
|
746 | - public function raw_value_in_form() |
|
747 | - { |
|
748 | - return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * returns the value after it's been sanitized, and then converted into it's proper type |
|
755 | - * in PHP. Eg, a string, an int, an array, |
|
756 | - * |
|
757 | - * @return mixed |
|
758 | - */ |
|
759 | - public function normalized_value() |
|
760 | - { |
|
761 | - return $this->_normalized_value; |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * Returns the normalized value is a presentable way. By default this is just |
|
768 | - * the normalized value by itself, but it can be overridden for when that's not |
|
769 | - * the best thing to display |
|
770 | - * |
|
771 | - * @return string |
|
772 | - */ |
|
773 | - public function pretty_value() |
|
774 | - { |
|
775 | - return $this->_normalized_value; |
|
776 | - } |
|
777 | - |
|
778 | - |
|
779 | - |
|
780 | - /** |
|
781 | - * When generating the JS for the jquery validation rules like<br> |
|
782 | - * <code>$( "#myform" ).validate({ |
|
783 | - * rules: { |
|
784 | - * password: "required", |
|
785 | - * password_again: { |
|
786 | - * equalTo: "#password" |
|
787 | - * } |
|
788 | - * } |
|
789 | - * });</code> |
|
790 | - * if this field had the name 'password_again', it should return |
|
791 | - * <br><code>password_again: { |
|
792 | - * equalTo: "#password" |
|
793 | - * }</code> |
|
794 | - * |
|
795 | - * @return array |
|
796 | - */ |
|
797 | - public function get_jquery_validation_rules() |
|
798 | - { |
|
799 | - $jquery_validation_js = array(); |
|
800 | - $jquery_validation_rules = array(); |
|
801 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
802 | - $jquery_validation_rules = array_replace_recursive( |
|
803 | - $jquery_validation_rules, |
|
804 | - $validation_strategy->get_jquery_validation_rule_array() |
|
805 | - ); |
|
806 | - } |
|
807 | - if (! empty($jquery_validation_rules)) { |
|
808 | - foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
809 | - $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
810 | - } |
|
811 | - } |
|
812 | - return $jquery_validation_js; |
|
813 | - } |
|
814 | - |
|
815 | - |
|
816 | - |
|
817 | - /** |
|
818 | - * Sets the input's default value for use in displaying in the form. Note: value should be |
|
819 | - * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
820 | - * |
|
821 | - * @param mixed $value |
|
822 | - * @return void |
|
823 | - */ |
|
824 | - public function set_default($value) |
|
825 | - { |
|
826 | - $this->_default = $value; |
|
827 | - $this->_set_normalized_value($value); |
|
828 | - $this->_set_raw_value($value); |
|
829 | - } |
|
830 | - |
|
831 | - |
|
832 | - |
|
833 | - /** |
|
834 | - * Sets the normalized value on this input |
|
835 | - * |
|
836 | - * @param mixed $value |
|
837 | - */ |
|
838 | - protected function _set_normalized_value($value) |
|
839 | - { |
|
840 | - $this->_normalized_value = $value; |
|
841 | - } |
|
842 | - |
|
843 | - |
|
844 | - |
|
845 | - /** |
|
846 | - * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
847 | - * |
|
848 | - * @param mixed $value |
|
849 | - */ |
|
850 | - protected function _set_raw_value($value) |
|
851 | - { |
|
852 | - $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
853 | - } |
|
854 | - |
|
855 | - |
|
856 | - |
|
857 | - /** |
|
858 | - * Sets the HTML label text after it has already been defined |
|
859 | - * |
|
860 | - * @param string $label |
|
861 | - * @return void |
|
862 | - */ |
|
863 | - public function set_html_label_text($label) |
|
864 | - { |
|
865 | - $this->_html_label_text = $label; |
|
866 | - } |
|
867 | - |
|
868 | - |
|
869 | - |
|
870 | - /** |
|
871 | - * Sets whether or not this field is required, and adjusts the validation strategy. |
|
872 | - * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
873 | - * please add it as a validation strategy using add_validation_strategy as normal |
|
874 | - * |
|
875 | - * @param boolean $required boolean |
|
876 | - * @param null $required_text |
|
877 | - */ |
|
878 | - public function set_required($required = true, $required_text = null) |
|
879 | - { |
|
880 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
881 | - //whether $required is a string or a boolean, we want to add a required validation strategy |
|
882 | - if ($required) { |
|
883 | - $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
884 | - } else { |
|
885 | - $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
886 | - } |
|
887 | - $this->_required = $required; |
|
888 | - } |
|
889 | - |
|
890 | - |
|
891 | - |
|
892 | - /** |
|
893 | - * Returns whether or not this field is required |
|
894 | - * |
|
895 | - * @return boolean |
|
896 | - */ |
|
897 | - public function required() |
|
898 | - { |
|
899 | - return $this->_required; |
|
900 | - } |
|
901 | - |
|
902 | - |
|
903 | - |
|
904 | - /** |
|
905 | - * @param string $required_css_class |
|
906 | - */ |
|
907 | - public function set_required_css_class($required_css_class) |
|
908 | - { |
|
909 | - $this->_required_css_class = $required_css_class; |
|
910 | - } |
|
911 | - |
|
912 | - |
|
913 | - |
|
914 | - /** |
|
915 | - * @return string |
|
916 | - */ |
|
917 | - public function required_css_class() |
|
918 | - { |
|
919 | - return $this->_required_css_class; |
|
920 | - } |
|
921 | - |
|
922 | - |
|
923 | - |
|
924 | - /** |
|
925 | - * @param bool $add_required |
|
926 | - * @return string |
|
927 | - */ |
|
928 | - public function html_class($add_required = false) |
|
929 | - { |
|
930 | - return $add_required && $this->required() |
|
931 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
932 | - : $this->_html_class; |
|
933 | - } |
|
934 | - |
|
935 | - |
|
936 | - /** |
|
937 | - * Sets the help text, in case |
|
938 | - * |
|
939 | - * @param string $text |
|
940 | - */ |
|
941 | - public function set_html_help_text($text) |
|
942 | - { |
|
943 | - $this->_html_help_text = $text; |
|
944 | - } |
|
945 | - |
|
946 | - |
|
947 | - |
|
948 | - /** |
|
949 | - * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
950 | - * input. If there is any kind of sensitive data removal on this input, we clear |
|
951 | - * out the raw value completely |
|
952 | - * |
|
953 | - * @return void |
|
954 | - */ |
|
955 | - public function clean_sensitive_data() |
|
956 | - { |
|
957 | - //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
958 | - //if we need more logic than this we'll make a strategy for it |
|
959 | - if ($this->_sensitive_data_removal_strategy |
|
960 | - && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
961 | - ) { |
|
962 | - $this->_set_raw_value(null); |
|
963 | - } |
|
964 | - //and clean the normalized value according to the appropriate strategy |
|
965 | - $this->_set_normalized_value( |
|
966 | - $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
967 | - $this->_normalized_value |
|
968 | - ) |
|
969 | - ); |
|
970 | - } |
|
971 | - |
|
972 | - |
|
973 | - |
|
974 | - /** |
|
975 | - * @param bool $primary |
|
976 | - * @param string $button_size |
|
977 | - * @param string $other_attributes |
|
978 | - */ |
|
979 | - public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
980 | - { |
|
981 | - $button_css_attributes = 'button'; |
|
982 | - $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
983 | - switch ($button_size) { |
|
984 | - case 'xs' : |
|
985 | - case 'extra-small' : |
|
986 | - $button_css_attributes .= ' button-xs'; |
|
987 | - break; |
|
988 | - case 'sm' : |
|
989 | - case 'small' : |
|
990 | - $button_css_attributes .= ' button-sm'; |
|
991 | - break; |
|
992 | - case 'lg' : |
|
993 | - case 'large' : |
|
994 | - $button_css_attributes .= ' button-lg'; |
|
995 | - break; |
|
996 | - case 'block' : |
|
997 | - $button_css_attributes .= ' button-block'; |
|
998 | - break; |
|
999 | - case 'md' : |
|
1000 | - case 'medium' : |
|
1001 | - default : |
|
1002 | - $button_css_attributes .= ''; |
|
1003 | - } |
|
1004 | - $this->_button_css_attributes .= ! empty($other_attributes) |
|
1005 | - ? $button_css_attributes . ' ' . $other_attributes |
|
1006 | - : $button_css_attributes; |
|
1007 | - } |
|
1008 | - |
|
1009 | - |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * @return string |
|
1013 | - */ |
|
1014 | - public function button_css_attributes() |
|
1015 | - { |
|
1016 | - if (empty($this->_button_css_attributes)) { |
|
1017 | - $this->set_button_css_attributes(); |
|
1018 | - } |
|
1019 | - return $this->_button_css_attributes; |
|
1020 | - } |
|
1021 | - |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * find_form_data_for_this_section |
|
1026 | - * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1027 | - * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1028 | - * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1']. |
|
1029 | - * (If that doesn't exist, we also check for this subsection's name |
|
1030 | - * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].) |
|
1031 | - * This function finds its value in the form. |
|
1032 | - * |
|
1033 | - * @param array $req_data |
|
1034 | - * @return mixed whatever the raw value of this form section is in the request data |
|
1035 | - * @throws \EE_Error |
|
1036 | - */ |
|
1037 | - public function find_form_data_for_this_section($req_data) |
|
1038 | - { |
|
1039 | - // break up the html name by "[]" |
|
1040 | - if (strpos($this->html_name(), '[') !== false) { |
|
1041 | - $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1042 | - } else { |
|
1043 | - $before_any_brackets = $this->html_name(); |
|
1044 | - } |
|
1045 | - // grab all of the segments |
|
1046 | - preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1047 | - if (isset($matches[1]) && is_array($matches[1])) { |
|
1048 | - $name_parts = $matches[1]; |
|
1049 | - array_unshift($name_parts, $before_any_brackets); |
|
1050 | - } else { |
|
1051 | - $name_parts = array($before_any_brackets); |
|
1052 | - } |
|
1053 | - // now get the value for the input |
|
1054 | - $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
|
1055 | - // check if this thing's name is at the TOP level of the request data |
|
1056 | - if ($value === null && isset($req_data[$this->name()])) { |
|
1057 | - $value = $req_data[$this->name()]; |
|
1058 | - } |
|
1059 | - return $value; |
|
1060 | - } |
|
1061 | - |
|
1062 | - |
|
1063 | - |
|
1064 | - /** |
|
1065 | - * @param array $html_name_parts |
|
1066 | - * @param array $req_data |
|
1067 | - * @return array | NULL |
|
1068 | - */ |
|
1069 | - public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) |
|
1070 | - { |
|
1071 | - $first_part_to_consider = array_shift($html_name_parts); |
|
1072 | - if (isset($req_data[$first_part_to_consider])) { |
|
1073 | - if (empty($html_name_parts)) { |
|
1074 | - return $req_data[$first_part_to_consider]; |
|
1075 | - } else { |
|
1076 | - return $this->_find_form_data_for_this_section_using_name_parts( |
|
1077 | - $html_name_parts, |
|
1078 | - $req_data[$first_part_to_consider] |
|
1079 | - ); |
|
1080 | - } |
|
1081 | - } else { |
|
1082 | - return null; |
|
1083 | - } |
|
1084 | - } |
|
1085 | - |
|
1086 | - |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * Checks if this form input's data is in the request data |
|
1090 | - * |
|
1091 | - * @param array $req_data like $_POST |
|
1092 | - * @return boolean |
|
1093 | - * @throws \EE_Error |
|
1094 | - */ |
|
1095 | - public function form_data_present_in($req_data = null) |
|
1096 | - { |
|
1097 | - if ($req_data === null) { |
|
1098 | - $req_data = $_POST; |
|
1099 | - } |
|
1100 | - $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1101 | - if ($checked_value !== null) { |
|
1102 | - return true; |
|
1103 | - } else { |
|
1104 | - return false; |
|
1105 | - } |
|
1106 | - } |
|
1107 | - |
|
1108 | - |
|
1109 | - |
|
1110 | - /** |
|
1111 | - * Overrides parent to add js data from validation and display strategies |
|
1112 | - * |
|
1113 | - * @param array $form_other_js_data |
|
1114 | - * @return array |
|
1115 | - */ |
|
1116 | - public function get_other_js_data($form_other_js_data = array()) |
|
1117 | - { |
|
1118 | - $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1119 | - return $form_other_js_data; |
|
1120 | - } |
|
1121 | - |
|
1122 | - |
|
1123 | - |
|
1124 | - /** |
|
1125 | - * Gets other JS data for localization from this input's strategies, like |
|
1126 | - * the validation strategies and the display strategy |
|
1127 | - * |
|
1128 | - * @param array $form_other_js_data |
|
1129 | - * @return array |
|
1130 | - */ |
|
1131 | - public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
1132 | - { |
|
1133 | - $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1134 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1135 | - $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1136 | - } |
|
1137 | - return $form_other_js_data; |
|
1138 | - } |
|
1139 | - |
|
1140 | - |
|
1141 | - |
|
1142 | - /** |
|
1143 | - * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1144 | - * |
|
1145 | - * @return void |
|
1146 | - */ |
|
1147 | - public function enqueue_js() |
|
1148 | - { |
|
1149 | - //ask our display strategy and validation strategies if they have js to enqueue |
|
1150 | - $this->enqueue_js_from_strategies(); |
|
1151 | - } |
|
1152 | - |
|
1153 | - |
|
1154 | - |
|
1155 | - /** |
|
1156 | - * Tells strategies when its ok to enqueue their js and css |
|
1157 | - * |
|
1158 | - * @return void |
|
1159 | - */ |
|
1160 | - public function enqueue_js_from_strategies() |
|
1161 | - { |
|
1162 | - $this->get_display_strategy()->enqueue_js(); |
|
1163 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1164 | - $validation_strategy->enqueue_js(); |
|
1165 | - } |
|
1166 | - } |
|
1167 | - |
|
1168 | - |
|
1169 | - |
|
1170 | - /** |
|
1171 | - * Gets the default value set on the input (not the current value, which may have been |
|
1172 | - * changed because of a form submission). If no default was set, this us null. |
|
1173 | - * @return mixed |
|
1174 | - */ |
|
1175 | - public function get_default() |
|
1176 | - { |
|
1177 | - return $this->_default; |
|
1178 | - } |
|
19 | + /** |
|
20 | + * the input's name attribute |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_html_name; |
|
25 | + |
|
26 | + /** |
|
27 | + * id for the html label tag |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_html_label_id; |
|
32 | + |
|
33 | + /** |
|
34 | + * class for teh html label tag |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $_html_label_class; |
|
39 | + |
|
40 | + /** |
|
41 | + * any additional html attributes that you may want to add |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + protected $_html_other_attributes; |
|
46 | + |
|
47 | + /** |
|
48 | + * style for teh html label tag |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_html_label_style; |
|
53 | + |
|
54 | + /** |
|
55 | + * text to be placed in the html label |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + protected $_html_label_text; |
|
60 | + |
|
61 | + /** |
|
62 | + * the full html label. If used, all other html_label_* properties are invalid |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + protected $_html_label; |
|
67 | + |
|
68 | + /** |
|
69 | + * HTML to use for help text (normally placed below form input), in a span which normally |
|
70 | + * has a class of 'description' |
|
71 | + * |
|
72 | + * @var string |
|
73 | + */ |
|
74 | + protected $_html_help_text; |
|
75 | + |
|
76 | + /** |
|
77 | + * CSS classes for displaying the help span |
|
78 | + * |
|
79 | + * @var string |
|
80 | + */ |
|
81 | + protected $_html_help_class = 'description'; |
|
82 | + |
|
83 | + /** |
|
84 | + * CSS to put in the style attribute on the help span |
|
85 | + * |
|
86 | + * @var string |
|
87 | + */ |
|
88 | + protected $_html_help_style; |
|
89 | + |
|
90 | + /** |
|
91 | + * Stores whether or not this input's response is required. |
|
92 | + * Because certain styling elements may also want to know that this |
|
93 | + * input is required etc. |
|
94 | + * |
|
95 | + * @var boolean |
|
96 | + */ |
|
97 | + protected $_required; |
|
98 | + |
|
99 | + /** |
|
100 | + * css class added to required inputs |
|
101 | + * |
|
102 | + * @var string |
|
103 | + */ |
|
104 | + protected $_required_css_class = 'ee-required'; |
|
105 | + |
|
106 | + /** |
|
107 | + * css styles applied to button type inputs |
|
108 | + * |
|
109 | + * @var string |
|
110 | + */ |
|
111 | + protected $_button_css_attributes; |
|
112 | + |
|
113 | + /** |
|
114 | + * The raw data submitted for this, like in the $_POST super global. |
|
115 | + * Generally unsafe for usage in client code |
|
116 | + * |
|
117 | + * @var mixed string or array |
|
118 | + */ |
|
119 | + protected $_raw_value; |
|
120 | + |
|
121 | + /** |
|
122 | + * Value normalized according to the input's normalization strategy. |
|
123 | + * The normalization strategy dictates whether this is a string, int, float, |
|
124 | + * boolean, or array of any of those. |
|
125 | + * |
|
126 | + * @var mixed |
|
127 | + */ |
|
128 | + protected $_normalized_value; |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Normalized default value either initially set on the input, or provided by calling |
|
133 | + * set_default(). |
|
134 | + * @var mixed |
|
135 | + */ |
|
136 | + protected $_default; |
|
137 | + |
|
138 | + /** |
|
139 | + * Strategy used for displaying this field. |
|
140 | + * Child classes must use _get_display_strategy to access it. |
|
141 | + * |
|
142 | + * @var EE_Display_Strategy_Base |
|
143 | + */ |
|
144 | + private $_display_strategy; |
|
145 | + |
|
146 | + /** |
|
147 | + * Gets all the validation strategies used on this field |
|
148 | + * |
|
149 | + * @var EE_Validation_Strategy_Base[] |
|
150 | + */ |
|
151 | + private $_validation_strategies = array(); |
|
152 | + |
|
153 | + /** |
|
154 | + * The normalization strategy for this field |
|
155 | + * |
|
156 | + * @var EE_Normalization_Strategy_Base |
|
157 | + */ |
|
158 | + private $_normalization_strategy; |
|
159 | + |
|
160 | + /** |
|
161 | + * Strategy for removing sensitive data after we're done with the form input |
|
162 | + * |
|
163 | + * @var EE_Sensitive_Data_Removal_Base |
|
164 | + */ |
|
165 | + protected $_sensitive_data_removal_strategy; |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param array $input_args { |
|
171 | + * @type string $html_name the html name for the input |
|
172 | + * @type string $html_label_id the id attribute to give to the html label tag |
|
173 | + * @type string $html_label_class the class attribute to give to the html label tag |
|
174 | + * @type string $html_label_style the style attribute to give ot teh label tag |
|
175 | + * @type string $html_label_text the text to put in the label tag |
|
176 | + * @type string $html_label the full html label. If used, |
|
177 | + * all other html_label_* args are invalid |
|
178 | + * @type string $html_help_text text to put in help element |
|
179 | + * @type string $html_help_style style attribute to give to teh help element |
|
180 | + * @type string $html_help_class class attribute to give to the help element |
|
181 | + * @type string $default default value NORMALIZED (eg, if providing the default |
|
182 | + * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
183 | + * @type EE_Display_Strategy_Base $display strategy |
|
184 | + * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
185 | + * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
186 | + * } |
|
187 | + */ |
|
188 | + public function __construct($input_args = array()) |
|
189 | + { |
|
190 | + $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
191 | + // the following properties must be cast as arrays |
|
192 | + if (isset($input_args['validation_strategies'])) { |
|
193 | + foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
194 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
195 | + $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
196 | + } |
|
197 | + } |
|
198 | + unset($input_args['validation_strategies']); |
|
199 | + } |
|
200 | + // loop thru incoming options |
|
201 | + foreach ($input_args as $key => $value) { |
|
202 | + // add underscore to $key to match property names |
|
203 | + $_key = '_' . $key; |
|
204 | + if (property_exists($this, $_key)) { |
|
205 | + $this->{$_key} = $value; |
|
206 | + } |
|
207 | + } |
|
208 | + // ensure that "required" is set correctly |
|
209 | + $this->set_required( |
|
210 | + $this->_required, isset($input_args['required_validation_error_message']) |
|
211 | + ? $input_args['required_validation_error_message'] |
|
212 | + : null |
|
213 | + ); |
|
214 | + //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
215 | + $this->_display_strategy->_construct_finalize($this); |
|
216 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
217 | + $validation_strategy->_construct_finalize($this); |
|
218 | + } |
|
219 | + if (! $this->_normalization_strategy) { |
|
220 | + $this->_normalization_strategy = new EE_Text_Normalization(); |
|
221 | + } |
|
222 | + $this->_normalization_strategy->_construct_finalize($this); |
|
223 | + //at least we can use the normalization strategy to populate the default |
|
224 | + if (isset($input_args['default'])) { |
|
225 | + $this->set_default($input_args['default']); |
|
226 | + unset($input_args['default']); |
|
227 | + } |
|
228 | + if (! $this->_sensitive_data_removal_strategy) { |
|
229 | + $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
230 | + } |
|
231 | + $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
232 | + parent::__construct($input_args); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * Sets the html_name to its default value, if none was specified in teh constructor. |
|
239 | + * Calculation involves using the name and the parent's html_name |
|
240 | + * |
|
241 | + * @throws \EE_Error |
|
242 | + */ |
|
243 | + protected function _set_default_html_name_if_empty() |
|
244 | + { |
|
245 | + if (! $this->_html_name) { |
|
246 | + $this->_html_name = $this->name(); |
|
247 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
248 | + $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
249 | + } |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param $parent_form_section |
|
257 | + * @param $name |
|
258 | + * @throws \EE_Error |
|
259 | + */ |
|
260 | + public function _construct_finalize($parent_form_section, $name) |
|
261 | + { |
|
262 | + parent::_construct_finalize($parent_form_section, $name); |
|
263 | + if ($this->_html_label === null && $this->_html_label_text === null) { |
|
264 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
265 | + } |
|
266 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
273 | + * |
|
274 | + * @return EE_Display_Strategy_Base |
|
275 | + * @throws EE_Error |
|
276 | + */ |
|
277 | + protected function _get_display_strategy() |
|
278 | + { |
|
279 | + $this->ensure_construct_finalized_called(); |
|
280 | + if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
281 | + throw new EE_Error( |
|
282 | + sprintf( |
|
283 | + __( |
|
284 | + "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
285 | + "event_espresso" |
|
286 | + ), |
|
287 | + $this->html_name(), |
|
288 | + $this->html_id() |
|
289 | + ) |
|
290 | + ); |
|
291 | + } else { |
|
292 | + return $this->_display_strategy; |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * Sets the display strategy. |
|
300 | + * |
|
301 | + * @param EE_Display_Strategy_Base $strategy |
|
302 | + */ |
|
303 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
304 | + { |
|
305 | + $this->_display_strategy = $strategy; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * Sets the sanitization strategy |
|
312 | + * |
|
313 | + * @param EE_Normalization_Strategy_Base $strategy |
|
314 | + */ |
|
315 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
316 | + { |
|
317 | + $this->_normalization_strategy = $strategy; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Gets sensitive_data_removal_strategy |
|
324 | + * |
|
325 | + * @return EE_Sensitive_Data_Removal_Base |
|
326 | + */ |
|
327 | + public function get_sensitive_data_removal_strategy() |
|
328 | + { |
|
329 | + return $this->_sensitive_data_removal_strategy; |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Sets sensitive_data_removal_strategy |
|
336 | + * |
|
337 | + * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
338 | + * @return boolean |
|
339 | + */ |
|
340 | + public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
341 | + { |
|
342 | + $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Gets the display strategy for this input |
|
349 | + * |
|
350 | + * @return EE_Display_Strategy_Base |
|
351 | + */ |
|
352 | + public function get_display_strategy() |
|
353 | + { |
|
354 | + return $this->_display_strategy; |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * Overwrites the display strategy |
|
361 | + * |
|
362 | + * @param EE_Display_Strategy_Base $display_strategy |
|
363 | + */ |
|
364 | + public function set_display_strategy($display_strategy) |
|
365 | + { |
|
366 | + $this->_display_strategy = $display_strategy; |
|
367 | + $this->_display_strategy->_construct_finalize($this); |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Gets the normalization strategy set on this input |
|
374 | + * |
|
375 | + * @return EE_Normalization_Strategy_Base |
|
376 | + */ |
|
377 | + public function get_normalization_strategy() |
|
378 | + { |
|
379 | + return $this->_normalization_strategy; |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * Overwrites the normalization strategy |
|
386 | + * |
|
387 | + * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
388 | + */ |
|
389 | + public function set_normalization_strategy($normalization_strategy) |
|
390 | + { |
|
391 | + $this->_normalization_strategy = $normalization_strategy; |
|
392 | + $this->_normalization_strategy->_construct_finalize($this); |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * Returns all teh validation strategies which apply to this field, numerically indexed |
|
399 | + * |
|
400 | + * @return EE_Validation_Strategy_Base[] |
|
401 | + */ |
|
402 | + public function get_validation_strategies() |
|
403 | + { |
|
404 | + return $this->_validation_strategies; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
411 | + * |
|
412 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
413 | + * @return void |
|
414 | + */ |
|
415 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
416 | + { |
|
417 | + $validation_strategy->_construct_finalize($this); |
|
418 | + $this->_validation_strategies[] = $validation_strategy; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * Adds a new validation strategy onto the form input |
|
425 | + * |
|
426 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
427 | + * @return void |
|
428 | + */ |
|
429 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
430 | + { |
|
431 | + $this->_add_validation_strategy($validation_strategy); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * The classname of the validation strategy to remove |
|
438 | + * |
|
439 | + * @param string $validation_strategy_classname |
|
440 | + */ |
|
441 | + public function remove_validation_strategy($validation_strategy_classname) |
|
442 | + { |
|
443 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
444 | + if ( |
|
445 | + $validation_strategy instanceof $validation_strategy_classname |
|
446 | + || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
447 | + ) { |
|
448 | + unset($this->_validation_strategies[$key]); |
|
449 | + } |
|
450 | + } |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
457 | + * |
|
458 | + * @param array $validation_strategy_classnames |
|
459 | + * @return bool |
|
460 | + */ |
|
461 | + public function has_validation_strategy($validation_strategy_classnames) |
|
462 | + { |
|
463 | + $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
464 | + ? $validation_strategy_classnames |
|
465 | + : array($validation_strategy_classnames); |
|
466 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
467 | + if (in_array($key, $validation_strategy_classnames)) { |
|
468 | + return true; |
|
469 | + } |
|
470 | + } |
|
471 | + return false; |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * Gets the HTML |
|
478 | + * |
|
479 | + * @return string |
|
480 | + */ |
|
481 | + public function get_html() |
|
482 | + { |
|
483 | + return $this->_parent_section->get_html_for_input($this); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * Gets the HTML for the input itself (no label or errors) according to the |
|
490 | + * input's display strategy |
|
491 | + * Makes sure the JS and CSS are enqueued for it |
|
492 | + * |
|
493 | + * @return string |
|
494 | + * @throws \EE_Error |
|
495 | + */ |
|
496 | + public function get_html_for_input() |
|
497 | + { |
|
498 | + return $this->_form_html_filter |
|
499 | + ? $this->_form_html_filter->filterHtml( |
|
500 | + $this->_get_display_strategy()->display(), |
|
501 | + $this |
|
502 | + ) |
|
503 | + : $this->_get_display_strategy()->display(); |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * @return string |
|
510 | + */ |
|
511 | + public function html_other_attributes() |
|
512 | + { |
|
513 | + return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * @param string $html_other_attributes |
|
520 | + */ |
|
521 | + public function set_html_other_attributes($html_other_attributes) |
|
522 | + { |
|
523 | + $this->_html_other_attributes = $html_other_attributes; |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * Gets the HTML for displaying the label for this form input |
|
530 | + * according to the form section's layout strategy |
|
531 | + * |
|
532 | + * @return string |
|
533 | + */ |
|
534 | + public function get_html_for_label() |
|
535 | + { |
|
536 | + return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * Gets the HTML for displaying the errors section for this form input |
|
543 | + * according to the form section's layout strategy |
|
544 | + * |
|
545 | + * @return string |
|
546 | + */ |
|
547 | + public function get_html_for_errors() |
|
548 | + { |
|
549 | + return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * Gets the HTML for displaying the help text for this form input |
|
556 | + * according to the form section's layout strategy |
|
557 | + * |
|
558 | + * @return string |
|
559 | + */ |
|
560 | + public function get_html_for_help() |
|
561 | + { |
|
562 | + return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
569 | + * and returns whether or not the form input's submitted value is value |
|
570 | + * |
|
571 | + * @return boolean |
|
572 | + */ |
|
573 | + protected function _validate() |
|
574 | + { |
|
575 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
576 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
577 | + try { |
|
578 | + $validation_strategy->validate($this->normalized_value()); |
|
579 | + } catch (EE_Validation_Error $e) { |
|
580 | + $this->add_validation_error($e); |
|
581 | + } |
|
582 | + } |
|
583 | + } |
|
584 | + if ($this->get_validation_errors()) { |
|
585 | + return false; |
|
586 | + } else { |
|
587 | + return true; |
|
588 | + } |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
595 | + * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
596 | + * |
|
597 | + * @param string $value |
|
598 | + * @return null|string |
|
599 | + */ |
|
600 | + private function _sanitize($value) |
|
601 | + { |
|
602 | + return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * Picks out the form value that relates to this form input, |
|
609 | + * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
610 | + * Returns whether or not any validation errors occurred |
|
611 | + * |
|
612 | + * @param array $req_data like $_POST |
|
613 | + * @return boolean whether or not there was an error |
|
614 | + * @throws \EE_Error |
|
615 | + */ |
|
616 | + protected function _normalize($req_data) |
|
617 | + { |
|
618 | + //any existing validation errors don't apply so clear them |
|
619 | + $this->_validation_errors = array(); |
|
620 | + try { |
|
621 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
622 | + //super simple sanitization for now |
|
623 | + if (is_array($raw_input)) { |
|
624 | + $raw_value = array(); |
|
625 | + foreach ($raw_input as $key => $value) { |
|
626 | + $raw_value[$key] = $this->_sanitize($value); |
|
627 | + } |
|
628 | + $this->_set_raw_value($raw_value); |
|
629 | + } else { |
|
630 | + $this->_set_raw_value($this->_sanitize($raw_input)); |
|
631 | + } |
|
632 | + //we want to mostly leave the input alone in case we need to re-display it to the user |
|
633 | + $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
634 | + } catch (EE_Validation_Error $e) { |
|
635 | + $this->add_validation_error($e); |
|
636 | + } |
|
637 | + } |
|
638 | + |
|
639 | + |
|
640 | + |
|
641 | + /** |
|
642 | + * @return string |
|
643 | + */ |
|
644 | + public function html_name() |
|
645 | + { |
|
646 | + $this->_set_default_html_name_if_empty(); |
|
647 | + return $this->_html_name; |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * @return string |
|
654 | + */ |
|
655 | + public function html_label_id() |
|
656 | + { |
|
657 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * @return string |
|
664 | + */ |
|
665 | + public function html_label_class() |
|
666 | + { |
|
667 | + return $this->_html_label_class; |
|
668 | + } |
|
669 | + |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * @return string |
|
674 | + */ |
|
675 | + public function html_label_style() |
|
676 | + { |
|
677 | + return $this->_html_label_style; |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * @return string |
|
684 | + */ |
|
685 | + public function html_label_text() |
|
686 | + { |
|
687 | + return $this->_html_label_text; |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * @return string |
|
694 | + */ |
|
695 | + public function html_help_text() |
|
696 | + { |
|
697 | + return $this->_html_help_text; |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * @return string |
|
704 | + */ |
|
705 | + public function html_help_class() |
|
706 | + { |
|
707 | + return $this->_html_help_class; |
|
708 | + } |
|
709 | + |
|
710 | + |
|
711 | + |
|
712 | + /** |
|
713 | + * @return string |
|
714 | + */ |
|
715 | + public function html_help_style() |
|
716 | + { |
|
717 | + return $this->_html_style; |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
724 | + * Please note that almost all client code should instead use the normalized_value; |
|
725 | + * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
726 | + * mostly by escaping quotes) |
|
727 | + * Note, we do not store the exact original value sent in the user's request because |
|
728 | + * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
729 | + * in which case, we would have stored the malicious content to our database. |
|
730 | + * |
|
731 | + * @return string |
|
732 | + */ |
|
733 | + public function raw_value() |
|
734 | + { |
|
735 | + return $this->_raw_value; |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * Returns a string safe to usage in form inputs when displaying, because |
|
742 | + * it escapes all html entities |
|
743 | + * |
|
744 | + * @return string |
|
745 | + */ |
|
746 | + public function raw_value_in_form() |
|
747 | + { |
|
748 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * returns the value after it's been sanitized, and then converted into it's proper type |
|
755 | + * in PHP. Eg, a string, an int, an array, |
|
756 | + * |
|
757 | + * @return mixed |
|
758 | + */ |
|
759 | + public function normalized_value() |
|
760 | + { |
|
761 | + return $this->_normalized_value; |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * Returns the normalized value is a presentable way. By default this is just |
|
768 | + * the normalized value by itself, but it can be overridden for when that's not |
|
769 | + * the best thing to display |
|
770 | + * |
|
771 | + * @return string |
|
772 | + */ |
|
773 | + public function pretty_value() |
|
774 | + { |
|
775 | + return $this->_normalized_value; |
|
776 | + } |
|
777 | + |
|
778 | + |
|
779 | + |
|
780 | + /** |
|
781 | + * When generating the JS for the jquery validation rules like<br> |
|
782 | + * <code>$( "#myform" ).validate({ |
|
783 | + * rules: { |
|
784 | + * password: "required", |
|
785 | + * password_again: { |
|
786 | + * equalTo: "#password" |
|
787 | + * } |
|
788 | + * } |
|
789 | + * });</code> |
|
790 | + * if this field had the name 'password_again', it should return |
|
791 | + * <br><code>password_again: { |
|
792 | + * equalTo: "#password" |
|
793 | + * }</code> |
|
794 | + * |
|
795 | + * @return array |
|
796 | + */ |
|
797 | + public function get_jquery_validation_rules() |
|
798 | + { |
|
799 | + $jquery_validation_js = array(); |
|
800 | + $jquery_validation_rules = array(); |
|
801 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
802 | + $jquery_validation_rules = array_replace_recursive( |
|
803 | + $jquery_validation_rules, |
|
804 | + $validation_strategy->get_jquery_validation_rule_array() |
|
805 | + ); |
|
806 | + } |
|
807 | + if (! empty($jquery_validation_rules)) { |
|
808 | + foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
809 | + $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
810 | + } |
|
811 | + } |
|
812 | + return $jquery_validation_js; |
|
813 | + } |
|
814 | + |
|
815 | + |
|
816 | + |
|
817 | + /** |
|
818 | + * Sets the input's default value for use in displaying in the form. Note: value should be |
|
819 | + * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
820 | + * |
|
821 | + * @param mixed $value |
|
822 | + * @return void |
|
823 | + */ |
|
824 | + public function set_default($value) |
|
825 | + { |
|
826 | + $this->_default = $value; |
|
827 | + $this->_set_normalized_value($value); |
|
828 | + $this->_set_raw_value($value); |
|
829 | + } |
|
830 | + |
|
831 | + |
|
832 | + |
|
833 | + /** |
|
834 | + * Sets the normalized value on this input |
|
835 | + * |
|
836 | + * @param mixed $value |
|
837 | + */ |
|
838 | + protected function _set_normalized_value($value) |
|
839 | + { |
|
840 | + $this->_normalized_value = $value; |
|
841 | + } |
|
842 | + |
|
843 | + |
|
844 | + |
|
845 | + /** |
|
846 | + * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
847 | + * |
|
848 | + * @param mixed $value |
|
849 | + */ |
|
850 | + protected function _set_raw_value($value) |
|
851 | + { |
|
852 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
853 | + } |
|
854 | + |
|
855 | + |
|
856 | + |
|
857 | + /** |
|
858 | + * Sets the HTML label text after it has already been defined |
|
859 | + * |
|
860 | + * @param string $label |
|
861 | + * @return void |
|
862 | + */ |
|
863 | + public function set_html_label_text($label) |
|
864 | + { |
|
865 | + $this->_html_label_text = $label; |
|
866 | + } |
|
867 | + |
|
868 | + |
|
869 | + |
|
870 | + /** |
|
871 | + * Sets whether or not this field is required, and adjusts the validation strategy. |
|
872 | + * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
873 | + * please add it as a validation strategy using add_validation_strategy as normal |
|
874 | + * |
|
875 | + * @param boolean $required boolean |
|
876 | + * @param null $required_text |
|
877 | + */ |
|
878 | + public function set_required($required = true, $required_text = null) |
|
879 | + { |
|
880 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
881 | + //whether $required is a string or a boolean, we want to add a required validation strategy |
|
882 | + if ($required) { |
|
883 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
884 | + } else { |
|
885 | + $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
886 | + } |
|
887 | + $this->_required = $required; |
|
888 | + } |
|
889 | + |
|
890 | + |
|
891 | + |
|
892 | + /** |
|
893 | + * Returns whether or not this field is required |
|
894 | + * |
|
895 | + * @return boolean |
|
896 | + */ |
|
897 | + public function required() |
|
898 | + { |
|
899 | + return $this->_required; |
|
900 | + } |
|
901 | + |
|
902 | + |
|
903 | + |
|
904 | + /** |
|
905 | + * @param string $required_css_class |
|
906 | + */ |
|
907 | + public function set_required_css_class($required_css_class) |
|
908 | + { |
|
909 | + $this->_required_css_class = $required_css_class; |
|
910 | + } |
|
911 | + |
|
912 | + |
|
913 | + |
|
914 | + /** |
|
915 | + * @return string |
|
916 | + */ |
|
917 | + public function required_css_class() |
|
918 | + { |
|
919 | + return $this->_required_css_class; |
|
920 | + } |
|
921 | + |
|
922 | + |
|
923 | + |
|
924 | + /** |
|
925 | + * @param bool $add_required |
|
926 | + * @return string |
|
927 | + */ |
|
928 | + public function html_class($add_required = false) |
|
929 | + { |
|
930 | + return $add_required && $this->required() |
|
931 | + ? $this->required_css_class() . ' ' . $this->_html_class |
|
932 | + : $this->_html_class; |
|
933 | + } |
|
934 | + |
|
935 | + |
|
936 | + /** |
|
937 | + * Sets the help text, in case |
|
938 | + * |
|
939 | + * @param string $text |
|
940 | + */ |
|
941 | + public function set_html_help_text($text) |
|
942 | + { |
|
943 | + $this->_html_help_text = $text; |
|
944 | + } |
|
945 | + |
|
946 | + |
|
947 | + |
|
948 | + /** |
|
949 | + * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
950 | + * input. If there is any kind of sensitive data removal on this input, we clear |
|
951 | + * out the raw value completely |
|
952 | + * |
|
953 | + * @return void |
|
954 | + */ |
|
955 | + public function clean_sensitive_data() |
|
956 | + { |
|
957 | + //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
958 | + //if we need more logic than this we'll make a strategy for it |
|
959 | + if ($this->_sensitive_data_removal_strategy |
|
960 | + && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
961 | + ) { |
|
962 | + $this->_set_raw_value(null); |
|
963 | + } |
|
964 | + //and clean the normalized value according to the appropriate strategy |
|
965 | + $this->_set_normalized_value( |
|
966 | + $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
967 | + $this->_normalized_value |
|
968 | + ) |
|
969 | + ); |
|
970 | + } |
|
971 | + |
|
972 | + |
|
973 | + |
|
974 | + /** |
|
975 | + * @param bool $primary |
|
976 | + * @param string $button_size |
|
977 | + * @param string $other_attributes |
|
978 | + */ |
|
979 | + public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
980 | + { |
|
981 | + $button_css_attributes = 'button'; |
|
982 | + $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
983 | + switch ($button_size) { |
|
984 | + case 'xs' : |
|
985 | + case 'extra-small' : |
|
986 | + $button_css_attributes .= ' button-xs'; |
|
987 | + break; |
|
988 | + case 'sm' : |
|
989 | + case 'small' : |
|
990 | + $button_css_attributes .= ' button-sm'; |
|
991 | + break; |
|
992 | + case 'lg' : |
|
993 | + case 'large' : |
|
994 | + $button_css_attributes .= ' button-lg'; |
|
995 | + break; |
|
996 | + case 'block' : |
|
997 | + $button_css_attributes .= ' button-block'; |
|
998 | + break; |
|
999 | + case 'md' : |
|
1000 | + case 'medium' : |
|
1001 | + default : |
|
1002 | + $button_css_attributes .= ''; |
|
1003 | + } |
|
1004 | + $this->_button_css_attributes .= ! empty($other_attributes) |
|
1005 | + ? $button_css_attributes . ' ' . $other_attributes |
|
1006 | + : $button_css_attributes; |
|
1007 | + } |
|
1008 | + |
|
1009 | + |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * @return string |
|
1013 | + */ |
|
1014 | + public function button_css_attributes() |
|
1015 | + { |
|
1016 | + if (empty($this->_button_css_attributes)) { |
|
1017 | + $this->set_button_css_attributes(); |
|
1018 | + } |
|
1019 | + return $this->_button_css_attributes; |
|
1020 | + } |
|
1021 | + |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * find_form_data_for_this_section |
|
1026 | + * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1027 | + * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1028 | + * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1']. |
|
1029 | + * (If that doesn't exist, we also check for this subsection's name |
|
1030 | + * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].) |
|
1031 | + * This function finds its value in the form. |
|
1032 | + * |
|
1033 | + * @param array $req_data |
|
1034 | + * @return mixed whatever the raw value of this form section is in the request data |
|
1035 | + * @throws \EE_Error |
|
1036 | + */ |
|
1037 | + public function find_form_data_for_this_section($req_data) |
|
1038 | + { |
|
1039 | + // break up the html name by "[]" |
|
1040 | + if (strpos($this->html_name(), '[') !== false) { |
|
1041 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1042 | + } else { |
|
1043 | + $before_any_brackets = $this->html_name(); |
|
1044 | + } |
|
1045 | + // grab all of the segments |
|
1046 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1047 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
1048 | + $name_parts = $matches[1]; |
|
1049 | + array_unshift($name_parts, $before_any_brackets); |
|
1050 | + } else { |
|
1051 | + $name_parts = array($before_any_brackets); |
|
1052 | + } |
|
1053 | + // now get the value for the input |
|
1054 | + $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
|
1055 | + // check if this thing's name is at the TOP level of the request data |
|
1056 | + if ($value === null && isset($req_data[$this->name()])) { |
|
1057 | + $value = $req_data[$this->name()]; |
|
1058 | + } |
|
1059 | + return $value; |
|
1060 | + } |
|
1061 | + |
|
1062 | + |
|
1063 | + |
|
1064 | + /** |
|
1065 | + * @param array $html_name_parts |
|
1066 | + * @param array $req_data |
|
1067 | + * @return array | NULL |
|
1068 | + */ |
|
1069 | + public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) |
|
1070 | + { |
|
1071 | + $first_part_to_consider = array_shift($html_name_parts); |
|
1072 | + if (isset($req_data[$first_part_to_consider])) { |
|
1073 | + if (empty($html_name_parts)) { |
|
1074 | + return $req_data[$first_part_to_consider]; |
|
1075 | + } else { |
|
1076 | + return $this->_find_form_data_for_this_section_using_name_parts( |
|
1077 | + $html_name_parts, |
|
1078 | + $req_data[$first_part_to_consider] |
|
1079 | + ); |
|
1080 | + } |
|
1081 | + } else { |
|
1082 | + return null; |
|
1083 | + } |
|
1084 | + } |
|
1085 | + |
|
1086 | + |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * Checks if this form input's data is in the request data |
|
1090 | + * |
|
1091 | + * @param array $req_data like $_POST |
|
1092 | + * @return boolean |
|
1093 | + * @throws \EE_Error |
|
1094 | + */ |
|
1095 | + public function form_data_present_in($req_data = null) |
|
1096 | + { |
|
1097 | + if ($req_data === null) { |
|
1098 | + $req_data = $_POST; |
|
1099 | + } |
|
1100 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1101 | + if ($checked_value !== null) { |
|
1102 | + return true; |
|
1103 | + } else { |
|
1104 | + return false; |
|
1105 | + } |
|
1106 | + } |
|
1107 | + |
|
1108 | + |
|
1109 | + |
|
1110 | + /** |
|
1111 | + * Overrides parent to add js data from validation and display strategies |
|
1112 | + * |
|
1113 | + * @param array $form_other_js_data |
|
1114 | + * @return array |
|
1115 | + */ |
|
1116 | + public function get_other_js_data($form_other_js_data = array()) |
|
1117 | + { |
|
1118 | + $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1119 | + return $form_other_js_data; |
|
1120 | + } |
|
1121 | + |
|
1122 | + |
|
1123 | + |
|
1124 | + /** |
|
1125 | + * Gets other JS data for localization from this input's strategies, like |
|
1126 | + * the validation strategies and the display strategy |
|
1127 | + * |
|
1128 | + * @param array $form_other_js_data |
|
1129 | + * @return array |
|
1130 | + */ |
|
1131 | + public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
1132 | + { |
|
1133 | + $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1134 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1135 | + $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1136 | + } |
|
1137 | + return $form_other_js_data; |
|
1138 | + } |
|
1139 | + |
|
1140 | + |
|
1141 | + |
|
1142 | + /** |
|
1143 | + * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1144 | + * |
|
1145 | + * @return void |
|
1146 | + */ |
|
1147 | + public function enqueue_js() |
|
1148 | + { |
|
1149 | + //ask our display strategy and validation strategies if they have js to enqueue |
|
1150 | + $this->enqueue_js_from_strategies(); |
|
1151 | + } |
|
1152 | + |
|
1153 | + |
|
1154 | + |
|
1155 | + /** |
|
1156 | + * Tells strategies when its ok to enqueue their js and css |
|
1157 | + * |
|
1158 | + * @return void |
|
1159 | + */ |
|
1160 | + public function enqueue_js_from_strategies() |
|
1161 | + { |
|
1162 | + $this->get_display_strategy()->enqueue_js(); |
|
1163 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1164 | + $validation_strategy->enqueue_js(); |
|
1165 | + } |
|
1166 | + } |
|
1167 | + |
|
1168 | + |
|
1169 | + |
|
1170 | + /** |
|
1171 | + * Gets the default value set on the input (not the current value, which may have been |
|
1172 | + * changed because of a form submission). If no default was set, this us null. |
|
1173 | + * @return mixed |
|
1174 | + */ |
|
1175 | + public function get_default() |
|
1176 | + { |
|
1177 | + return $this->_default; |
|
1178 | + } |
|
1179 | 1179 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -187,10 +187,10 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function __construct($input_args = array()) |
189 | 189 | { |
190 | - $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
190 | + $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
191 | 191 | // the following properties must be cast as arrays |
192 | 192 | if (isset($input_args['validation_strategies'])) { |
193 | - foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
193 | + foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
194 | 194 | if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
195 | 195 | $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
196 | 196 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | // loop thru incoming options |
201 | 201 | foreach ($input_args as $key => $value) { |
202 | 202 | // add underscore to $key to match property names |
203 | - $_key = '_' . $key; |
|
203 | + $_key = '_'.$key; |
|
204 | 204 | if (property_exists($this, $_key)) { |
205 | 205 | $this->{$_key} = $value; |
206 | 206 | } |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | foreach ($this->_validation_strategies as $validation_strategy) { |
217 | 217 | $validation_strategy->_construct_finalize($this); |
218 | 218 | } |
219 | - if (! $this->_normalization_strategy) { |
|
219 | + if ( ! $this->_normalization_strategy) { |
|
220 | 220 | $this->_normalization_strategy = new EE_Text_Normalization(); |
221 | 221 | } |
222 | 222 | $this->_normalization_strategy->_construct_finalize($this); |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | $this->set_default($input_args['default']); |
226 | 226 | unset($input_args['default']); |
227 | 227 | } |
228 | - if (! $this->_sensitive_data_removal_strategy) { |
|
228 | + if ( ! $this->_sensitive_data_removal_strategy) { |
|
229 | 229 | $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
230 | 230 | } |
231 | 231 | $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
@@ -242,10 +242,10 @@ discard block |
||
242 | 242 | */ |
243 | 243 | protected function _set_default_html_name_if_empty() |
244 | 244 | { |
245 | - if (! $this->_html_name) { |
|
245 | + if ( ! $this->_html_name) { |
|
246 | 246 | $this->_html_name = $this->name(); |
247 | 247 | if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
248 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
248 | + $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]"; |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | protected function _get_display_strategy() |
278 | 278 | { |
279 | 279 | $this->ensure_construct_finalized_called(); |
280 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
280 | + if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
281 | 281 | throw new EE_Error( |
282 | 282 | sprintf( |
283 | 283 | __( |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | */ |
511 | 511 | public function html_other_attributes() |
512 | 512 | { |
513 | - return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
513 | + return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : ''; |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | */ |
655 | 655 | public function html_label_id() |
656 | 656 | { |
657 | - return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
657 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id().'-lbl'; |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | |
@@ -804,7 +804,7 @@ discard block |
||
804 | 804 | $validation_strategy->get_jquery_validation_rule_array() |
805 | 805 | ); |
806 | 806 | } |
807 | - if (! empty($jquery_validation_rules)) { |
|
807 | + if ( ! empty($jquery_validation_rules)) { |
|
808 | 808 | foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
809 | 809 | $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
810 | 810 | } |
@@ -928,7 +928,7 @@ discard block |
||
928 | 928 | public function html_class($add_required = false) |
929 | 929 | { |
930 | 930 | return $add_required && $this->required() |
931 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
931 | + ? $this->required_css_class().' '.$this->_html_class |
|
932 | 932 | : $this->_html_class; |
933 | 933 | } |
934 | 934 | |
@@ -1002,7 +1002,7 @@ discard block |
||
1002 | 1002 | $button_css_attributes .= ''; |
1003 | 1003 | } |
1004 | 1004 | $this->_button_css_attributes .= ! empty($other_attributes) |
1005 | - ? $button_css_attributes . ' ' . $other_attributes |
|
1005 | + ? $button_css_attributes.' '.$other_attributes |
|
1006 | 1006 | : $button_css_attributes; |
1007 | 1007 | } |
1008 | 1008 |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class EE_Submit_Input_Display_Strategy extends EE_Display_Strategy_Base{ |
13 | 13 | |
14 | - const HTML_TAG_BUTTON = 'button'; |
|
15 | - const HTML_TAG_INPUT = 'input'; |
|
14 | + const HTML_TAG_BUTTON = 'button'; |
|
15 | + const HTML_TAG_INPUT = 'input'; |
|
16 | 16 | |
17 | 17 | |
18 | 18 | /** |
@@ -20,24 +20,24 @@ discard block |
||
20 | 20 | * @return string of html to display the input |
21 | 21 | */ |
22 | 22 | public function display(){ |
23 | - $default_value = $this->_input->get_default(); |
|
24 | - if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
|
25 | - $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
|
26 | - } |
|
27 | - $value_in_form = htmlentities( |
|
28 | - $default_value, |
|
29 | - ENT_QUOTES, |
|
30 | - 'UTF-8' |
|
31 | - ); |
|
32 | - $tag = apply_filters( |
|
33 | - 'FHEE__EE_Submit_Input_Display_Strategy__display__submit_input_html_tag', |
|
34 | - EE_Submit_Input_Display_Strategy::HTML_TAG_INPUT |
|
35 | - ); |
|
36 | - // verify result is one of the two valid options |
|
37 | - $tag = $tag === EE_Submit_Input_Display_Strategy::HTML_TAG_BUTTON |
|
38 | - || $tag === EE_Submit_Input_Display_Strategy::HTML_TAG_INPUT |
|
39 | - ? $tag |
|
40 | - : EE_Submit_Input_Display_Strategy::HTML_TAG_INPUT; |
|
23 | + $default_value = $this->_input->get_default(); |
|
24 | + if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
|
25 | + $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
|
26 | + } |
|
27 | + $value_in_form = htmlentities( |
|
28 | + $default_value, |
|
29 | + ENT_QUOTES, |
|
30 | + 'UTF-8' |
|
31 | + ); |
|
32 | + $tag = apply_filters( |
|
33 | + 'FHEE__EE_Submit_Input_Display_Strategy__display__submit_input_html_tag', |
|
34 | + EE_Submit_Input_Display_Strategy::HTML_TAG_INPUT |
|
35 | + ); |
|
36 | + // verify result is one of the two valid options |
|
37 | + $tag = $tag === EE_Submit_Input_Display_Strategy::HTML_TAG_BUTTON |
|
38 | + || $tag === EE_Submit_Input_Display_Strategy::HTML_TAG_INPUT |
|
39 | + ? $tag |
|
40 | + : EE_Submit_Input_Display_Strategy::HTML_TAG_INPUT; |
|
41 | 41 | $html = '<' . $tag . ' type="submit" '; |
42 | 42 | $html .= 'name="' . $this->_input->html_name() . '" '; |
43 | 43 | $html .= 'value="' . $value_in_form . '" '; |
@@ -46,17 +46,17 @@ discard block |
||
46 | 46 | $html .= 'style="' . $this->_input->html_style() . '" '; |
47 | 47 | $html .= $this->_input->other_html_attributes(); |
48 | 48 | if($tag === EE_Submit_Input_Display_Strategy::HTML_TAG_BUTTON) { |
49 | - $button_text = $this->_input->html_label_text(); |
|
50 | - $button_text = ! empty($button_text) |
|
51 | - ? $button_text |
|
52 | - : $value_in_form; |
|
53 | - $html .= '>'; |
|
54 | - $html .= $button_text; |
|
55 | - $html .= '</button>'; |
|
56 | - } else { |
|
57 | - $html .= '/>'; |
|
58 | - } |
|
59 | - return $html; |
|
49 | + $button_text = $this->_input->html_label_text(); |
|
50 | + $button_text = ! empty($button_text) |
|
51 | + ? $button_text |
|
52 | + : $value_in_form; |
|
53 | + $html .= '>'; |
|
54 | + $html .= $button_text; |
|
55 | + $html .= '</button>'; |
|
56 | + } else { |
|
57 | + $html .= '/>'; |
|
58 | + } |
|
59 | + return $html; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @package Event Espresso |
10 | 10 | * @author Mike Nelson |
11 | 11 | */ |
12 | -class EE_Submit_Input_Display_Strategy extends EE_Display_Strategy_Base{ |
|
12 | +class EE_Submit_Input_Display_Strategy extends EE_Display_Strategy_Base { |
|
13 | 13 | |
14 | 14 | const HTML_TAG_BUTTON = 'button'; |
15 | 15 | const HTML_TAG_INPUT = 'input'; |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return string of html to display the input |
21 | 21 | */ |
22 | - public function display(){ |
|
22 | + public function display() { |
|
23 | 23 | $default_value = $this->_input->get_default(); |
24 | 24 | if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
25 | 25 | $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | || $tag === EE_Submit_Input_Display_Strategy::HTML_TAG_INPUT |
39 | 39 | ? $tag |
40 | 40 | : EE_Submit_Input_Display_Strategy::HTML_TAG_INPUT; |
41 | - $html = '<' . $tag . ' type="submit" '; |
|
42 | - $html .= 'name="' . $this->_input->html_name() . '" '; |
|
43 | - $html .= 'value="' . $value_in_form . '" '; |
|
44 | - $html .= 'id="' . $this->_input->html_id() . '-submit" '; |
|
45 | - $html .= 'class="' . $this->_input->html_class() . ' ' . $this->_input->button_css_attributes() . '" '; |
|
46 | - $html .= 'style="' . $this->_input->html_style() . '" '; |
|
41 | + $html = '<'.$tag.' type="submit" '; |
|
42 | + $html .= 'name="'.$this->_input->html_name().'" '; |
|
43 | + $html .= 'value="'.$value_in_form.'" '; |
|
44 | + $html .= 'id="'.$this->_input->html_id().'-submit" '; |
|
45 | + $html .= 'class="'.$this->_input->html_class().' '.$this->_input->button_css_attributes().'" '; |
|
46 | + $html .= 'style="'.$this->_input->html_style().'" '; |
|
47 | 47 | $html .= $this->_input->other_html_attributes(); |
48 | - if($tag === EE_Submit_Input_Display_Strategy::HTML_TAG_BUTTON) { |
|
48 | + if ($tag === EE_Submit_Input_Display_Strategy::HTML_TAG_BUTTON) { |
|
49 | 49 | $button_text = $this->_input->html_label_text(); |
50 | 50 | $button_text = ! empty($button_text) |
51 | 51 | ? $button_text |