PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / V3.0.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder vV3.0.3
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 V3.0.3, at includes/Frontend/Form/View/InputWrapper.php

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