PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.18
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.18
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 +56 -141 6.276.18 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,9 +33,8 @@
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 38 // this field may have already been loaded
41 39 continue;
42 40 }
@@ -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();
@@ -64,15 +63,14 @@
64 63 public static function create() {
65 64 FrmAppHelper::permission_check( 'frm_edit_forms' );
66 65 check_ajax_referer( 'frm_ajax', 'nonce' );
67 66
68 - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
69 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
70 - $field_options = FrmAppHelper::get_post_param( 'field_options', array(), 'wp_kses_post' );
67 + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
68 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
71 69
72 70 do_action( 'frm_before_create_field', $field_type, $form_id );
73 71
74 - $field = self::include_new_field( $field_type, $form_id, $field_options );
72 + $field = self::include_new_field( $field_type, $form_id );
75 73
76 74 // this hook will allow for multiple fields to be added at once
77 75 do_action( 'frm_after_field_created', $field, $form_id );
78 76
@@ -83,19 +81,14 @@
83 81 * Set up and create a new field
84 82 *
85 83 * @param string $field_type
86 84 * @param int $form_id
87 - * @param array $field_options
88 85 *
89 86 * @return array|false
90 87 */
91 - public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
88 + public static function include_new_field( $field_type, $form_id ) {
92 89 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
93 90
94 - if ( $field_options ) {
95 - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
96 - }
97 -
98 91 // When a new field is added to the form, flag it as draft and hide it from the front-end.
99 92 $field_values['field_options']['draft'] = 1;
100 93
101 94 /**
@@ -107,15 +100,15 @@
107 100 if ( ! $field_id ) {
108 101 return false;
109 102 }
110 103
111 - $field = self::get_field_array_from_id( $field_id );
104 + $field = self::get_field_array_from_id( $field_id );
105 +
112 106 $values = array();
113 -
114 107 if ( FrmAppHelper::pro_is_installed() ) {
115 108 $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 109
110 + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
118 111 if ( $parent_form_id ) {
119 112 $field['parent_form_id'] = $parent_form_id;
120 113 }
121 114 }
@@ -128,10 +121,11 @@
128 121 public static function duplicate() {
129 122 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 123 check_ajax_referer( 'frm_ajax', 'nonce' );
131 124
132 - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
133 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
125 + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
126 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
127 +
134 128 $new_field = FrmField::duplicate_single_field( $field_id, $form_id );
135 129
136 130 if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) {
137 131 self::load_single_field( $new_field['field_id'], $new_field['values'] );
@@ -148,8 +142,9 @@
148 142 * @return array
149 143 */
150 144 public static function get_field_array_from_id( $field_id ) {
151 145 $field = FrmField::getOne( $field_id );
146 +
152 147 return FrmFieldsHelper::setup_edit_vars( $field );
153 148 }
154 149
155 150 /**
@@ -157,10 +152,8 @@
157 152 *
158 153 * @param array|int|object $field_object
159 154 * @param array $values
160 155 * @param int $form_id
161 - *
162 - * @return void
163 156 */
164 157 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
165 158 global $frm_vars;
166 159 $frm_vars['is_admin'] = true;
@@ -171,10 +164,11 @@
171 164 $field = $field_object;
172 165 $field_object = FrmField::getOne( $field['id'] );
173 166 }
174 167
175 - $field_obj = FrmFieldFactory::get_field_factory( $field_object );
176 - $display = self::display_field_options( array(), $field_obj );
168 + $field_obj = FrmFieldFactory::get_field_factory( $field_object );
169 + $display = self::display_field_options( array(), $field_obj );
170 +
177 171 $ajax_loading = ! empty( $values['ajax_load'] );
178 172 $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
179 173
180 174 if ( $ajax_loading && $ajax_this_field ) {
@@ -183,23 +177,12 @@
183 177 return;
184 178 }
185 179
186 180 if ( ! isset( $field ) && is_object( $field_object ) ) {
187 - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id;
181 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
188 182 $field = FrmFieldsHelper::setup_edit_vars( $field_object );
189 183 }
190 184
191 - /**
192 - * Filter for adding extra attributes to the field container.
193 - *
194 - * @since 6.23
195 - *
196 - * @param array $extra_field_attributes
197 - * @param array $field
198 - * @param array $display
199 - */
200 - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display );
201 -
202 185 $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
203 186 $li_classes .= ' ui-state-default widgets-holder-wrap';
204 187
205 188 require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
@@ -210,9 +193,8 @@
210 193 *
211 194 * @param array $field
212 195 * @param array $display
213 196 * @param FrmFieldType $field_info
214 - *
215 197 * @return string
216 198 */
217 199 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
218 200 $li_classes = $field_info->form_builder_classes( $display['type'] );
@@ -260,9 +242,8 @@
260 242 *
261 243 * @since 6.8.4
262 244 *
263 245 * @param array $bulk_edit_types
264 - *
265 246 * @return array
266 247 */
267 248 $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
268 249
@@ -270,19 +251,18 @@
270 251 return;
271 252 }
272 253
273 254 $field = FrmFieldsHelper::setup_edit_vars( $field );
255 + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
256 + $opts = explode( "\n", rtrim( $opts, "\n" ) );
257 + $opts = array_map( 'trim', $opts );
274 258
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 259 $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
280 260 $field['separate_value'] = $separate === 'true';
281 261
282 262 if ( $field['separate_value'] ) {
283 263 foreach ( $opts as $opt_key => $opt ) {
284 - if ( str_contains( $opt, '|' ) ) {
264 + if ( strpos( $opt, '|' ) !== false ) {
285 265 $vals = explode( '|', $opt );
286 266 $opts[ $opt_key ] = array(
287 267 'label' => trim( $vals[0] ),
288 268 'value' => trim( $vals[1] ),
@@ -293,12 +273,10 @@
293 273 }
294 274 }
295 275
296 276 // Keep other options after bulk update.
297 - // phpcs:ignore Universal.Operators.StrictComparisons
298 - if ( ! empty( $field['field_options']['other'] ) ) {
277 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
299 278 $other_array = array();
300 -
301 279 foreach ( $field['options'] as $opt_key => $opt ) {
302 280 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
303 281 $other_array[ $opt_key ] = $opt;
304 282 }
@@ -303,10 +281,9 @@
303 281 $other_array[ $opt_key ] = $opt;
304 282 }
305 283 unset( $opt_key, $opt );
306 284 }
307 -
308 - if ( $other_array ) {
285 + if ( ! empty( $other_array ) ) {
309 286 $opts = array_merge( $opts, $other_array );
310 287 }
311 288 }
312 289
@@ -320,9 +297,8 @@
320 297 /**
321 298 * @since 4.0
322 299 *
323 300 * @param array $atts - Includes field array, field_obj, display array, values array.
324 - *
325 301 * @return void
326 302 */
327 303 public static function load_single_field_settings( $atts ) {
328 304 $field = $atts['field'];
@@ -348,9 +324,9 @@
348 324 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
349 325 // Add fallback for an add-on field type that has been deactivated.
350 326 $all_field_types[ $field['type'] ] = array(
351 327 'name' => ucfirst( $field['type'] ),
352 - 'icon' => 'frmfont frm_pencil_icon',
328 + 'icon' => 'frm_icon_font frm_pencil_icon',
353 329 );
354 330 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
355 331 // Fallback for fields added in a more basic way.
356 332 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -356,9 +332,8 @@
356 332 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
357 333 }
358 334
359 335 $type_name = $all_field_types[ $field['type'] ]['name'];
360 -
361 336 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
362 337 $type_name = $all_field_types['divider|repeat']['name'];
363 338 }
364 339
@@ -391,9 +366,8 @@
391 366 * @since 4.0
392 367 *
393 368 * @param array $field
394 369 * @param array $atts
395 - *
396 370 * @return array
397 371 */
398 372 private static function default_value_types( $field, $atts ) {
399 373 $types = array(
@@ -398,33 +372,31 @@
398 372 private static function default_value_types( $field, $atts ) {
399 373 $types = array(
400 374 'default_value' => array(
401 375 'class' => '',
402 - 'icon' => 'frmfont frm_text2_icon',
403 - 'title' => __( 'Default Value', 'formidable' ),
376 + 'icon' => 'frm_icon_font frm_text2_icon',
377 + 'title' => __( 'Default Value (Text)', 'formidable' ),
404 378 'data' => array(
405 379 'frmshow' => '#default-value-for-',
406 380 ),
407 381 ),
408 382 'calc' => array(
409 - 'class' => 'frm_show_upgrade frm_noallow',
410 - 'title' => __( 'Calculate Value', 'formidable' ),
411 - 'icon' => 'frmfont frm_calculator_icon',
412 - 'data' => array(
383 + 'class' => 'frm_show_upgrade frm_noallow',
384 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
385 + 'icon' => 'frm_icon_font frm_calculator_icon',
386 + 'data' => array(
413 387 'medium' => 'calculations',
414 388 'upgrade' => __( 'Calculator forms', 'formidable' ),
415 389 ),
416 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
417 390 ),
418 391 'get_values_field' => array(
419 - 'class' => 'frm_show_upgrade frm_noallow',
420 - 'title' => __( 'Lookup', 'formidable' ),
421 - 'icon' => 'frmfont frm_search_icon',
422 - 'data' => array(
392 + 'class' => 'frm_show_upgrade frm_noallow',
393 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
394 + 'icon' => 'frm_icon_font frm_search_icon',
395 + 'data' => array(
423 396 'medium' => 'lookup',
424 397 'upgrade' => __( 'Lookup fields', 'formidable' ),
425 398 ),
426 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
427 399 ),
428 400 );
429 401
430 402 $types = apply_filters( 'frm_default_value_types', $types, $atts );
@@ -432,13 +404,11 @@
432 404 // Set active class.
433 405 $settings = array_keys( $types );
434 406 $active = 'default_value';
435 407
436 - if ( FrmAppHelper::pro_is_connected() ) {
437 - foreach ( $settings as $type ) {
438 - if ( ! empty( $field[ $type ] ) ) {
439 - $active = $type;
440 - }
408 + foreach ( $settings as $type ) {
409 + if ( ! empty( $field[ $type ] ) ) {
410 + $active = $type;
441 411 }
442 412 }
443 413
444 414 $types[ $active ]['class'] .= ' current';
@@ -448,9 +418,8 @@
448 418 }
449 419
450 420 /**
451 421 * @param string $type
452 - *
453 422 * @return string
454 423 */
455 424 public static function change_type( $type ) {
456 425 $type_switch = array(
@@ -460,9 +429,8 @@
460 429 'rte' => 'textarea',
461 430 'website' => 'url',
462 431 'image' => 'url',
463 432 );
464 -
465 433 if ( isset( $type_switch[ $type ] ) ) {
466 434 $type = $type_switch[ $type ];
467 435 }
468 436
@@ -501,9 +469,8 @@
501 469 * @since 3.0
502 470 *
503 471 * @param array $field Field data.
504 472 * @param bool $is_hidden Whether the format option should be hidden.
505 - *
506 473 * @return void
507 474 */
508 475 public static function show_format_option( $field, $is_hidden = false ) {
509 476 $attributes = array(
@@ -517,14 +484,8 @@
517 484
518 485 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
519 486 }
520 487
521 - /**
522 - * @param array $field
523 - * @param bool $echo
524 - *
525 - * @return string
526 - */
527 488 public static function input_html( $field, $echo = true ) {
528 489 $class = array();
529 490 self::add_input_classes( $field, $class );
530 491
@@ -553,9 +514,8 @@
553 514
554 515 /**
555 516 * @param array $field
556 517 * @param array $class
557 - *
558 518 * @return void
559 519 */
560 520 private static function add_input_classes( $field, array &$class ) {
561 521 if ( ! empty( $field['input_class'] ) ) {
@@ -573,9 +533,8 @@
573 533
574 534 /**
575 535 * @param array $field
576 536 * @param array $add_html
577 - *
578 537 * @return void
579 538 */
580 539 private static function add_html_size( $field, array &$add_html ) {
581 540 $size_fields = array(
@@ -608,9 +567,8 @@
608 567
609 568 /**
610 569 * @param array $field
611 570 * @param array $add_html
612 - *
613 571 * @return void
614 572 */
615 573 private static function add_html_cols( $field, array &$add_html ) {
616 574 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -631,9 +589,10 @@
631 589 if ( ! isset( $calc[ $unit ] ) ) {
632 590 return;
633 591 }
634 592
635 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
593 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
594 +
636 595 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
637 596 }
638 597
639 598 /**
@@ -638,9 +597,8 @@
638 597
639 598 /**
640 599 * @param array $field
641 600 * @param array $add_html
642 - *
643 601 * @return void
644 602 */
645 603 private static function add_html_length( $field, array &$add_html ) {
646 604 // Check for max setting and if this field accepts maxlength.
@@ -666,13 +624,11 @@
666 624 /**
667 625 * @param array $field
668 626 * @param array $add_html
669 627 * @param array $class
670 - *
671 628 * @return void
672 629 */
673 630 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
674 - // phpcs:ignore Universal.Operators.StrictComparisons
675 631 if ( $field['default_value'] != '' ) {
676 632 if ( is_array( $field['default_value'] ) ) {
677 633 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
678 634 } else {
@@ -680,10 +636,8 @@
680 636 }
681 637 }
682 638
683 639 $field['placeholder'] = self::prepare_placeholder( $field );
684 -
685 - // phpcs:ignore Universal.Operators.StrictComparisons
686 640 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
687 641 // don't include a json placeholder
688 642 return;
689 643 }
@@ -696,13 +650,14 @@
696 650 *
697 651 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
698 652 *
699 653 * @param array $field Field array.
700 - *
701 654 * @return string
702 655 */
703 656 private static function prepare_placeholder( $field ) {
704 - return $field['placeholder'] ?? '';
657 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
658 +
659 + return $placeholder;
705 660 }
706 661
707 662 /**
708 663 * If the label position is "inside",
@@ -723,17 +678,13 @@
723 678 * Maybe add a blank placeholder option before any options
724 679 * in a dropdown.
725 680 *
726 681 * @since 4.04
727 - *
728 - * @param array|object $field
729 - *
730 682 * @return bool True if placeholder was added.
731 683 */
732 684 public static function add_placeholder_to_select( $field ) {
733 685 $placeholder = FrmField::get_option( $field, 'placeholder' );
734 -
735 - if ( ! $placeholder ) {
686 + if ( empty( $placeholder ) ) {
736 687 $placeholder = self::get_default_value_from_name( $field );
737 688 }
738 689
739 690 $use_placeholder = $placeholder;
@@ -740,9 +691,8 @@
740 691 $autocomplete = FrmField::get_option( $field, 'autocom' );
741 692
742 693 if ( $autocomplete ) {
743 694 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
744 -
745 695 if ( $use_chosen ) {
746 696 $use_placeholder = '';
747 697 }
748 698 }
@@ -765,9 +715,8 @@
765 715 * Use HTML5 placeholder with js fallback.
766 716 *
767 717 * @param array $field
768 718 * @param array $add_html
769 - *
770 719 * @return void
771 720 */
772 721 private static function add_placeholder_to_input( $field, &$add_html ) {
773 722 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -777,13 +726,11 @@
777 726
778 727 /**
779 728 * @param array $field
780 729 * @param array $add_html
781 - *
782 730 * @return void
783 731 */
784 732 private static function add_frmval_to_input( $field, &$add_html ) {
785 - // phpcs:ignore Universal.Operators.StrictComparisons
786 733 if ( $field['placeholder'] != '' ) {
787 734 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
788 735
789 736 if ( 'select' === $field['type'] ) {
@@ -790,20 +737,13 @@
790 737 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
791 738 }
792 739 }
793 740
794 - // phpcs:ignore Universal.Operators.StrictComparisons
795 741 if ( $field['default_value'] != '' ) {
796 742 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
797 743 }
798 744 }
799 745
800 - /**
801 - * @param array $field
802 - * @param array $add_html
803 - *
804 - * @return void
805 - */
806 746 private static function add_validation_messages( $field, array &$add_html ) {
807 747 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
808 748
809 749 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -827,9 +767,8 @@
827 767 *
828 768 * @since 6.9
829 769 *
830 770 * @param array|object $field
831 - *
832 771 * @return array
833 772 */
834 773 private static function get_validation_data_attribute_visibility_info( $field ) {
835 774 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -859,20 +798,17 @@
859 798 * @since 5.0.03
860 799 *
861 800 * @param array $field
862 801 * @param array $add_html
863 - *
864 802 * @return void
865 803 */
866 804 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
867 805 $form = self::get_form_for_js_validation( $field );
868 -
869 806 if ( false === $form ) {
870 807 return;
871 808 }
872 809
873 810 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
874 -
875 811 if ( false !== $error_body ) {
876 812 $error_body = urlencode( $error_body );
877 813 $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
878 814 }
@@ -881,24 +817,20 @@
881 817 /**
882 818 * @since 5.0.03
883 819 *
884 820 * @param array $field
885 - *
886 821 * @return false|stdClass false if there is no form object found with JS validation active.
887 822 */
888 823 private static function get_form_for_js_validation( $field ) {
889 824 global $frm_vars;
890 -
891 825 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
892 826 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
893 827 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
894 828 }
895 -
896 829 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
897 830 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
898 831 }
899 832 }
900 -
901 833 return false;
902 834 }
903 835
904 836 /**
@@ -904,9 +836,8 @@
904 836 /**
905 837 * @param stdClass $form
906 838 * @param array $field
907 839 * @param array $errors
908 - *
909 840 * @return false|string
910 841 */
911 842 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
912 843 if ( empty( $field['custom_html'] ) ) {
@@ -914,16 +845,15 @@
914 845 }
915 846
916 847 $custom_html = $field['custom_html'];
917 848 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
918 - $start = strpos( $custom_html, '[if error]' );
919 849
850 + $start = strpos( $custom_html, '[if error]' );
920 851 if ( false === $start ) {
921 852 return false;
922 853 }
923 854
924 855 $end = strpos( $custom_html, '[/if error]' );
925 -
926 856 if ( false === $end || $end < $start ) {
927 857 return false;
928 858 }
929 859
@@ -934,9 +864,13 @@
934 864 '<div class="frm_error">[error]</div>',
935 865 '<div class="frm_error" role="alert">[error]</div>',
936 866 );
937 867
938 - return in_array( $error_body, $default_html, true ) ? false : $error_body;
868 + if ( in_array( $error_body, $default_html, true ) ) {
869 + return false;
870 + }
871 +
872 + return $error_body;
939 873 }
940 874
941 875 /**
942 876 * If 'required' is added to a conditionally hidden field, the form won't
@@ -943,12 +877,10 @@
943 877 * submit in many browsers. Check to make sure the javascript to conditionally
944 878 * remove it is present if needed.
945 879 *
946 880 * @since 3.06.01
947 - *
948 881 * @param array $field
949 882 * @param array $add_html
950 - *
951 883 * @return void
952 884 */
953 885 private static function maybe_add_html_required( $field, array &$add_html ) {
954 886 $excluded_field_types =
@@ -967,9 +899,8 @@
967 899
968 900 /**
969 901 * @param array $field
970 902 * @param array $add_html
971 - *
972 903 * @return void
973 904 */
974 905 private static function add_shortcodes_to_html( $field, array &$add_html ) {
975 906 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -980,11 +911,10 @@
980 911 unset( $field['shortcodes']['autocomplete'] );
981 912 }
982 913
983 914 foreach ( $field['shortcodes'] as $k => $v ) {
984 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
915 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
985 916 $subfield_name = $field['subfield_name'];
986 -
987 917 if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
988 918 continue;
989 919 }
990 920 // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
@@ -991,14 +921,13 @@
991 921 $k = 'aria-invalid';
992 922 $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
993 923 unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
994 924 }
995 -
996 925 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
997 926 continue;
998 927 }
999 928
1000 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
929 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1001 930 $add_html[] = $v;
1002 931 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1003 932 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1004 933 } else {
@@ -1014,9 +943,8 @@
1014 943 *
1015 944 * @since 6.11.2
1016 945 *
1017 946 * @param string $key The option key.
1018 - *
1019 947 * @return bool
1020 948 */
1021 949 private static function should_allow_input_attribute( $key ) {
1022 950 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1031,9 +959,8 @@
1031 959 * @since 3.0
1032 960 *
1033 961 * @param array $field
1034 962 * @param array $add_html
1035 - *
1036 963 * @return void
1037 964 */
1038 965 private static function add_pattern_attribute( $field, array &$add_html ) {
1039 966 $format_value = FrmField::get_option( $field, 'format' );
@@ -1047,21 +974,14 @@
1047 974 $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1048 975 }
1049 976 }
1050 977
1051 - /**
1052 - * @param mixed $opt
1053 - * @param mixed $opt_key
1054 - * @param array|object $field
1055 - *
1056 - * @return mixed
1057 - */
1058 978 public static function check_value( $opt, $opt_key, $field ) {
1059 979 if ( is_array( $opt ) ) {
1060 980 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1061 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
981 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1062 982 } else {
1063 - $opt = $opt['label'] ?? reset( $opt );
983 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1064 984 }
1065 985 }
1066 986
1067 987 return $opt;
@@ -1066,16 +986,11 @@
1066 986
1067 987 return $opt;
1068 988 }
1069 989
1070 - /**
1071 - * @param mixed $opt
1072 - *
1073 - * @return mixed
1074 - */
1075 990 public static function check_label( $opt ) {
1076 991 if ( is_array( $opt ) ) {
1077 - $opt = $opt['label'] ?? reset( $opt );
992 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1078 993 }
1079 994
1080 995 return $opt;
1081 996 }