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