PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.0
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
bit-form / includes / Frontend / Form / View / Theme / Fields / HtmlSelectField.php

HtmlSelectField.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.0, at includes/Frontend/Form/View/Theme/Fields/HtmlSelectField.php

119 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields;
4
5 class HtmlSelectField {
6 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null) {
7 $inputWrapper = new InputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
8 $input = self::field($field, $rowID, $form_atomic_Cls_map, $value);
9 return $inputWrapper->wrapper($input);
10 }
11
12 private static function checkSelected($opt, $val) {
13 $selected = '';
14 if (isset($opt->val) && $opt->val === $val) {
15 $selected = 'selected';
16 } elseif (isset($opt->lbl) && $opt->lbl === $val) {
17 $selected = 'selected';
18 } elseif (property_exists($opt, 'check')) {
19 $selected = 'selected';
20 }
21 return $selected;
22 }
23
24 private static function field($field, $rowID, $form_atomic_Cls_map, $v) {
25 $fieldHelpers = new FieldHelpers($field, $rowID, $form_atomic_Cls_map);
26 $disabled = $fieldHelpers->disabled();
27 $readonly = $fieldHelpers->readonly();
28 $name = $fieldHelpers->name();
29 $value = '';
30 if ($v) {
31 $value = $v;
32 } elseif (isset($field->val)) {
33 $value = $field->val;
34 }
35
36 $readonlyCls = $readonly ? 'readonly' : '';
37 $phHide = '';
38 $optionsHTML = '';
39
40 if ($fieldHelpers->property_exists_nested($field, 'phHide', true)) {
41 $phHide = <<<PHHIDE
42 <option
43 class="{$fieldHelpers->getAtomicCls('slct-optn')} {$fieldHelpers->getCustomClasses('slct-optn')}"
44 value="{$field->ph}"
45 {$fieldHelpers->getCustomAttributes('slct-optn')}
46 >
47 {$field->ph}
48 </option>
49 PHHIDE;
50 }
51
52 if (property_exists($field, 'opt')) {
53 foreach ($field->opt as $opt) {
54 $disabled = property_exists($opt, 'disabled') ? 'disabled' : '';
55 if (property_exists($opt, 'type')) {
56 $optionsHTML .= <<<OPTGRP
57 <optgroup
58 class="{$fieldHelpers->getAtomicCls('slct-opt-grp')} {$fieldHelpers->getCustomClasses('slct-opt-grp')}"
59 label="{$opt->title}"
60 {$fieldHelpers->getCustomAttributes('slct-opt-grp')}
61 {$disabled}
62 >
63 OPTGRP;
64 foreach ($opt->childs as $child) {
65 $val = isset($child->val) ? $child->val : $child->lbl;
66 $selected = self::checkSelected($child, $value);
67 $disabled = property_exists($child, 'disabled') ? 'disabled' : '';
68 $optionsHTML .= <<<OPT
69 <option
70 class="{$fieldHelpers->getAtomicCls('slct-optn')} {$fieldHelpers->getCustomClasses('slct-optn')}"
71 value="{$val}"
72 {$fieldHelpers->getCustomAttributes('slct-optn')}
73 {$selected}
74 {$disabled}
75 >
76 {$child->lbl}
77 </option>
78 OPT;
79 }
80 $optionsHTML .= '</optgroup>';
81 } else {
82 $selected = self::checkSelected($opt, $value);
83 $val = isset($opt->val) ? $opt->val : $opt->lbl;
84 $optionsHTML .= <<<OPT
85 <option
86 class="{$fieldHelpers->getAtomicCls('slct-optn')} {$fieldHelpers->getCustomClasses('slct-optn')}"
87 value="{$val}"
88 {$selected}
89 {$fieldHelpers->getCustomAttributes('slct-optn')}
90 {$disabled}
91 >
92 {$opt->lbl}
93 </option>
94 OPT;
95 }
96 }
97 }
98
99 return <<<HTMLSELECTFIELD
100 <div class="{$fieldHelpers->getAtomicCls('inp-fld-wrp')} {$fieldHelpers->getCustomClasses('inp-fld-wrp')}"
101 {$fieldHelpers->getCustomAttributes('inp-fld-wrp')}
102 >
103 <select
104 id={$rowID}
105 class="{$fieldHelpers->getAtomicCls('fld')} {$fieldHelpers->getCustomClasses('fld')} {$readonlyCls}"
106 {$readonly}
107 {$disabled}
108 {$name}
109 value="{$value}"
110 {$fieldHelpers->getCustomAttributes('fld')}
111 >
112 {$phHide}
113 {$optionsHTML}
114 </select>
115 </div>
116 HTMLSELECTFIELD;
117 }
118 }
119