PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
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 3.3.1, at includes/Frontend/Form/View/Theme/Fields/RadioBoxField.php

250 lines 7.7 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 (is_object($field) && property_exists($field, 'opt') && is_countable($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 aria-hidden="true"
81 >
82 <use
83 data-ck-icn
84 href=#%5$s-ck-svg
85 class="%23$s %24$s"
86 />
87 </svg>
88 </span>
89 <span
90 %25$s
91 class="%26$s %27$s"
92 >
93 %28$s
94 </span>
95 </label>
96 </div>',
97 $fieldHelpers->getCustomAttributes('cw'),
98 $fieldHelpers->getAtomicCls('cw'),
99 $fieldHelpers->getCustomClasses('cw'),
100 $fieldHelpers->getCustomAttributes('ci'),
101 $rowID,
102 $contentCount,
103 $key,
104 $fieldHelpers->getAtomicCls('ci'),
105 $fieldHelpers->getCustomClasses('ci'),
106 $fieldHelpers->esc_attr($value),
107 $check,
108 $name,
109 $req,
110 $disabled,
111 $fieldHelpers->getCustomAttributes('cl'),
112 $fieldHelpers->getAtomicCls('cl'),
113 $fieldHelpers->getCustomClasses('cl'),
114 $fieldHelpers->getCustomAttributes('bx'),
115 $fieldHelpers->getAtomicCls('bx'),
116 $fieldHelpers->getCustomClasses('bx'),
117 $fieldHelpers->getAtomicCls('svgwrp'),
118 $fieldHelpers->getCustomClasses('svgwrp'),
119 $fieldHelpers->getAtomicCls('ck-icn'),
120 $fieldHelpers->getCustomClasses('ck-icn'),
121 $fieldHelpers->getCustomAttributes('ct'),
122 $fieldHelpers->getAtomicCls('ct'),
123 $fieldHelpers->getCustomClasses('ct'),
124 $fieldHelpers->kses_post($lbl)
125 );
126 }
127 }
128
129 //Other Option
130 $otherOptLbl = !empty($field->otherOptLbl) ? $field->otherOptLbl : __('Other...', 'bit-form');
131 $optCount = isset($field->opt) && is_countable($field->opt) ? count($field->opt) : 0;
132 $inputPh = isset($field->otherInpPh) ? $field->otherInpPh : $otherOptLbl;
133 $inpReq = isset($field->valid->otherOptReq) ? ($field->valid->otherOptReq ? 'required' : '') : '';
134 if (property_exists($field, 'addOtherOpt') && $field->addOtherOpt) {
135 $check = $check ?? '';
136 $radioBoxOptions .= sprintf(
137 '
138 <div
139 %1$s
140 class="%2$s %3$s"
141 >
142 <input
143 %4$s
144 id="%5$s-%6$s-chk-%7$s"
145 data-oopt="%5$s"
146 type="radio"
147 class="%8$s %9$s"
148 value=""
149 %10$s
150 %11$s
151 />
152 <label
153 %12$s
154 data-cl
155 for="%5$s-%6$s-chk-%7$s"
156 class="%13$s %14$s"
157 >
158 <span
159 %15$s
160 data-bx
161 class="%16$s %17$s %18$s"
162 >
163 <svg
164 width="12"
165 height="10"
166 viewBox="0 0 12 10"
167 class="%19$s %20$s"
168 >
169 <use
170 data-ck-icn
171 href=#%5$s-ck-svg
172 class="%21$s %22$s"
173 />
174 </svg>
175 </span>
176 <span
177 %23$s
178 class="%24$s %25$s"
179 >
180 %26$s
181 </span>
182 </label>
183 <div data-oinp-wrp class="%27$s">
184 <input
185 data-bf-other-inp="%5$s-chk-%7$s"
186 type="text"
187 class="%28$s"
188 %29$s
189 placeholder="%30$s"
190 >
191 </div>
192 </div>',
193 $fieldHelpers->getCustomAttributes('cw'),
194 $fieldHelpers->getAtomicCls('cw'),
195 $fieldHelpers->getCustomClasses('cw'),
196 $fieldHelpers->getCustomAttributes('ci'),
197 $rowID,
198 $contentCount,
199 $optCount,
200 $fieldHelpers->getAtomicCls('ci'),
201 $fieldHelpers->getCustomClasses('ci'),
202 $check,
203 $name,
204 $fieldHelpers->getCustomAttributes('cl'),
205 $fieldHelpers->getAtomicCls('cl'),
206 $fieldHelpers->getCustomClasses('cl'),
207 $fieldHelpers->getCustomAttributes('rdo'),
208 $fieldHelpers->getAtomicCls('bx'),
209 $fieldHelpers->getAtomicCls('rdo'),
210 $fieldHelpers->getCustomClasses('rdo'),
211 $fieldHelpers->getAtomicCls('svgwrp'),
212 $fieldHelpers->getCustomClasses('svgwrp'),
213 $fieldHelpers->getAtomicCls('ck-icn'),
214 $fieldHelpers->getCustomClasses('ck-icn'),
215 $fieldHelpers->getCustomAttributes('ct'),
216 $fieldHelpers->getAtomicCls('ct'),
217 $fieldHelpers->getCustomClasses('ct'),
218 $otherOptLbl,
219 $fieldHelpers->getAtomicCls('other-inp-wrp'),
220 $fieldHelpers->getAtomicCls('other-inp'),
221 $inpReq,
222 $fieldHelpers->esc_attr($inputPh)
223 );
224 }
225
226 $labelId = $fieldHelpers->getLabelId();
227 $ariaDescribedBy = $fieldHelpers->ariaDescribedBy();
228 $ariaRequired = $fieldHelpers->ariaRequired();
229 return sprintf(
230 '<div
231 %1$s
232 class="%2$s %3$s"
233 role="radiogroup"
234 aria-labelledby="%4$s"
235 %5$s
236 %6$s
237 >
238 %7$s
239 </div>',
240 $fieldHelpers->getCustomAttributes('cc'),
241 $fieldHelpers->getAtomicCls('cc'),
242 $fieldHelpers->getCustomClasses('cc'),
243 $labelId,
244 $ariaDescribedBy,
245 $ariaRequired,
246 $radioBoxOptions
247 );
248 }
249 }
250