PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.19
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.19
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 +19 -105 6.276.19 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,15 +180,12 @@
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' ) );
230 - // phpcs:ignore Universal.Operators.StrictComparisons
231 188 FrmShortcodeHelper::remove_inline_conditions( ( $description && $description != '' ), 'description', $description, $this->html );
232 189 }
233 190
234 191 /**
@@ -235,15 +192,11 @@
235 192 * Add an ID to the description for aria-describedby.
236 193 * This ID was added to the HTML in v3.0.
237 194 *
238 195 * @since 3.0
239 - *
240 - * @return void
241 196 */
242 197 private function maybe_add_description_id() {
243 198 $description = $this->field_obj->get_field_column( 'description' );
244 -
245 - // phpcs:ignore Universal.Operators.StrictComparisons
246 199 if ( $description != '' ) {
247 200 $this->add_element_id( 'description', 'desc' );
248 201 }
249 202 }
@@ -251,17 +204,11 @@
251 204 /**
252 205 * Insert an ID if it doesn't exist.
253 206 *
254 207 * @since 3.06.02
255 - *
256 - * @param string $param
257 - * @param string $id
258 - *
259 - * @return void
260 208 */
261 209 private function add_element_id( $param, $id ) {
262 210 preg_match_all( '/(\[if\s+' . $param . '\])(.*?)(\[\/if\s+' . $param . '\])/mis', $this->html, $inner_html );
263 -
264 211 if ( ! isset( $inner_html[2] ) ) {
265 212 return;
266 213 }
267 214
@@ -269,10 +216,9 @@
269 216 $inner_html[2] = $inner_html[2][0];
270 217 }
271 218
272 219 if ( is_string( $inner_html[2] ) ) {
273 - $has_id = str_contains( $inner_html[2], ' id=' );
274 -
220 + $has_id = strpos( $inner_html[2], ' id=' );
275 221 if ( ! $has_id ) {
276 222 $id = 'frm_' . $id . '_' . $this->html_id;
277 223 $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html );
278 224 }
@@ -280,19 +226,16 @@
280 226 }
281 227
282 228 /**
283 229 * @since 3.0
284 - *
285 - * @return void
286 230 */
287 231 private function replace_error_shortcode() {
288 232 $this->maybe_add_error_id();
289 - $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;
290 234
291 - if ( $error && ! str_contains( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) {
235 + if ( ! empty( $error ) && false === strpos( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) {
292 236 $error_body = self::get_error_body( $this->html );
293 -
294 - if ( is_string( $error_body ) && ! str_contains( $error_body, 'role=' ) ) {
237 + if ( is_string( $error_body ) && false === strpos( $error_body, 'role=' ) ) {
295 238 $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 );
296 239 $this->html = str_replace( '[if error]' . $error_body . '[/if error]', '[if error]' . $new_error_body . '[/if error]', $this->html );
297 240 }
298 241 }
@@ -303,25 +246,23 @@
303 246 /**
304 247 * Pull the HTML between [if error] and [/if error] shortcodes.
305 248 *
306 249 * @param string $html
307 - *
308 250 * @return false|string
309 251 */
310 252 private static function get_error_body( $html ) {
311 253 $start = strpos( $html, '[if error]' );
312 -
313 254 if ( false === $start ) {
314 255 return false;
315 256 }
316 257
317 258 $end = strpos( $html, '[/if error]', $start );
318 -
319 259 if ( false === $end ) {
320 260 return false;
321 261 }
322 262
323 - return substr( $html, $start + 10, $end - $start - 10 );
263 + $error_body = substr( $html, $start + 10, $end - $start - 10 );
264 + return $error_body;
324 265 }
325 266
326 267 /**
327 268 * Add an ID to the error message for aria-describedby.
@@ -327,10 +268,8 @@
327 268 * Add an ID to the error message for aria-describedby.
328 269 * This ID was added to the HTML in v3.06.02.
329 270 *
330 271 * @since 3.06.02
331 - *
332 - * @return void
333 272 */
334 273 private function maybe_add_error_id() {
335 274 if ( ! isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) {
336 275 return;
@@ -342,10 +281,8 @@
342 281 /**
343 282 * Replace [required_class]
344 283 *
345 284 * @since 3.0
346 - *
347 - * @return void
348 285 */
349 286 private function replace_required_class() {
350 287 $required_class = FrmField::is_required( $this->field_obj->get_field() ) ? ' frm_required_field' : '';
351 288 $this->html = str_replace( '[required_class]', $required_class, $this->html );
@@ -352,10 +289,8 @@
352 289 }
353 290
354 291 /**
355 292 * @since 3.0
356 - *
357 - * @return void
358 293 */
359 294 private function replace_form_shortcodes() {
360 295 if ( ! empty( $this->form ) ) {
361 296 $form = (array) $this->form;
@@ -369,16 +304,14 @@
369 304 }
370 305
371 306 /**
372 307 * @since 3.0
373 - *
374 - * @return void
375 308 */
376 309 public function replace_shortcodes_after_input() {
377 310 $this->html .= "\n";
378 311
379 312 // Stop html filtering on confirmation field to prevent loop
380 - if ( $this->field_obj->get_field_column( 'conf_field' ) !== 'stop' ) {
313 + if ( $this->field_obj->get_field_column( 'conf_field' ) != 'stop' ) {
381 314 $this->filter_for_more_shortcodes();
382 315 }
383 316 }
384 317
@@ -383,10 +316,8 @@
383 316 }
384 317
385 318 /**
386 319 * @since 3.0
387 - *
388 - * @return void
389 320 */
390 321 private function filter_for_more_shortcodes() {
391 322 $atts = $this->pass_args;
392 323
@@ -405,13 +336,11 @@
405 336 *
406 337 * @since 3.0
407 338 *
408 339 * @param string $html
409 - *
410 - * @return void
411 340 */
412 341 public function remove_collapse_shortcode( &$html ) {
413 - if ( str_contains( $html, '[collapse_this]' ) ) {
342 + if ( strpos( $html, '[collapse_this]' ) ) {
414 343 $html = str_replace( '[collapse_this]', '', $html );
415 344 }
416 345 }
417 346
@@ -416,10 +345,8 @@
416 345 }
417 346
418 347 /**
419 348 * @since 3.0
420 - *
421 - * @return void
422 349 */
423 350 private function replace_shortcodes_with_atts() {
424 351 preg_match_all( "/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $this->html, $shortcodes, PREG_PATTERN_ORDER );
425 352
@@ -425,10 +352,11 @@
425 352
426 353 foreach ( $shortcodes[0] as $short_key => $tag ) {
427 354 $shortcode_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
428 355 $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
429 - $replace_with = '';
430 356
357 + $replace_with = '';
358 +
431 359 if ( $tag === 'deletelink' && FrmAppHelper::pro_is_installed() ) {
432 360 $replace_with = FrmProEntriesController::entry_delete_link( $shortcode_atts );
433 361 } elseif ( $tag === 'input' ) {
434 362 $replace_with = $this->replace_input_shortcode( $shortcode_atts );
@@ -444,8 +372,9 @@
444 372 * @return string
445 373 */
446 374 private function replace_input_shortcode( $shortcode_atts ) {
447 375 $shortcode_atts = $this->prepare_input_shortcode_atts( $shortcode_atts );
376 +
448 377 return $this->field_obj->include_front_field_input( $this->pass_args, $shortcode_atts );
449 378 }
450 379
451 380 /**
@@ -457,9 +386,9 @@
457 386 if ( isset( $shortcode_atts['opt'] ) ) {
458 387 --$shortcode_atts['opt'];
459 388 }
460 389
461 - $field_class = $shortcode_atts['class'] ?? '';
390 + $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : '';
462 391 $this->field_obj->set_field_column( 'input_class', $field_class );
463 392
464 393 if ( isset( $shortcode_atts['class'] ) ) {
465 394 unset( $shortcode_atts['class'] );
@@ -476,10 +405,8 @@
476 405 * Add the label position class into the HTML
477 406 * If the label position is inside, add a class to show the label if the field has a value.
478 407 *
479 408 * @since 3.0
480 - *
481 - * @return void
482 409 */
483 410 private function add_class_to_label() {
484 411 $label_class = $this->field_obj->get_label_class();
485 412 $this->html = str_replace( '[label_position]', $label_class, $this->html );
@@ -488,10 +415,8 @@
488 415 /**
489 416 * Replace [entry_key]
490 417 *
491 418 * @since 3.0
492 - *
493 - * @return void
494 419 */
495 420 private function replace_entry_key() {
496 421 $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' );
497 422 $this->html = str_replace( '[entry_key]', $entry_key, $this->html );
@@ -500,15 +425,13 @@
500 425 /**
501 426 * Add classes to a field div
502 427 *
503 428 * @since 3.0
504 - *
505 - * @return void
506 429 */
507 430 private function add_field_div_classes() {
508 431 $classes = $this->get_field_div_classes();
509 432
510 - if ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && ! str_contains( $this->html, '[error_class]' ) ) {
433 + if ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && strpos( $this->html, '[error_class]' ) === false ) {
511 434 // there is no error_class shortcode for HTML fields
512 435 $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . esc_attr( $classes ), $this->html );
513 436 return;
514 437 }
@@ -528,10 +451,9 @@
528 451 $classes = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? ' frm_blank_field' : '';
529 452
530 453 // Add label position class
531 454 $settings = $this->field_obj->display_field_settings();
532 -
533 - if ( ! empty( $settings['label_position'] ) ) {
455 + if ( isset( $settings['label_position'] ) && $settings['label_position'] ) {
534 456 $label_position = $this->field_obj->get_field_column( 'label' );
535 457 $classes .= ' frm_' . $label_position . '_container';
536 458
537 459 // Add class if field has value, to be used for floating label styling.
@@ -541,14 +463,12 @@
541 463 }
542 464
543 465 // Add CSS layout classes
544 466 $extra_classes = $this->field_obj->get_field_column( 'classes' );
545 -
546 - if ( $extra_classes ) {
547 - if ( ! str_contains( $this->html, 'frm_form_field ' ) ) {
467 + if ( ! empty( $extra_classes ) ) {
468 + if ( ! strpos( $this->html, 'frm_form_field ' ) ) {
548 469 $classes .= ' frm_form_field';
549 470 }
550 -
551 471 $classes .= ' ' . $extra_classes;
552 472 }
553 473
554 474 $classes .= $this->field_obj->get_container_class();
@@ -556,9 +476,11 @@
556 476 // Get additional classes
557 477 $classes = apply_filters( 'frm_field_div_classes', $classes, $this->field_obj->get_field(), array( 'field_id' => $this->field_id ) );
558 478
559 479 // Remove unexpected characters from class.
560 - return implode( ' ', array_map( 'FrmFormsHelper::sanitize_layout_class', explode( ' ', $classes ) ) );
480 + $classes = implode( ' ', array_map( 'FrmFormsHelper::sanitize_layout_class', explode( ' ', $classes ) ) );
481 +
482 + return $classes;
561 483 }
562 484
563 485 /**
564 486 * This filters shortcodes in the field HTML
@@ -563,10 +485,8 @@
563 485 /**
564 486 * This filters shortcodes in the field HTML
565 487 *
566 488 * @since 3.0
567 - *
568 - * @return void
569 489 */
570 490 private function process_wp_shortcodes() {
571 491 if ( apply_filters( 'frm_do_html_shortcodes', true ) ) {
572 492 $this->html = do_shortcode( $this->html );
@@ -576,9 +496,8 @@
576 496 /**
577 497 * Adds multiple input attributes.
578 498 *
579 499 * @since 6.4.1
580 - *
581 500 * @return void
582 501 */
583 502 private function add_multiple_input_attributes() {
584 503 $field_type = $this->field_obj->get_field_column( 'type' );
@@ -604,13 +523,8 @@
604 523
605 524 // Add 'aria-required' attribute to the field if required.
606 525 if ( $is_radio && '1' === $field['required'] ) {
607 526 $attributes['aria-required'] = 'true';
608 - }
609 -
610 - // Add 'aria-invalid' attribute to the group if there are errors.
611 - if ( isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) {
612 - $attributes['aria-invalid'] = 'true';
613 527 }
614 528
615 529 // Concatenate attributes into a string, and replace the role="group" in the HTML with the attributes string.
616 530 $html_attributes = FrmAppHelper::array_to_html_params( $attributes );