PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.23
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.23
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/controllers/FrmFieldsController.php +78 -143 6.296.23 View file →
@@ -18,10 +18,9 @@
18 18
19 19 // Javascript may be included in some field settings.
20 20 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
21 21 $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array();
22 -
23 - if ( ! $fields ) {
22 + if ( empty( $fields ) ) {
24 23 wp_die();
25 24 }
26 25
27 26 $_GET['page'] = 'formidable';
@@ -34,11 +33,10 @@
34 33
35 34 foreach ( $fields as $field ) {
36 35 $field = htmlspecialchars_decode( nl2br( $field ) );
37 36 $field = json_decode( $field );
38 -
39 37 if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
40 - // This field may have already been loaded
38 + // this field may have already been loaded
41 39 continue;
42 40 }
43 41
44 42 if ( ! isset( $field->value ) ) {
@@ -49,10 +47,11 @@
49 47 $field->default_value = json_decode( json_encode( $field->default_value ), true );
50 48
51 49 ob_start();
52 50 self::load_single_field( $field, $values );
53 - $field_html[ absint( $field->id ) ] = ob_get_clean();
54 - }//end foreach
51 + $field_html[ absint( $field->id ) ] = ob_get_contents();
52 + ob_end_clean();
53 + }
55 54
56 55 echo json_encode( $field_html );
57 56
58 57 wp_die();
@@ -72,9 +71,9 @@
72 71 do_action( 'frm_before_create_field', $field_type, $form_id );
73 72
74 73 $field = self::include_new_field( $field_type, $form_id, $field_options );
75 74
76 - // This hook will allow for multiple fields to be added at once
75 + // this hook will allow for multiple fields to be added at once
77 76 do_action( 'frm_after_field_created', $field, $form_id );
78 77
79 78 wp_die();
80 79 }
@@ -90,9 +89,9 @@
90 89 */
91 90 public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
92 91 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
93 92
94 - if ( $field_options ) {
93 + if ( ! empty( $field_options ) ) {
95 94 $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
96 95 }
97 96
98 97 // When a new field is added to the form, flag it as draft and hide it from the front-end.
@@ -107,15 +106,15 @@
107 106 if ( ! $field_id ) {
108 107 return false;
109 108 }
110 109
111 - $field = self::get_field_array_from_id( $field_id );
110 + $field = self::get_field_array_from_id( $field_id );
111 +
112 112 $values = array();
113 -
114 113 if ( FrmAppHelper::pro_is_installed() ) {
115 114 $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
116 - $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
117 115
116 + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
118 117 if ( $parent_form_id ) {
119 118 $field['parent_form_id'] = $parent_form_id;
120 119 }
121 120 }
@@ -128,10 +127,11 @@
128 127 public static function duplicate() {
129 128 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 129 check_ajax_referer( 'frm_ajax', 'nonce' );
131 130
132 - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
133 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
131 + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
132 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
133 +
134 134 $new_field = FrmField::duplicate_single_field( $field_id, $form_id );
135 135
136 136 if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) {
137 137 self::load_single_field( $new_field['field_id'], $new_field['values'] );
@@ -148,8 +148,9 @@
148 148 * @return array
149 149 */
150 150 public static function get_field_array_from_id( $field_id ) {
151 151 $field = FrmField::getOne( $field_id );
152 +
152 153 return FrmFieldsHelper::setup_edit_vars( $field );
153 154 }
154 155
155 156 /**
@@ -154,13 +155,11 @@
154 155
155 156 /**
156 157 * @since 3.0
157 158 *
158 - * @param array|int|object|string $field_object
159 - * @param array $values
160 - * @param int $form_id
161 - *
162 - * @return void
159 + * @param array|int|object $field_object
160 + * @param array $values
161 + * @param int $form_id
163 162 */
164 163 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
165 164 global $frm_vars;
166 165 $frm_vars['is_admin'] = true;
@@ -171,10 +170,11 @@
171 170 $field = $field_object;
172 171 $field_object = FrmField::getOne( $field['id'] );
173 172 }
174 173
175 - $field_obj = FrmFieldFactory::get_field_factory( $field_object );
176 - $display = self::display_field_options( array(), $field_obj );
174 + $field_obj = FrmFieldFactory::get_field_factory( $field_object );
175 + $display = self::display_field_options( array(), $field_obj );
176 +
177 177 $ajax_loading = ! empty( $values['ajax_load'] );
178 178 $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
179 179
180 180 if ( $ajax_loading && $ajax_this_field ) {
@@ -183,9 +183,9 @@
183 183 return;
184 184 }
185 185
186 186 if ( ! isset( $field ) && is_object( $field_object ) ) {
187 - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id;
187 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
188 188 $field = FrmFieldsHelper::setup_edit_vars( $field_object );
189 189 }
190 190
191 191 /**
@@ -210,9 +210,8 @@
210 210 *
211 211 * @param array $field
212 212 * @param array $display
213 213 * @param FrmFieldType $field_info
214 - *
215 214 * @return string
216 215 */
217 216 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
218 217 $li_classes = $field_info->form_builder_classes( $display['type'] );
@@ -224,9 +223,9 @@
224 223
225 224 $li_classes .= 'frmend';
226 225
227 226 if ( $field ) {
228 - return apply_filters( 'frm_build_field_class', $li_classes, $field );
227 + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
229 228 }
230 229
231 230 return $li_classes;
232 231 }
@@ -260,9 +259,8 @@
260 259 *
261 260 * @since 6.8.4
262 261 *
263 262 * @param array $bulk_edit_types
264 - *
265 263 * @return array
266 264 */
267 265 $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
268 266
@@ -270,19 +268,18 @@
270 268 return;
271 269 }
272 270
273 271 $field = FrmFieldsHelper::setup_edit_vars( $field );
272 + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
273 + $opts = explode( "\n", rtrim( $opts, "\n" ) );
274 + $opts = array_map( 'trim', $opts );
274 275
275 - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
276 - $opts = explode( "\n", rtrim( $opts, "\n" ) );
277 - $opts = array_map( 'trim', $opts );
278 -
279 276 $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
280 277 $field['separate_value'] = $separate === 'true';
281 278
282 279 if ( $field['separate_value'] ) {
283 280 foreach ( $opts as $opt_key => $opt ) {
284 - if ( str_contains( $opt, '|' ) ) {
281 + if ( strpos( $opt, '|' ) !== false ) {
285 282 $vals = explode( '|', $opt );
286 283 $opts[ $opt_key ] = array(
287 284 'label' => trim( $vals[0] ),
288 285 'value' => trim( $vals[1] ),
@@ -293,11 +290,10 @@
293 290 }
294 291 }
295 292
296 293 // Keep other options after bulk update.
297 - if ( ! empty( $field['field_options']['other'] ) ) {
294 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
298 295 $other_array = array();
299 -
300 296 foreach ( $field['options'] as $opt_key => $opt ) {
301 297 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
302 298 $other_array[ $opt_key ] = $opt;
303 299 }
@@ -302,10 +298,9 @@
302 298 $other_array[ $opt_key ] = $opt;
303 299 }
304 300 unset( $opt_key, $opt );
305 301 }
306 -
307 - if ( $other_array ) {
302 + if ( ! empty( $other_array ) ) {
308 303 $opts = array_merge( $opts, $other_array );
309 304 }
310 305 }
311 306
@@ -319,9 +314,8 @@
319 314 /**
320 315 * @since 4.0
321 316 *
322 317 * @param array $atts - Includes field array, field_obj, display array, values array.
323 - *
324 318 * @return void
325 319 */
326 320 public static function load_single_field_settings( $atts ) {
327 321 $field = $atts['field'];
@@ -347,9 +341,9 @@
347 341 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
348 342 // Add fallback for an add-on field type that has been deactivated.
349 343 $all_field_types[ $field['type'] ] = array(
350 344 'name' => ucfirst( $field['type'] ),
351 - 'icon' => 'frmfont frm_pencil_icon',
345 + 'icon' => 'frm_icon_font frm_pencil_icon',
352 346 );
353 347 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
354 348 // Fallback for fields added in a more basic way.
355 349 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -355,9 +349,8 @@
355 349 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
356 350 }
357 351
358 352 $type_name = $all_field_types[ $field['type'] ]['name'];
359 -
360 353 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
361 354 $type_name = $all_field_types['divider|repeat']['name'];
362 355 }
363 356
@@ -390,9 +383,8 @@
390 383 * @since 4.0
391 384 *
392 385 * @param array $field
393 386 * @param array $atts
394 - *
395 387 * @return array
396 388 */
397 389 private static function default_value_types( $field, $atts ) {
398 390 $types = array(
@@ -397,33 +389,31 @@
397 389 private static function default_value_types( $field, $atts ) {
398 390 $types = array(
399 391 'default_value' => array(
400 392 'class' => '',
401 - 'icon' => 'frmfont frm_text2_icon',
402 - 'title' => __( 'Default Value', 'formidable' ),
393 + 'icon' => 'frm_icon_font frm_text2_icon',
394 + 'title' => __( 'Default Value (Text)', 'formidable' ),
403 395 'data' => array(
404 396 'frmshow' => '#default-value-for-',
405 397 ),
406 398 ),
407 399 'calc' => array(
408 - 'class' => 'frm_show_upgrade frm_noallow',
409 - 'title' => __( 'Calculate Value', 'formidable' ),
410 - 'icon' => 'frmfont frm_calculator_icon',
411 - 'data' => array(
400 + 'class' => 'frm_show_upgrade frm_noallow',
401 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
402 + 'icon' => 'frm_icon_font frm_calculator_icon',
403 + 'data' => array(
412 404 'medium' => 'calculations',
413 405 'upgrade' => __( 'Calculator forms', 'formidable' ),
414 406 ),
415 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
416 407 ),
417 408 'get_values_field' => array(
418 - 'class' => 'frm_show_upgrade frm_noallow',
419 - 'title' => __( 'Lookup', 'formidable' ),
420 - 'icon' => 'frmfont frm_search_icon',
421 - 'data' => array(
409 + 'class' => 'frm_show_upgrade frm_noallow',
410 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
411 + 'icon' => 'frm_icon_font frm_search_icon',
412 + 'data' => array(
422 413 'medium' => 'lookup',
423 414 'upgrade' => __( 'Lookup fields', 'formidable' ),
424 415 ),
425 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
426 416 ),
427 417 );
428 418
429 419 $types = apply_filters( 'frm_default_value_types', $types, $atts );
@@ -431,13 +421,11 @@
431 421 // Set active class.
432 422 $settings = array_keys( $types );
433 423 $active = 'default_value';
434 424
435 - if ( FrmAppHelper::pro_is_connected() ) {
436 - foreach ( $settings as $type ) {
437 - if ( ! empty( $field[ $type ] ) ) {
438 - $active = $type;
439 - }
425 + foreach ( $settings as $type ) {
426 + if ( ! empty( $field[ $type ] ) ) {
427 + $active = $type;
440 428 }
441 429 }
442 430
443 431 $types[ $active ]['class'] .= ' current';
@@ -447,9 +435,8 @@
447 435 }
448 436
449 437 /**
450 438 * @param string $type
451 - *
452 439 * @return string
453 440 */
454 441 public static function change_type( $type ) {
455 442 $type_switch = array(
@@ -459,9 +446,8 @@
459 446 'rte' => 'textarea',
460 447 'website' => 'url',
461 448 'image' => 'url',
462 449 );
463 -
464 450 if ( isset( $type_switch[ $type ] ) ) {
465 451 $type = $type_switch[ $type ];
466 452 }
467 453
@@ -469,9 +455,13 @@
469 455 // We want to keep credit_card types as credit card types for Stripe Lite.
470 456 // The credit_card key is set for backward compatibility.
471 457 unset( $pro_fields['credit_card'] );
472 458
473 - return array_key_exists( $type, $pro_fields ) ? 'text' : $type;
459 + if ( array_key_exists( $type, $pro_fields ) ) {
460 + $type = 'text';
461 + }
462 +
463 + return $type;
474 464 }
475 465
476 466 /**
477 467 * @param array $settings
@@ -496,9 +486,8 @@
496 486 * @since 3.0
497 487 *
498 488 * @param array $field Field data.
499 489 * @param bool $is_hidden Whether the format option should be hidden.
500 - *
501 490 * @return void
502 491 */
503 492 public static function show_format_option( $field, $is_hidden = false ) {
504 493 $attributes = array(
@@ -512,14 +501,8 @@
512 501
513 502 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
514 503 }
515 504
516 - /**
517 - * @param array $field
518 - * @param bool $echo
519 - *
520 - * @return string
521 - */
522 505 public static function input_html( $field, $echo = true ) {
523 506 $class = array();
524 507 self::add_input_classes( $field, $class );
525 508
@@ -548,9 +531,8 @@
548 531
549 532 /**
550 533 * @param array $field
551 534 * @param array $class
552 - *
553 535 * @return void
554 536 */
555 537 private static function add_input_classes( $field, array &$class ) {
556 538 if ( ! empty( $field['input_class'] ) ) {
@@ -568,9 +550,8 @@
568 550
569 551 /**
570 552 * @param array $field
571 553 * @param array $add_html
572 - *
573 554 * @return void
574 555 */
575 556 private static function add_html_size( $field, array &$add_html ) {
576 557 $size_fields = array(
@@ -603,9 +584,8 @@
603 584
604 585 /**
605 586 * @param array $field
606 587 * @param array $add_html
607 - *
608 588 * @return void
609 589 */
610 590 private static function add_html_cols( $field, array &$add_html ) {
611 591 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -619,9 +599,9 @@
619 599 'rem' => 0.444,
620 600 'em' => 0.544,
621 601 );
622 602
623 - // Include "col" for valid html
603 + // include "col" for valid html
624 604 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
625 605
626 606 if ( ! isset( $calc[ $unit ] ) ) {
627 607 return;
@@ -626,9 +606,10 @@
626 606 if ( ! isset( $calc[ $unit ] ) ) {
627 607 return;
628 608 }
629 609
630 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
610 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
611 +
631 612 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
632 613 }
633 614
634 615 /**
@@ -633,9 +614,8 @@
633 614
634 615 /**
635 616 * @param array $field
636 617 * @param array $add_html
637 - *
638 618 * @return void
639 619 */
640 620 private static function add_html_length( $field, array &$add_html ) {
641 621 // Check for max setting and if this field accepts maxlength.
@@ -661,13 +641,11 @@
661 641 /**
662 642 * @param array $field
663 643 * @param array $add_html
664 644 * @param array $class
665 - *
666 645 * @return void
667 646 */
668 647 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
669 - // phpcs:ignore Universal.Operators.StrictComparisons
670 648 if ( $field['default_value'] != '' ) {
671 649 if ( is_array( $field['default_value'] ) ) {
672 650 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
673 651 } else {
@@ -675,12 +653,10 @@
675 653 }
676 654 }
677 655
678 656 $field['placeholder'] = self::prepare_placeholder( $field );
679 -
680 - // phpcs:ignore Universal.Operators.StrictComparisons
681 657 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
682 - // Don't include a json placeholder
658 + // don't include a json placeholder
683 659 return;
684 660 }
685 661
686 662 self::add_placeholder_to_input( $field, $add_html );
@@ -691,13 +667,14 @@
691 667 *
692 668 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
693 669 *
694 670 * @param array $field Field array.
695 - *
696 671 * @return string
697 672 */
698 673 private static function prepare_placeholder( $field ) {
699 - return $field['placeholder'] ?? '';
674 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
675 +
676 + return $placeholder;
700 677 }
701 678
702 679 /**
703 680 * If the label position is "inside",
@@ -718,17 +695,13 @@
718 695 * Maybe add a blank placeholder option before any options
719 696 * in a dropdown.
720 697 *
721 698 * @since 4.04
722 - *
723 - * @param array|object $field
724 - *
725 699 * @return bool True if placeholder was added.
726 700 */
727 701 public static function add_placeholder_to_select( $field ) {
728 702 $placeholder = FrmField::get_option( $field, 'placeholder' );
729 -
730 - if ( ! $placeholder ) {
703 + if ( empty( $placeholder ) ) {
731 704 $placeholder = self::get_default_value_from_name( $field );
732 705 }
733 706
734 707 $use_placeholder = $placeholder;
@@ -735,9 +708,8 @@
735 708 $autocomplete = FrmField::get_option( $field, 'autocom' );
736 709
737 710 if ( $autocomplete ) {
738 711 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
739 -
740 712 if ( $use_chosen ) {
741 713 $use_placeholder = '';
742 714 }
743 715 }
@@ -760,9 +732,8 @@
760 732 * Use HTML5 placeholder with js fallback.
761 733 *
762 734 * @param array $field
763 735 * @param array $add_html
764 - *
765 736 * @return void
766 737 */
767 738 private static function add_placeholder_to_input( $field, &$add_html ) {
768 739 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -772,13 +743,11 @@
772 743
773 744 /**
774 745 * @param array $field
775 746 * @param array $add_html
776 - *
777 747 * @return void
778 748 */
779 749 private static function add_frmval_to_input( $field, &$add_html ) {
780 - // phpcs:ignore Universal.Operators.StrictComparisons
781 750 if ( $field['placeholder'] != '' ) {
782 751 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
783 752
784 753 if ( 'select' === $field['type'] ) {
@@ -785,20 +754,13 @@
785 754 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
786 755 }
787 756 }
788 757
789 - // phpcs:ignore Universal.Operators.StrictComparisons
790 758 if ( $field['default_value'] != '' ) {
791 759 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
792 760 }
793 761 }
794 762
795 - /**
796 - * @param array $field
797 - * @param array $add_html
798 - *
799 - * @return void
800 - */
801 763 private static function add_validation_messages( $field, array &$add_html ) {
802 764 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
803 765
804 766 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -822,9 +784,8 @@
822 784 *
823 785 * @since 6.9
824 786 *
825 787 * @param array|object $field
826 - *
827 788 * @return array
828 789 */
829 790 private static function get_validation_data_attribute_visibility_info( $field ) {
830 791 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -854,26 +815,21 @@
854 815 * @since 5.0.03
855 816 *
856 817 * @param array $field
857 818 * @param array $add_html
858 - *
859 819 * @return void
860 820 */
861 821 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
862 822 $form = self::get_form_for_js_validation( $field );
863 -
864 823 if ( false === $form ) {
865 824 return;
866 825 }
867 826
868 827 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
869 -
870 - if ( false === $error_body ) {
871 - return;
828 + if ( false !== $error_body ) {
829 + $error_body = urlencode( $error_body );
830 + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
872 831 }
873 -
874 - $error_body = urlencode( $error_body );
875 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
876 832 }
877 833
878 834 /**
879 835 * @since 5.0.03
@@ -878,24 +834,20 @@
878 834 /**
879 835 * @since 5.0.03
880 836 *
881 837 * @param array $field
882 - *
883 838 * @return false|stdClass false if there is no form object found with JS validation active.
884 839 */
885 840 private static function get_form_for_js_validation( $field ) {
886 841 global $frm_vars;
887 -
888 842 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
889 843 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
890 844 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
891 845 }
892 -
893 846 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
894 847 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
895 848 }
896 849 }
897 -
898 850 return false;
899 851 }
900 852
901 853 /**
@@ -901,9 +853,8 @@
901 853 /**
902 854 * @param stdClass $form
903 855 * @param array $field
904 856 * @param array $errors
905 - *
906 857 * @return false|string
907 858 */
908 859 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
909 860 if ( empty( $field['custom_html'] ) ) {
@@ -911,16 +862,15 @@
911 862 }
912 863
913 864 $custom_html = $field['custom_html'];
914 865 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
915 - $start = strpos( $custom_html, '[if error]' );
916 866
867 + $start = strpos( $custom_html, '[if error]' );
917 868 if ( false === $start ) {
918 869 return false;
919 870 }
920 871
921 872 $end = strpos( $custom_html, '[/if error]' );
922 -
923 873 if ( false === $end || $end < $start ) {
924 874 return false;
925 875 }
926 876
@@ -931,9 +881,13 @@
931 881 '<div class="frm_error">[error]</div>',
932 882 '<div class="frm_error" role="alert">[error]</div>',
933 883 );
934 884
935 - return in_array( $error_body, $default_html, true ) ? false : $error_body;
885 + if ( in_array( $error_body, $default_html, true ) ) {
886 + return false;
887 + }
888 +
889 + return $error_body;
936 890 }
937 891
938 892 /**
939 893 * If 'required' is added to a conditionally hidden field, the form won't
@@ -940,16 +894,13 @@
940 894 * submit in many browsers. Check to make sure the javascript to conditionally
941 895 * remove it is present if needed.
942 896 *
943 897 * @since 3.06.01
944 - *
945 898 * @param array $field
946 899 * @param array $add_html
947 - *
948 900 * @return void
949 901 */
950 902 private static function maybe_add_html_required( $field, array &$add_html ) {
951 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
952 903 $excluded_field_types =
953 904 FrmField::is_radio( $field ) ||
954 905 FrmField::is_checkbox( $field ) ||
955 906 FrmField::is_field_type( $field, 'file' ) ||
@@ -954,9 +905,8 @@
954 905 FrmField::is_checkbox( $field ) ||
955 906 FrmField::is_field_type( $field, 'file' ) ||
956 907 FrmField::is_field_type( $field, 'nps' ) ||
957 908 FrmField::is_field_type( $field, 'scale' );
958 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
959 909
960 910 if ( $excluded_field_types ) {
961 911 return;
962 912 }
@@ -966,9 +916,8 @@
966 916
967 917 /**
968 918 * @param array $field
969 919 * @param array $add_html
970 - *
971 920 * @return void
972 921 */
973 922 private static function add_shortcodes_to_html( $field, array &$add_html ) {
974 923 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -979,11 +928,10 @@
979 928 unset( $field['shortcodes']['autocomplete'] );
980 929 }
981 930
982 931 foreach ( $field['shortcodes'] as $k => $v ) {
983 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
932 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
984 933 $subfield_name = $field['subfield_name'];
985 -
986 934 if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
987 935 continue;
988 936 }
989 937 // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
@@ -990,14 +938,13 @@
990 938 $k = 'aria-invalid';
991 939 $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
992 940 unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
993 941 }
994 -
995 942 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
996 943 continue;
997 944 }
998 945
999 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
946 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1000 947 $add_html[] = $v;
1001 948 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1002 949 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1003 950 } else {
@@ -1013,9 +960,8 @@
1013 960 *
1014 961 * @since 6.11.2
1015 962 *
1016 963 * @param string $key The option key.
1017 - *
1018 964 * @return bool
1019 965 */
1020 966 private static function should_allow_input_attribute( $key ) {
1021 967 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1030,9 +976,8 @@
1030 976 * @since 3.0
1031 977 *
1032 978 * @param array $field
1033 979 * @param array $add_html
1034 - *
1035 980 * @return void
1036 981 */
1037 982 private static function add_pattern_attribute( $field, array &$add_html ) {
1038 983 $format_value = FrmField::get_option( $field, 'format' );
@@ -1038,31 +983,22 @@
1038 983 $format_value = FrmField::get_option( $field, 'format' );
1039 984 $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
1040 985 $format_field = FrmField::is_field_type( $field, 'text' );
1041 986
1042 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1043 - return;
987 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
988 + $format = FrmEntryValidate::phone_format( $field );
989 + $format = substr( $format, 2, - 1 );
990 +
991 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1044 992 }
1045 -
1046 - $format = FrmEntryValidate::phone_format( $field );
1047 - $format = substr( $format, 2, - 1 );
1048 -
1049 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1050 993 }
1051 994
1052 - /**
1053 - * @param mixed $opt
1054 - * @param mixed $opt_key
1055 - * @param array|object $field
1056 - *
1057 - * @return mixed
1058 - */
1059 995 public static function check_value( $opt, $opt_key, $field ) {
1060 996 if ( is_array( $opt ) ) {
1061 997 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1062 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
998 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1063 999 } else {
1064 - $opt = $opt['label'] ?? reset( $opt );
1000 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1065 1001 }
1066 1002 }
1067 1003
1068 1004 return $opt;
@@ -1067,13 +1003,12 @@
1067 1003
1068 1004 return $opt;
1069 1005 }
1070 1006
1071 - /**
1072 - * @param mixed $opt
1073 - *
1074 - * @return mixed
1075 - */
1076 1007 public static function check_label( $opt ) {
1077 - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt;
1008 + if ( is_array( $opt ) ) {
1009 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1010 + }
1011 +
1012 + return $opt;
1078 1013 }
1079 1014 }