PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.24.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.24.1
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 +6 -77 6.266.24.1 View file →
@@ -18,9 +18,8 @@
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 22 if ( empty( $fields ) ) {
24 23 wp_die();
25 24 }
26 25
@@ -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 }
@@ -51,9 +49,9 @@
51 49 ob_start();
52 50 self::load_single_field( $field, $values );
53 51 $field_html[ absint( $field->id ) ] = ob_get_contents();
54 52 ob_end_clean();
55 - }//end foreach
53 + }
56 54
57 55 echo json_encode( $field_html );
58 56
59 57 wp_die();
@@ -111,14 +109,12 @@
111 109
112 110 $field = self::get_field_array_from_id( $field_id );
113 111
114 112 $values = array();
115 -
116 113 if ( FrmAppHelper::pro_is_installed() ) {
117 114 $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
118 115
119 116 $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
120 -
121 117 if ( $parent_form_id ) {
122 118 $field['parent_form_id'] = $parent_form_id;
123 119 }
124 120 }
@@ -162,10 +158,8 @@
162 158 *
163 159 * @param array|int|object $field_object
164 160 * @param array $values
165 161 * @param int $form_id
166 - *
167 - * @return void
168 162 */
169 163 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
170 164 global $frm_vars;
171 165 $frm_vars['is_admin'] = true;
@@ -189,9 +183,9 @@
189 183 return;
190 184 }
191 185
192 186 if ( ! isset( $field ) && is_object( $field_object ) ) {
193 - $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;
194 188 $field = FrmFieldsHelper::setup_edit_vars( $field_object );
195 189 }
196 190
197 191 /**
@@ -216,9 +210,8 @@
216 210 *
217 211 * @param array $field
218 212 * @param array $display
219 213 * @param FrmFieldType $field_info
220 - *
221 214 * @return string
222 215 */
223 216 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
224 217 $li_classes = $field_info->form_builder_classes( $display['type'] );
@@ -266,9 +259,8 @@
266 259 *
267 260 * @since 6.8.4
268 261 *
269 262 * @param array $bulk_edit_types
270 - *
271 263 * @return array
272 264 */
273 265 $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
274 266
@@ -300,9 +292,8 @@
300 292
301 293 // Keep other options after bulk update.
302 294 if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
303 295 $other_array = array();
304 -
305 296 foreach ( $field['options'] as $opt_key => $opt ) {
306 297 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
307 298 $other_array[ $opt_key ] = $opt;
308 299 }
@@ -307,9 +298,8 @@
307 298 $other_array[ $opt_key ] = $opt;
308 299 }
309 300 unset( $opt_key, $opt );
310 301 }
311 -
312 302 if ( ! empty( $other_array ) ) {
313 303 $opts = array_merge( $opts, $other_array );
314 304 }
315 305 }
@@ -324,9 +314,8 @@
324 314 /**
325 315 * @since 4.0
326 316 *
327 317 * @param array $atts - Includes field array, field_obj, display array, values array.
328 - *
329 318 * @return void
330 319 */
331 320 public static function load_single_field_settings( $atts ) {
332 321 $field = $atts['field'];
@@ -360,9 +349,8 @@
360 349 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
361 350 }
362 351
363 352 $type_name = $all_field_types[ $field['type'] ]['name'];
364 -
365 353 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
366 354 $type_name = $all_field_types['divider|repeat']['name'];
367 355 }
368 356
@@ -395,9 +383,8 @@
395 383 * @since 4.0
396 384 *
397 385 * @param array $field
398 386 * @param array $atts
399 - *
400 387 * @return array
401 388 */
402 389 private static function default_value_types( $field, $atts ) {
403 390 $types = array(
@@ -452,9 +439,8 @@
452 439 }
453 440
454 441 /**
455 442 * @param string $type
456 - *
457 443 * @return string
458 444 */
459 445 public static function change_type( $type ) {
460 446 $type_switch = array(
@@ -464,9 +450,8 @@
464 450 'rte' => 'textarea',
465 451 'website' => 'url',
466 452 'image' => 'url',
467 453 );
468 -
469 454 if ( isset( $type_switch[ $type ] ) ) {
470 455 $type = $type_switch[ $type ];
471 456 }
472 457
@@ -505,9 +490,8 @@
505 490 * @since 3.0
506 491 *
507 492 * @param array $field Field data.
508 493 * @param bool $is_hidden Whether the format option should be hidden.
509 - *
510 494 * @return void
511 495 */
512 496 public static function show_format_option( $field, $is_hidden = false ) {
513 497 $attributes = array(
@@ -521,14 +505,8 @@
521 505
522 506 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
523 507 }
524 508
525 - /**
526 - * @param array $field
527 - * @param bool $echo
528 - *
529 - * @return string
530 - */
531 509 public static function input_html( $field, $echo = true ) {
532 510 $class = array();
533 511 self::add_input_classes( $field, $class );
534 512
@@ -557,9 +535,8 @@
557 535
558 536 /**
559 537 * @param array $field
560 538 * @param array $class
561 - *
562 539 * @return void
563 540 */
564 541 private static function add_input_classes( $field, array &$class ) {
565 542 if ( ! empty( $field['input_class'] ) ) {
@@ -577,9 +554,8 @@
577 554
578 555 /**
579 556 * @param array $field
580 557 * @param array $add_html
581 - *
582 558 * @return void
583 559 */
584 560 private static function add_html_size( $field, array &$add_html ) {
585 561 $size_fields = array(
@@ -612,9 +588,8 @@
612 588
613 589 /**
614 590 * @param array $field
615 591 * @param array $add_html
616 - *
617 592 * @return void
618 593 */
619 594 private static function add_html_cols( $field, array &$add_html ) {
620 595 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -643,9 +618,8 @@
643 618
644 619 /**
645 620 * @param array $field
646 621 * @param array $add_html
647 - *
648 622 * @return void
649 623 */
650 624 private static function add_html_length( $field, array &$add_html ) {
651 625 // Check for max setting and if this field accepts maxlength.
@@ -671,9 +645,8 @@
671 645 /**
672 646 * @param array $field
673 647 * @param array $add_html
674 648 * @param array $class
675 - *
676 649 * @return void
677 650 */
678 651 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
679 652 if ( $field['default_value'] != '' ) {
@@ -684,9 +657,8 @@
684 657 }
685 658 }
686 659
687 660 $field['placeholder'] = self::prepare_placeholder( $field );
688 -
689 661 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
690 662 // don't include a json placeholder
691 663 return;
692 664 }
@@ -699,13 +671,12 @@
699 671 *
700 672 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
701 673 *
702 674 * @param array $field Field array.
703 - *
704 675 * @return string
705 676 */
706 677 private static function prepare_placeholder( $field ) {
707 - $placeholder = $field['placeholder'] ?? '';
678 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
708 679
709 680 return $placeholder;
710 681 }
711 682
@@ -728,16 +699,12 @@
728 699 * Maybe add a blank placeholder option before any options
729 700 * in a dropdown.
730 701 *
731 702 * @since 4.04
732 - *
733 - * @param array|object $field
734 - *
735 703 * @return bool True if placeholder was added.
736 704 */
737 705 public static function add_placeholder_to_select( $field ) {
738 706 $placeholder = FrmField::get_option( $field, 'placeholder' );
739 -
740 707 if ( empty( $placeholder ) ) {
741 708 $placeholder = self::get_default_value_from_name( $field );
742 709 }
743 710
@@ -745,9 +712,8 @@
745 712 $autocomplete = FrmField::get_option( $field, 'autocom' );
746 713
747 714 if ( $autocomplete ) {
748 715 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
749 -
750 716 if ( $use_chosen ) {
751 717 $use_placeholder = '';
752 718 }
753 719 }
@@ -770,9 +736,8 @@
770 736 * Use HTML5 placeholder with js fallback.
771 737 *
772 738 * @param array $field
773 739 * @param array $add_html
774 - *
775 740 * @return void
776 741 */
777 742 private static function add_placeholder_to_input( $field, &$add_html ) {
778 743 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -782,9 +747,8 @@
782 747
783 748 /**
784 749 * @param array $field
785 750 * @param array $add_html
786 - *
787 751 * @return void
788 752 */
789 753 private static function add_frmval_to_input( $field, &$add_html ) {
790 754 if ( $field['placeholder'] != '' ) {
@@ -799,14 +763,8 @@
799 763 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
800 764 }
801 765 }
802 766
803 - /**
804 - * @param array $field
805 - * @param array $add_html
806 - *
807 - * @return void
808 - */
809 767 private static function add_validation_messages( $field, array &$add_html ) {
810 768 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
811 769
812 770 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -830,9 +788,8 @@
830 788 *
831 789 * @since 6.9
832 790 *
833 791 * @param array|object $field
834 - *
835 792 * @return array
836 793 */
837 794 private static function get_validation_data_attribute_visibility_info( $field ) {
838 795 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -862,20 +819,17 @@
862 819 * @since 5.0.03
863 820 *
864 821 * @param array $field
865 822 * @param array $add_html
866 - *
867 823 * @return void
868 824 */
869 825 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
870 826 $form = self::get_form_for_js_validation( $field );
871 -
872 827 if ( false === $form ) {
873 828 return;
874 829 }
875 830
876 831 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
877 -
878 832 if ( false !== $error_body ) {
879 833 $error_body = urlencode( $error_body );
880 834 $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
881 835 }
@@ -884,19 +838,16 @@
884 838 /**
885 839 * @since 5.0.03
886 840 *
887 841 * @param array $field
888 - *
889 842 * @return false|stdClass false if there is no form object found with JS validation active.
890 843 */
891 844 private static function get_form_for_js_validation( $field ) {
892 845 global $frm_vars;
893 -
894 846 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
895 847 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
896 848 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
897 849 }
898 -
899 850 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
900 851 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
901 852 }
902 853 }
@@ -906,9 +857,8 @@
906 857 /**
907 858 * @param stdClass $form
908 859 * @param array $field
909 860 * @param array $errors
910 - *
911 861 * @return false|string
912 862 */
913 863 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
914 864 if ( empty( $field['custom_html'] ) ) {
@@ -918,15 +868,13 @@
918 868 $custom_html = $field['custom_html'];
919 869 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
920 870
921 871 $start = strpos( $custom_html, '[if error]' );
922 -
923 872 if ( false === $start ) {
924 873 return false;
925 874 }
926 875
927 876 $end = strpos( $custom_html, '[/if error]' );
928 -
929 877 if ( false === $end || $end < $start ) {
930 878 return false;
931 879 }
932 880
@@ -950,12 +898,10 @@
950 898 * submit in many browsers. Check to make sure the javascript to conditionally
951 899 * remove it is present if needed.
952 900 *
953 901 * @since 3.06.01
954 - *
955 902 * @param array $field
956 903 * @param array $add_html
957 - *
958 904 * @return void
959 905 */
960 906 private static function maybe_add_html_required( $field, array &$add_html ) {
961 907 $excluded_field_types =
@@ -974,9 +920,8 @@
974 920
975 921 /**
976 922 * @param array $field
977 923 * @param array $add_html
978 - *
979 924 * @return void
980 925 */
981 926 private static function add_shortcodes_to_html( $field, array &$add_html ) {
982 927 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -989,9 +934,8 @@
989 934
990 935 foreach ( $field['shortcodes'] as $k => $v ) {
991 936 if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
992 937 $subfield_name = $field['subfield_name'];
993 -
994 938 if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
995 939 continue;
996 940 }
997 941 // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
@@ -998,9 +942,8 @@
998 942 $k = 'aria-invalid';
999 943 $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1000 944 unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1001 945 }
1002 -
1003 946 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
1004 947 continue;
1005 948 }
1006 949
@@ -1021,9 +964,8 @@
1021 964 *
1022 965 * @since 6.11.2
1023 966 *
1024 967 * @param string $key The option key.
1025 - *
1026 968 * @return bool
1027 969 */
1028 970 private static function should_allow_input_attribute( $key ) {
1029 971 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1038,9 +980,8 @@
1038 980 * @since 3.0
1039 981 *
1040 982 * @param array $field
1041 983 * @param array $add_html
1042 - *
1043 984 * @return void
1044 985 */
1045 986 private static function add_pattern_attribute( $field, array &$add_html ) {
1046 987 $format_value = FrmField::get_option( $field, 'format' );
@@ -1054,21 +995,14 @@
1054 995 $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1055 996 }
1056 997 }
1057 998
1058 - /**
1059 - * @param mixed $opt
1060 - * @param mixed $opt_key
1061 - * @param array|object $field
1062 - *
1063 - * @return mixed
1064 - */
1065 999 public static function check_value( $opt, $opt_key, $field ) {
1066 1000 if ( is_array( $opt ) ) {
1067 1001 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1068 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
1002 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1069 1003 } else {
1070 - $opt = $opt['label'] ?? reset( $opt );
1004 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1071 1005 }
1072 1006 }
1073 1007
1074 1008 return $opt;
@@ -1073,16 +1007,11 @@
1073 1007
1074 1008 return $opt;
1075 1009 }
1076 1010
1077 - /**
1078 - * @param mixed $opt
1079 - *
1080 - * @return mixed
1081 - */
1082 1011 public static function check_label( $opt ) {
1083 1012 if ( is_array( $opt ) ) {
1084 - $opt = $opt['label'] ?? reset( $opt );
1013 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1085 1014 }
1086 1015
1087 1016 return $opt;
1088 1017 }