PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.1.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.1.2
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 2.10.2 All 137 releases
bit-form / includes / Frontend / Form / View / InputWrapper.php

InputWrapper.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.1.2, at includes/Frontend/Form/View/InputWrapper.php

305 lines 10.2 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;
4
5 use BitCode\BitForm\Core\Util\FrontendHelpers;
6
7 class InputWrapper
8 {
9 private $_fieldData;
10 private $_fieldKey;
11 private $_fieldName;
12 private $_formID;
13 private $_error;
14 private $_value;
15 private $_fieldHelpers;
16
17 public function __construct($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
18 {
19 $this->_fieldData = $field;
20 $this->_fieldKey = $rowID;
21 $this->_fieldName = $field_name;
22 $this->_formID = $formID;
23 $this->_error = $error;
24 $this->_value = $value;
25 $this->_fieldHelpers = new FieldHelpers($field, $rowID, $form_atomic_Cls_map);
26 }
27
28 public function wrapper($field, $noLabel = false, $noErrMsg = false)
29 {
30 $labelWrapper = !$noLabel ? $this->labelWrapper() : '';
31 $helperText = $this->helperText();
32 $error = !$noErrMsg ? $this->errorMessages() : '';
33 $fieldTypeClass = empty($this->_fieldData->typ) ? 'bf-default-field' : 'bf-' . $this->_fieldData->typ . '-field';
34
35 return sprintf(
36 '<div %1$s class="%2$s %3$s %4$s">
37 %5$s
38 <div %6$s class="%7$s %8$s">
39 %9$s
40 %10$s
41 %11$s
42 </div>
43 </div>',
44 $this->_fieldHelpers->getCustomAttributes('fld-wrp'),
45 $fieldTypeClass,
46 $this->_fieldHelpers->getAtomicCls('fld-wrp'),
47 $this->_fieldHelpers->getCustomClasses('fld-wrp'),
48 $labelWrapper,
49 $this->_fieldHelpers->getCustomAttributes('inp-wrp'),
50 $this->_fieldHelpers->getAtomicCls('inp-wrp'),
51 $this->_fieldHelpers->getCustomClasses('inp-wrp'),
52 $field,
53 $helperText,
54 $error
55 );
56 }
57
58 private function labelWrapper()
59 {
60 $_label = '';
61 $_lblPreIcn = $this->_fieldHelpers->icon('lblPreIcn', 'lbl-pre-i');
62 $_lblSufIcn = $this->_fieldHelpers->icon('lblSufIcn', 'lbl-suf-i');
63 $_reqPre = '';
64 $_reqPost = '';
65 $_lbl = '';
66 $_subtitle = '';
67 $_subtitleText = '';
68 $_subtitlePreIcn = $this->_fieldHelpers->icon('subTlePreIcn', 'sub-titl-pre-i');
69 $_subtitlePostIcn = $this->_fieldHelpers->icon('subTleSufIcn', 'sub-titl-suf-i');
70 if (property_exists($this->_fieldData, 'lbl')) {
71 $replaceToBackSlash = $this->_fieldHelpers->replaceToBackSlash($this->_fieldData->lbl);
72 $_lbl = wp_kses_post($this->_fieldHelpers->renderHTMR($replaceToBackSlash));
73 }
74
75 if (property_exists($this->_fieldData, 'subtitle')) {
76 $replaceToBackSlash = $this->_fieldHelpers->replaceToBackSlash($this->_fieldData->subtitle);
77 $_subtitleText = wp_kses_post($this->_fieldHelpers->renderHTMR($replaceToBackSlash));
78 }
79
80 // for pre required icon
81 // aria-hidden="true" is used because the asterisk is purely decorative/visual.
82 // Screen readers will announce the field as required via aria-required="true" on the input element.
83 // This prevents redundant "asterisk" or "star" announcements.
84 if (
85 $this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->req')
86 && $this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->reqShow', true)
87 && $this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->reqPos', 'before')
88 ) {
89 $_reqPre = sprintf(
90 '<span %1$s class="%2$s %3$s" aria-hidden="true">*</span>',
91 $this->_fieldHelpers->getCustomAttributes('req-smbl'),
92 $this->_fieldHelpers->getAtomicCls('req-smbl'),
93 $this->_fieldHelpers->getCustomClasses('req-smbl')
94 );
95 }
96 // for post required icon
97 // Same accessibility reasoning as pre required icon - hide from screen readers
98 // to avoid redundant announcements since aria-required is on the input.
99 if (
100 $this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->req')
101 && $this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->reqShow', true)
102 && $this->_fieldHelpers->property_exists_nested($this->_fieldData, 'valid->reqPos', 'before', 1)
103 ) {
104 $_reqPost = sprintf(
105 '<span %1$s class="%2$s %3$s" aria-hidden="true">*</span>',
106 $this->_fieldHelpers->getCustomAttributes('req-smbl'),
107 $this->_fieldHelpers->getAtomicCls('req-smbl'),
108 $this->_fieldHelpers->getCustomClasses('req-smbl')
109 );
110 }
111
112 // for Label
113 if (
114 property_exists($this->_fieldData, 'lbl')
115 // && isset($this->_fieldData->valid->hideLbl)
116 // && $this->_fieldData->valid->hideLbl !== true
117 ) {
118 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
119 $contentCount = count($bfFrontendFormIds);
120 $labelId = $this->_fieldHelpers->getLabelId();
121 $_label = sprintf(
122 '<label
123 id="%1$s"
124 %2$s
125 class="%3$s %4$s"
126 for="%5$s-%6$d">
127 %7$s
128 %8$s
129 %9$s
130 %10$s
131 %11$s
132 </label>',
133 $labelId,
134 $this->_fieldHelpers->getCustomAttributes('lbl'),
135 $this->_fieldHelpers->getAtomicCls('lbl'),
136 $this->_fieldHelpers->getCustomClasses('lbl'),
137 $this->_fieldKey,
138 $contentCount,
139 $_reqPre,
140 $_lblPreIcn,
141 $_lbl,
142 $_lblSufIcn,
143 $_reqPost
144 );
145 }
146
147 // for subtitle
148 if (property_exists($this->_fieldData, 'subtitle') && $this->_fieldData->subtitleHide) {
149 $_subtitle = sprintf(
150 '<div %1$s class="%2$s %3$s">%4$s%5$s%6$s</div>',
151 $this->_fieldHelpers->getCustomAttributes('sub-titl'),
152 $this->_fieldHelpers->getAtomicCls('sub-titl'),
153 $this->_fieldHelpers->getCustomClasses('sub-titl'),
154 $_subtitlePreIcn,
155 $_subtitleText,
156 $_subtitlePostIcn
157 );
158 }
159
160 return sprintf(
161 '<div %1$s class="%2$s %3$s">%4$s%5$s</div>',
162 $this->_fieldHelpers->getCustomAttributes('lbl-wrp'),
163 $this->_fieldHelpers->getAtomicCls('lbl-wrp'),
164 $this->_fieldHelpers->getCustomClasses('lbl-wrp'),
165 $_label,
166 $_subtitle
167 );
168 }
169
170 private function helperText()
171 {
172 $_helperTxtPreIcn = $this->_fieldHelpers->icon('hlpPreIcn', 'hlp-txt-pre-i');
173 $_helperTxtSufIcn = $this->_fieldHelpers->icon('hlpSufIcn', 'hlp-txt-suf-i');
174 $_helperTxt = '';
175
176 if (isset($this->_fieldData->helperTxt)) {
177 $_helperTxt = wp_kses_post($this->_fieldHelpers->renderHTMR($this->_fieldData->helperTxt));
178 }
179
180 if (property_exists($this->_fieldData, 'helperTxt') && $this->_fieldData->helperTxt) {
181 $helperTextId = $this->_fieldHelpers->getHelperTextId();
182 $_helperTxt = sprintf(
183 '<div
184 id="%1$s"
185 %2$s
186 class="%3$s %4$s"
187 >
188 %5$s
189 %6$s
190 %7$s
191 </div>',
192 $helperTextId,
193 $this->_fieldHelpers->getCustomAttributes('hlp-txt'),
194 $this->_fieldHelpers->getAtomicCls('hlp-txt'),
195 $this->_fieldHelpers->getCustomClasses('hlp-txt'),
196 $_helperTxtPreIcn,
197 $_helperTxt,
198 $_helperTxtSufIcn
199 );
200 }
201
202 // for helper text
203 return $_helperTxt;
204 }
205
206 public function errorMessages()
207 {
208 $_errorPreIcn = $this->_fieldHelpers->icon('errPreIcn', 'err-txt-pre-i');
209 $_errorSufIcn = $this->_fieldHelpers->icon('errSufIcn', 'err-txt-suf-i');
210 $_error = '';
211 $_style = 'opacity: 0 !important; height: 0px !important;';
212
213 if ($this->_error) {
214 $_error = wp_kses_post($this->_error);
215 $_style = 'margin-top: 5px !important; height: 9px !important;';
216 }
217
218 $errorId = $this->_fieldHelpers->getErrorId();
219 $errMsgStart = '';
220 $errMsgEnd = '';
221 $msgStyle = "style='display: none !important;'";
222 $errMsgAtomicCls = $this->_fieldHelpers->getAtomicCls('err-msg');
223 $errMsgCustomCls = $this->_fieldHelpers->getCustomClasses('err-msg');
224 $errMsgCustomAttr = $this->_fieldHelpers->getCustomAttributes('err-msg');
225 if (!(empty($_errorPreIcn) && empty($_errorSufIcn))) {
226 $errMsgStart = "<div {$errMsgCustomAttr} class='{$errMsgAtomicCls} {$errMsgCustomCls}' {$msgStyle}>";
227 $errMsgEnd = '</div>';
228 $msgStyle = '';
229 $errMsgAtomicCls = '';
230 $errMsgCustomCls = '';
231 $errMsgCustomAttr = '';
232 }
233
234 return sprintf(
235 '<div class="%1$s" role="alert" aria-atomic="true" aria-live="assertive" style="%2$s">
236 <div class="%3$s">
237 %4$s
238 %5$s
239 <div
240 id="%6$s"
241 %7$s
242 %8$s
243 class="%9$s %10$s %11$s %12$s "
244 %13$s
245 >
246 %14$s
247 </div>
248 %15$s
249 %16$s
250 </div>
251 </div>',
252 $this->_fieldHelpers->getAtomicCls('err-wrp'), // 1
253 $_style, // 2
254 $this->_fieldHelpers->getAtomicCls('err-inner'), // 3
255 $errMsgStart, // 4
256 $_errorPreIcn, // 5
257 $errorId, // 6
258 $this->_fieldHelpers->getCustomAttributes('err-txt'), // 7
259 $errMsgCustomAttr, // 8
260 $errMsgAtomicCls, // 9
261 $errMsgCustomCls, // 10
262 $this->_fieldHelpers->getAtomicCls('err-txt'), // 11
263 $this->_fieldHelpers->getCustomClasses('err-txt'), // 12
264 $msgStyle, // 13
265 $_error, // 14
266 $_errorSufIcn, // 15
267 $errMsgEnd // 16
268 );
269 }
270
271 /**
272 * Get the field helpers instance for external access
273 * @return FieldHelpers
274 */
275 public function getFieldHelpers()
276 {
277 return $this->_fieldHelpers;
278 }
279
280 public function parentFieldWrapper($childFieldsInput)
281 {
282 return '<div '
283 . $this->_fieldHelpers->getCustomAttributes('parent-fld-wrp')
284 . ' class="' . $this->_fieldHelpers->getAtomicCls('parent-fld-wrp') . ' ' . $this->_fieldHelpers->getCustomClasses('parent-fld-wrp') . '">'
285 . $childFieldsInput
286 . '</div>';
287 }
288
289 public function childFieldWrapper($fieldInput, $subFieldName = '', $colSpan = null, $childKey = '')
290 {
291 $dataAttr = $subFieldName ? ' data-bf-subfield="' . esc_attr($subFieldName) . '"' : '';
292 $styleAttr = null !== $colSpan ? ' style="--bfv-addr-col:' . (int) $colSpan . '"' : '';
293 // Per-child class so conditional actions (show/hide) can collapse the whole column.
294 $childKeyCls = $childKey ? ' ' . esc_attr($childKey) . '-sub-fld-wrp' : '';
295 return '<div'
296 . $dataAttr
297 . $styleAttr
298 . ' '
299 . $this->_fieldHelpers->getCustomAttributes('child-fld-wrp')
300 . ' class="' . $this->_fieldHelpers->getAtomicCls('child-fld-wrp') . ' ' . $this->_fieldHelpers->getCustomClasses('child-fld-wrp') . $childKeyCls . '">'
301 . $fieldInput
302 . '</div>';
303 }
304 }
305