PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / V3.0.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder vV3.0.2
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 / Conversational / Fields / ConversationalInputWrapper.php

ConversationalInputWrapper.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder V3.0.2, at includes/Frontend/Form/View/Conversational/Fields/ConversationalInputWrapper.php

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