PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFieldFormHtml.php +4 -94 6.266.16 View file →
@@ -7,16 +7,10 @@
7 7 * @since 3.0
8 8 */
9 9 class FrmFieldFormHtml {
10 10
11 - /**
12 - * @var string
13 - */
14 11 private $html;
15 12
16 - /**
17 - * @var string
18 - */
19 13 private $html_id;
20 14
21 15 /**
22 16 * @var FrmFieldType
@@ -22,21 +16,12 @@
22 16 * @var FrmFieldType
23 17 */
24 18 private $field_obj;
25 19
26 - /**
27 - * @var int|string
28 - */
29 20 private $field_id;
30 21
31 - /**
32 - * @var array|object
33 - */
34 22 private $form = array();
35 23
36 - /**
37 - * @var array
38 - */
39 24 private $pass_args = array();
40 25
41 26 /**
42 27 * @since 3.0
@@ -56,10 +41,8 @@
56 41 * @since 3.0
57 42 *
58 43 * @param string $param
59 44 * @param array $atts
60 - *
61 - * @return void
62 45 */
63 46 private function _set( $param, $atts ) {
64 47 if ( isset( $atts[ $param ] ) ) {
65 48 $this->{$param} = $atts[ $param ];
@@ -69,10 +52,8 @@
69 52 /**
70 53 * @since 3.0
71 54 *
72 55 * @param array $atts
73 - *
74 - * @return void
75 56 */
76 57 private function set_html( $atts ) {
77 58 $this->set_from_field(
78 59 $atts,
@@ -86,10 +67,8 @@
86 67 /**
87 68 * @since 3.0
88 69 *
89 70 * @param array $atts
90 - *
91 - * @return void
92 71 */
93 72 private function set_field_id( $atts ) {
94 73 $this->set_from_field(
95 74 $atts,
@@ -103,16 +82,13 @@
103 82 /**
104 83 * @since 3.0
105 84 *
106 85 * @param array $atts
107 - *
108 - * @return void
109 86 */
110 87 private function set_pass_args( $atts ) {
111 88 $this->pass_args = $atts;
112 89
113 90 $exclude = array( 'field_obj', 'html' );
114 -
115 91 foreach ( $exclude as $ex ) {
116 92 if ( isset( $atts[ $ex ] ) ) {
117 93 unset( $this->pass_args[ $ex ] );
118 94 }
@@ -123,10 +99,8 @@
123 99 * @since 3.0
124 100 *
125 101 * @param array $atts
126 102 * @param array $set
127 - *
128 - * @return void
129 103 */
130 104 private function set_from_field( $atts, $set ) {
131 105 if ( isset( $atts[ $set['param'] ] ) ) {
132 106 $this->{$set['param']} = $atts[ $set['param'] ];
@@ -134,11 +108,8 @@
134 108 $this->{$set['param']} = $this->field_obj->get_field_column( $set['default'] );
135 109 }
136 110 }
137 111
138 - /**
139 - * @return string
140 - */
141 112 public function get_html() {
142 113 $this->replace_shortcodes_before_input();
143 114 $this->replace_shortcodes_with_atts();
144 115 $this->replace_shortcodes_after_input();
@@ -147,10 +118,8 @@
147 118 }
148 119
149 120 /**
150 121 * @since 3.0
151 - *
152 - * @return void
153 122 */
154 123 private function replace_shortcodes_before_input() {
155 124 $this->html = apply_filters( 'frm_before_replace_shortcodes', $this->html, $this->field_obj->get_field(), $this->pass_args['errors'], $this->form );
156 125
@@ -172,10 +141,8 @@
172 141 }
173 142
174 143 /**
175 144 * @since 3.0
176 - *
177 - * @return void
178 145 */
179 146 private function replace_field_values() {
180 147 // Replace [id].
181 148 $this->html = str_replace( '[id]', $this->field_id, $this->html );
@@ -191,10 +158,8 @@
191 158 }
192 159
193 160 /**
194 161 * @since 3.0
195 - *
196 - * @return void
197 162 */
198 163 private function replace_required_label_shortcode() {
199 164 $required = FrmField::is_required( $this->field_obj->get_field() ) ? $this->field_obj->get_field_column( 'required_indicator' ) : '';
200 165 FrmShortcodeHelper::remove_inline_conditions( ! empty( $required ), 'required_label', $required, $this->html );
@@ -204,17 +169,12 @@
204 169 * If this is an HTML field, the values are included in the description.
205 170 * In this case, we don't want to run the wp shortcodes with the description included.
206 171 *
207 172 * @since 3.0
208 - *
209 - * @param bool $wp_processed
210 - *
211 - * @return void
212 173 */
213 174 private function maybe_replace_description_shortcode( $wp_processed = false ) {
214 175 $is_html = 'html' === $this->field_obj->get_field_column( 'type' );
215 176 $should_replace = ( $is_html && $wp_processed ) || ( ! $is_html && ! $wp_processed );
216 -
217 177 if ( $should_replace ) {
218 178 $this->replace_description_shortcode();
219 179 }
220 180 }
@@ -220,10 +180,8 @@
220 180 }
221 181
222 182 /**
223 183 * @since 3.0
224 - *
225 - * @return void
226 184 */
227 185 private function replace_description_shortcode() {
228 186 $this->maybe_add_description_id();
229 187 $description = FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'description' ) );
@@ -234,14 +192,11 @@
234 192 * Add an ID to the description for aria-describedby.
235 193 * This ID was added to the HTML in v3.0.
236 194 *
237 195 * @since 3.0
238 - *
239 - * @return void
240 196 */
241 197 private function maybe_add_description_id() {
242 198 $description = $this->field_obj->get_field_column( 'description' );
243 -
244 199 if ( $description != '' ) {
245 200 $this->add_element_id( 'description', 'desc' );
246 201 }
247 202 }
@@ -249,17 +204,11 @@
249 204 /**
250 205 * Insert an ID if it doesn't exist.
251 206 *
252 207 * @since 3.06.02
253 - *
254 - * @param string $param
255 - * @param string $id
256 - *
257 - * @return void
258 208 */
259 209 private function add_element_id( $param, $id ) {
260 210 preg_match_all( '/(\[if\s+' . $param . '\])(.*?)(\[\/if\s+' . $param . '\])/mis', $this->html, $inner_html );
261 -
262 211 if ( ! isset( $inner_html[2] ) ) {
263 212 return;
264 213 }
265 214
@@ -268,9 +217,8 @@
268 217 }
269 218
270 219 if ( is_string( $inner_html[2] ) ) {
271 220 $has_id = strpos( $inner_html[2], ' id=' );
272 -
273 221 if ( ! $has_id ) {
274 222 $id = 'frm_' . $id . '_' . $this->html_id;
275 223 $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html );
276 224 }
@@ -278,18 +226,15 @@
278 226 }
279 227
280 228 /**
281 229 * @since 3.0
282 - *
283 - * @return void
284 230 */
285 231 private function replace_error_shortcode() {
286 232 $this->maybe_add_error_id();
287 - $error = $this->pass_args['errors'][ 'field' . $this->field_id ] ?? false;
233 + $error = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? $this->pass_args['errors'][ 'field' . $this->field_id ] : false;
288 234
289 235 if ( ! empty( $error ) && false === strpos( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) {
290 236 $error_body = self::get_error_body( $this->html );
291 -
292 237 if ( is_string( $error_body ) && false === strpos( $error_body, 'role=' ) ) {
293 238 $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 );
294 239 $this->html = str_replace( '[if error]' . $error_body . '[/if error]', '[if error]' . $new_error_body . '[/if error]', $this->html );
295 240 }
@@ -301,20 +246,17 @@
301 246 /**
302 247 * Pull the HTML between [if error] and [/if error] shortcodes.
303 248 *
304 249 * @param string $html
305 - *
306 250 * @return false|string
307 251 */
308 252 private static function get_error_body( $html ) {
309 253 $start = strpos( $html, '[if error]' );
310 -
311 254 if ( false === $start ) {
312 255 return false;
313 256 }
314 257
315 258 $end = strpos( $html, '[/if error]', $start );
316 -
317 259 if ( false === $end ) {
318 260 return false;
319 261 }
320 262
@@ -326,10 +268,8 @@
326 268 * Add an ID to the error message for aria-describedby.
327 269 * This ID was added to the HTML in v3.06.02.
328 270 *
329 271 * @since 3.06.02
330 - *
331 - * @return void
332 272 */
333 273 private function maybe_add_error_id() {
334 274 if ( ! isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) {
335 275 return;
@@ -341,10 +281,8 @@
341 281 /**
342 282 * Replace [required_class]
343 283 *
344 284 * @since 3.0
345 - *
346 - * @return void
347 285 */
348 286 private function replace_required_class() {
349 287 $required_class = FrmField::is_required( $this->field_obj->get_field() ) ? ' frm_required_field' : '';
350 288 $this->html = str_replace( '[required_class]', $required_class, $this->html );
@@ -351,10 +289,8 @@
351 289 }
352 290
353 291 /**
354 292 * @since 3.0
355 - *
356 - * @return void
357 293 */
358 294 private function replace_form_shortcodes() {
359 295 if ( ! empty( $this->form ) ) {
360 296 $form = (array) $this->form;
@@ -368,10 +304,8 @@
368 304 }
369 305
370 306 /**
371 307 * @since 3.0
372 - *
373 - * @return void
374 308 */
375 309 public function replace_shortcodes_after_input() {
376 310 $this->html .= "\n";
377 311
@@ -382,10 +316,8 @@
382 316 }
383 317
384 318 /**
385 319 * @since 3.0
386 - *
387 - * @return void
388 320 */
389 321 private function filter_for_more_shortcodes() {
390 322 $atts = $this->pass_args;
391 323
@@ -404,10 +336,8 @@
404 336 *
405 337 * @since 3.0
406 338 *
407 339 * @param string $html
408 - *
409 - * @return void
410 340 */
411 341 public function remove_collapse_shortcode( &$html ) {
412 342 if ( strpos( $html, '[collapse_this]' ) ) {
413 343 $html = str_replace( '[collapse_this]', '', $html );
@@ -415,10 +345,8 @@
415 345 }
416 346
417 347 /**
418 348 * @since 3.0
419 - *
420 - * @return void
421 349 */
422 350 private function replace_shortcodes_with_atts() {
423 351 preg_match_all( "/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $this->html, $shortcodes, PREG_PATTERN_ORDER );
424 352
@@ -458,9 +386,9 @@
458 386 if ( isset( $shortcode_atts['opt'] ) ) {
459 387 --$shortcode_atts['opt'];
460 388 }
461 389
462 - $field_class = $shortcode_atts['class'] ?? '';
390 + $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : '';
463 391 $this->field_obj->set_field_column( 'input_class', $field_class );
464 392
465 393 if ( isset( $shortcode_atts['class'] ) ) {
466 394 unset( $shortcode_atts['class'] );
@@ -465,9 +393,9 @@
465 393 if ( isset( $shortcode_atts['class'] ) ) {
466 394 unset( $shortcode_atts['class'] );
467 395 }
468 396
469 - $this->field_obj->set_aria_invalid_error( $shortcode_atts, $this->pass_args );
397 + $shortcode_atts['aria-invalid'] = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? 'true' : 'false';
470 398
471 399 $this->field_obj->set_field_column( 'shortcodes', $shortcode_atts );
472 400
473 401 return $shortcode_atts;
@@ -477,10 +405,8 @@
477 405 * Add the label position class into the HTML
478 406 * If the label position is inside, add a class to show the label if the field has a value.
479 407 *
480 408 * @since 3.0
481 - *
482 - * @return void
483 409 */
484 410 private function add_class_to_label() {
485 411 $label_class = $this->field_obj->get_label_class();
486 412 $this->html = str_replace( '[label_position]', $label_class, $this->html );
@@ -489,10 +415,8 @@
489 415 /**
490 416 * Replace [entry_key]
491 417 *
492 418 * @since 3.0
493 - *
494 - * @return void
495 419 */
496 420 private function replace_entry_key() {
497 421 $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' );
498 422 $this->html = str_replace( '[entry_key]', $entry_key, $this->html );
@@ -501,18 +425,15 @@
501 425 /**
502 426 * Add classes to a field div
503 427 *
504 428 * @since 3.0
505 - *
506 - * @return void
507 429 */
508 430 private function add_field_div_classes() {
509 431 $classes = $this->get_field_div_classes();
510 432
511 - if ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && strpos( $this->html, '[error_class]' ) === false ) {
433 + if ( $this->field_obj->get_field_column( 'type' ) === 'html' && strpos( $this->html, '[error_class]' ) === false ) {
512 434 // there is no error_class shortcode for HTML fields
513 435 $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . esc_attr( $classes ), $this->html );
514 - return;
515 436 }
516 437
517 438 $this->html = str_replace( '[error_class]', esc_attr( $classes ), $this->html );
518 439 }
@@ -529,9 +450,8 @@
529 450 $classes = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? ' frm_blank_field' : '';
530 451
531 452 // Add label position class
532 453 $settings = $this->field_obj->display_field_settings();
533 -
534 454 if ( isset( $settings['label_position'] ) && $settings['label_position'] ) {
535 455 $label_position = $this->field_obj->get_field_column( 'label' );
536 456 $classes .= ' frm_' . $label_position . '_container';
537 457
@@ -542,14 +462,12 @@
542 462 }
543 463
544 464 // Add CSS layout classes
545 465 $extra_classes = $this->field_obj->get_field_column( 'classes' );
546 -
547 466 if ( ! empty( $extra_classes ) ) {
548 467 if ( ! strpos( $this->html, 'frm_form_field ' ) ) {
549 468 $classes .= ' frm_form_field';
550 469 }
551 -
552 470 $classes .= ' ' . $extra_classes;
553 471 }
554 472
555 473 $classes .= $this->field_obj->get_container_class();
@@ -566,10 +484,8 @@
566 484 /**
567 485 * This filters shortcodes in the field HTML
568 486 *
569 487 * @since 3.0
570 - *
571 - * @return void
572 488 */
573 489 private function process_wp_shortcodes() {
574 490 if ( apply_filters( 'frm_do_html_shortcodes', true ) ) {
575 491 $this->html = do_shortcode( $this->html );
@@ -579,9 +495,8 @@
579 495 /**
580 496 * Adds multiple input attributes.
581 497 *
582 498 * @since 6.4.1
583 - *
584 499 * @return void
585 500 */
586 501 private function add_multiple_input_attributes() {
587 502 $field_type = $this->field_obj->get_field_column( 'type' );
@@ -607,13 +522,8 @@
607 522
608 523 // Add 'aria-required' attribute to the field if required.
609 524 if ( $is_radio && '1' === $field['required'] ) {
610 525 $attributes['aria-required'] = 'true';
611 - }
612 -
613 - // Add 'aria-invalid' attribute to the group if there are errors.
614 - if ( isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) {
615 - $attributes['aria-invalid'] = 'true';
616 526 }
617 527
618 528 // Concatenate attributes into a string, and replace the role="group" in the HTML with the attributes string.
619 529 $html_attributes = FrmAppHelper::array_to_html_params( $attributes );