PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
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 / RadioBoxField.php

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

238 lines 7.3 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 use BitCode\BitForm\Core\Util\FrontendHelpers;
6
7 class RadioBoxField
8 {
9 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
10 {
11 $inputWrapper = new ClassicInputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
12 $input = self::field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
13 return $inputWrapper->wrapper($input);
14 }
15
16 private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value)
17 {
18 $fieldHelpers = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map);
19 $req = $fieldHelpers->required();
20 $name = $fieldHelpers->name();
21 $value = '';
22 $radioBoxOptions = '';
23 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
24 $contentCount = count($bfFrontendFormIds);
25 if (property_exists($field, 'opt') && count($field->opt) > 0) {
26 $defaultValue = isset($field->val) ? $field->val : '';
27 foreach ($field->opt as $key => $opt) {
28 $value = isset($opt->val) ? $opt->val : $opt->lbl;
29 $check = '';
30 $req = '';
31 $lbl = $fieldHelpers->renderHTMR($opt->lbl);
32 $disabled = '';
33 if ($fieldHelpers->property_exists_nested($opt, 'check', true)) {
34 $check = "checked='{$opt->check}'";
35 } else {
36 if ($value === $defaultValue) {
37 $check = "checked='checked'";
38 }
39 }
40 if ($fieldHelpers->property_exists_nested($opt, 'req', true)) {
41 $req = "required='{$opt->req}'";
42 }
43 if ($fieldHelpers->property_exists_nested($field, 'valid->disabled', true)
44 || $fieldHelpers->property_exists_nested($opt, 'disabled', true)) {
45 $disabled = "disabled='disabled'";
46 }
47
48 $radioBoxOptions .= sprintf(
49 '<div
50 %1$s
51 class="%2$s %3$s"
52 >
53 <input
54 %4$s
55 id="%5$s-%6$s-chk-%7$s"
56 type="radio"
57 class="%8$s %9$s"
58 value="%10$s"
59 %11$s
60 %12$s
61 %13$s
62 %14$s
63 />
64 <label
65 %15$s
66 data-cl
67 for="%5$s-%6$s-chk-%7$s"
68 class="%16$s %17$s"
69 >
70 <span
71 %18$s
72 data-bx
73 class="%19$s %20$s"
74 >
75 <svg
76 width="12"
77 height="10"
78 viewBox="0 0 12 10"
79 class="%21$s %22$s"
80 >
81 <use
82 data-ck-icn
83 href=#%5$s-ck-svg
84 class="%23$s %24$s"
85 />
86 </svg>
87 </span>
88 <span
89 %25$s
90 class="%26$s %27$s"
91 >
92 %28$s
93 </span>
94 </label>
95 </div>',
96 $fieldHelpers->getCustomAttributes('cw'),
97 $fieldHelpers->getAtomicCls('cw'),
98 $fieldHelpers->getCustomClasses('cw'),
99 $fieldHelpers->getCustomAttributes('ci'),
100 $rowID,
101 $contentCount,
102 $key,
103 $fieldHelpers->getAtomicCls('ci'),
104 $fieldHelpers->getCustomClasses('ci'),
105 $fieldHelpers->esc_attr($value),
106 $check,
107 $name,
108 $req,
109 $disabled,
110 $fieldHelpers->getCustomAttributes('cl'),
111 $fieldHelpers->getAtomicCls('cl'),
112 $fieldHelpers->getCustomClasses('cl'),
113 $fieldHelpers->getCustomAttributes('bx'),
114 $fieldHelpers->getAtomicCls('bx'),
115 $fieldHelpers->getCustomClasses('bx'),
116 $fieldHelpers->getAtomicCls('svgwrp'),
117 $fieldHelpers->getCustomClasses('svgwrp'),
118 $fieldHelpers->getAtomicCls('ck-icn'),
119 $fieldHelpers->getCustomClasses('ck-icn'),
120 $fieldHelpers->getCustomAttributes('ct'),
121 $fieldHelpers->getAtomicCls('ct'),
122 $fieldHelpers->getCustomClasses('ct'),
123 $fieldHelpers->kses_post($lbl)
124 );
125 }
126 }
127
128 //Other Option
129 $otherOptLbl = !empty($field->otherOptLbl) ? $field->otherOptLbl : __('Other...', 'bit-form');
130 $optCount = property_exists($field, 'opt') ? count($field->opt) : 0;
131 $inputPh = isset($field->otherInpPh) ? $field->otherInpPh : $otherOptLbl;
132 $inpReq = isset($field->valid->otherOptReq) ? ($field->valid->otherOptReq ? 'required' : '') : '';
133 if (property_exists($field, 'addOtherOpt') && $field->addOtherOpt) {
134 $check = $check ?? '';
135 $radioBoxOptions .= sprintf(
136 ' <div
137 %1$s
138 class="%2$s %3$s"
139 >
140 <input
141 %4$s
142 id="%5$s-%6$s-chk-%7$s"
143 data-oopt="%5$s"
144 type="radio"
145 class="%8$s %9$s"
146 value=""
147 %10$s
148 %11$s
149 />
150 <label
151 %12$s
152 data-cl
153 for="%5$s-%6$s-chk-%7$s"
154 class="%13$s %14$s"
155 >
156 <span
157 %15$s
158 data-bx
159 class="%16$s %17$s %18$s"
160 >
161 <svg
162 width="12"
163 height="10"
164 viewBox="0 0 12 10"
165 class="%19$s %20$s"
166 >
167 <use
168 data-ck-icn
169 href=#%5$s-ck-svg
170 class="%21$s %22$s"
171 />
172 </svg>
173 </span>
174 <span
175 %23$s
176 class="%24$s %25$s"
177 >
178 %26$s
179 </span>
180 </label>
181 <div data-oinp-wrp class="%27$s">
182 <input
183 data-bf-other-inp="%5$s-chk-%7$s"
184 type="text"
185 class="%28$s"
186 %29$s
187 placeholder="%30$s"
188 >
189 </div>
190 </div>',
191 $fieldHelpers->getCustomAttributes('cw'),
192 $fieldHelpers->getAtomicCls('cw'),
193 $fieldHelpers->getCustomClasses('cw'),
194 $fieldHelpers->getCustomAttributes('ci'),
195 $rowID,
196 $contentCount,
197 $optCount,
198 $fieldHelpers->getAtomicCls('ci'),
199 $fieldHelpers->getCustomClasses('ci'),
200 $check,
201 $name,
202 $fieldHelpers->getCustomAttributes('cl'),
203 $fieldHelpers->getAtomicCls('cl'),
204 $fieldHelpers->getCustomClasses('cl'),
205 $fieldHelpers->getCustomAttributes('rdo'),
206 $fieldHelpers->getAtomicCls('bx'),
207 $fieldHelpers->getAtomicCls('rdo'),
208 $fieldHelpers->getCustomClasses('rdo'),
209 $fieldHelpers->getAtomicCls('svgwrp'),
210 $fieldHelpers->getCustomClasses('svgwrp'),
211 $fieldHelpers->getAtomicCls('ck-icn'),
212 $fieldHelpers->getCustomClasses('ck-icn'),
213 $fieldHelpers->getCustomAttributes('ct'),
214 $fieldHelpers->getAtomicCls('ct'),
215 $fieldHelpers->getCustomClasses('ct'),
216 $otherOptLbl,
217 $fieldHelpers->getAtomicCls('other-inp-wrp'),
218 $fieldHelpers->getAtomicCls('other-inp'),
219 $inpReq,
220 $fieldHelpers->esc_attr($inputPh)
221 );
222 }
223
224 return sprintf(
225 '<div
226 %1$s
227 class="%2$s %3$s"
228 >
229 %4$s
230 </div>',
231 $fieldHelpers->getCustomAttributes('cc'),
232 $fieldHelpers->getAtomicCls('cc'),
233 $fieldHelpers->getCustomClasses('cc'),
234 $radioBoxOptions
235 );
236 }
237 }
238