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 +18 -93 6.266.23 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(
@@ -403,32 +390,30 @@
403 390 $types = array(
404 391 'default_value' => array(
405 392 'class' => '',
406 393 'icon' => 'frm_icon_font frm_text2_icon',
407 - 'title' => __( 'Default Value', 'formidable' ),
394 + 'title' => __( 'Default Value (Text)', 'formidable' ),
408 395 'data' => array(
409 396 'frmshow' => '#default-value-for-',
410 397 ),
411 398 ),
412 399 'calc' => array(
413 - 'class' => 'frm_show_upgrade frm_noallow',
414 - 'title' => __( 'Calculate Value', 'formidable' ),
415 - 'icon' => 'frm_icon_font frm_calculator_icon',
416 - '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(
417 404 'medium' => 'calculations',
418 405 'upgrade' => __( 'Calculator forms', 'formidable' ),
419 406 ),
420 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
421 407 ),
422 408 'get_values_field' => array(
423 - 'class' => 'frm_show_upgrade frm_noallow',
424 - 'title' => __( 'Lookup', 'formidable' ),
425 - 'icon' => 'frm_icon_font frm_search_icon',
426 - '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(
427 413 'medium' => 'lookup',
428 414 'upgrade' => __( 'Lookup fields', 'formidable' ),
429 415 ),
430 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
431 416 ),
432 417 );
433 418
434 419 $types = apply_filters( 'frm_default_value_types', $types, $atts );
@@ -436,13 +421,11 @@
436 421 // Set active class.
437 422 $settings = array_keys( $types );
438 423 $active = 'default_value';
439 424
440 - if ( FrmAppHelper::pro_is_connected() ) {
441 - foreach ( $settings as $type ) {
442 - if ( ! empty( $field[ $type ] ) ) {
443 - $active = $type;
444 - }
425 + foreach ( $settings as $type ) {
426 + if ( ! empty( $field[ $type ] ) ) {
427 + $active = $type;
445 428 }
446 429 }
447 430
448 431 $types[ $active ]['class'] .= ' current';
@@ -452,9 +435,8 @@
452 435 }
453 436
454 437 /**
455 438 * @param string $type
456 - *
457 439 * @return string
458 440 */
459 441 public static function change_type( $type ) {
460 442 $type_switch = array(
@@ -464,9 +446,8 @@
464 446 'rte' => 'textarea',
465 447 'website' => 'url',
466 448 'image' => 'url',
467 449 );
468 -
469 450 if ( isset( $type_switch[ $type ] ) ) {
470 451 $type = $type_switch[ $type ];
471 452 }
472 453
@@ -505,9 +486,8 @@
505 486 * @since 3.0
506 487 *
507 488 * @param array $field Field data.
508 489 * @param bool $is_hidden Whether the format option should be hidden.
509 - *
510 490 * @return void
511 491 */
512 492 public static function show_format_option( $field, $is_hidden = false ) {
513 493 $attributes = array(
@@ -521,14 +501,8 @@
521 501
522 502 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
523 503 }
524 504
525 - /**
526 - * @param array $field
527 - * @param bool $echo
528 - *
529 - * @return string
530 - */
531 505 public static function input_html( $field, $echo = true ) {
532 506 $class = array();
533 507 self::add_input_classes( $field, $class );
534 508
@@ -557,9 +531,8 @@
557 531
558 532 /**
559 533 * @param array $field
560 534 * @param array $class
561 - *
562 535 * @return void
563 536 */
564 537 private static function add_input_classes( $field, array &$class ) {
565 538 if ( ! empty( $field['input_class'] ) ) {
@@ -577,9 +550,8 @@
577 550
578 551 /**
579 552 * @param array $field
580 553 * @param array $add_html
581 - *
582 554 * @return void
583 555 */
584 556 private static function add_html_size( $field, array &$add_html ) {
585 557 $size_fields = array(
@@ -612,9 +584,8 @@
612 584
613 585 /**
614 586 * @param array $field
615 587 * @param array $add_html
616 - *
617 588 * @return void
618 589 */
619 590 private static function add_html_cols( $field, array &$add_html ) {
620 591 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -643,9 +614,8 @@
643 614
644 615 /**
645 616 * @param array $field
646 617 * @param array $add_html
647 - *
648 618 * @return void
649 619 */
650 620 private static function add_html_length( $field, array &$add_html ) {
651 621 // Check for max setting and if this field accepts maxlength.
@@ -671,9 +641,8 @@
671 641 /**
672 642 * @param array $field
673 643 * @param array $add_html
674 644 * @param array $class
675 - *
676 645 * @return void
677 646 */
678 647 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
679 648 if ( $field['default_value'] != '' ) {
@@ -684,9 +653,8 @@
684 653 }
685 654 }
686 655
687 656 $field['placeholder'] = self::prepare_placeholder( $field );
688 -
689 657 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
690 658 // don't include a json placeholder
691 659 return;
692 660 }
@@ -699,13 +667,12 @@
699 667 *
700 668 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
701 669 *
702 670 * @param array $field Field array.
703 - *
704 671 * @return string
705 672 */
706 673 private static function prepare_placeholder( $field ) {
707 - $placeholder = $field['placeholder'] ?? '';
674 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
708 675
709 676 return $placeholder;
710 677 }
711 678
@@ -728,16 +695,12 @@
728 695 * Maybe add a blank placeholder option before any options
729 696 * in a dropdown.
730 697 *
731 698 * @since 4.04
732 - *
733 - * @param array|object $field
734 - *
735 699 * @return bool True if placeholder was added.
736 700 */
737 701 public static function add_placeholder_to_select( $field ) {
738 702 $placeholder = FrmField::get_option( $field, 'placeholder' );
739 -
740 703 if ( empty( $placeholder ) ) {
741 704 $placeholder = self::get_default_value_from_name( $field );
742 705 }
743 706
@@ -745,9 +708,8 @@
745 708 $autocomplete = FrmField::get_option( $field, 'autocom' );
746 709
747 710 if ( $autocomplete ) {
748 711 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
749 -
750 712 if ( $use_chosen ) {
751 713 $use_placeholder = '';
752 714 }
753 715 }
@@ -770,9 +732,8 @@
770 732 * Use HTML5 placeholder with js fallback.
771 733 *
772 734 * @param array $field
773 735 * @param array $add_html
774 - *
775 736 * @return void
776 737 */
777 738 private static function add_placeholder_to_input( $field, &$add_html ) {
778 739 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -782,9 +743,8 @@
782 743
783 744 /**
784 745 * @param array $field
785 746 * @param array $add_html
786 - *
787 747 * @return void
788 748 */
789 749 private static function add_frmval_to_input( $field, &$add_html ) {
790 750 if ( $field['placeholder'] != '' ) {
@@ -799,14 +759,8 @@
799 759 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
800 760 }
801 761 }
802 762
803 - /**
804 - * @param array $field
805 - * @param array $add_html
806 - *
807 - * @return void
808 - */
809 763 private static function add_validation_messages( $field, array &$add_html ) {
810 764 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
811 765
812 766 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -830,9 +784,8 @@
830 784 *
831 785 * @since 6.9
832 786 *
833 787 * @param array|object $field
834 - *
835 788 * @return array
836 789 */
837 790 private static function get_validation_data_attribute_visibility_info( $field ) {
838 791 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -862,20 +815,17 @@
862 815 * @since 5.0.03
863 816 *
864 817 * @param array $field
865 818 * @param array $add_html
866 - *
867 819 * @return void
868 820 */
869 821 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
870 822 $form = self::get_form_for_js_validation( $field );
871 -
872 823 if ( false === $form ) {
873 824 return;
874 825 }
875 826
876 827 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
877 -
878 828 if ( false !== $error_body ) {
879 829 $error_body = urlencode( $error_body );
880 830 $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
881 831 }
@@ -884,19 +834,16 @@
884 834 /**
885 835 * @since 5.0.03
886 836 *
887 837 * @param array $field
888 - *
889 838 * @return false|stdClass false if there is no form object found with JS validation active.
890 839 */
891 840 private static function get_form_for_js_validation( $field ) {
892 841 global $frm_vars;
893 -
894 842 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
895 843 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
896 844 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
897 845 }
898 -
899 846 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
900 847 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
901 848 }
902 849 }
@@ -906,9 +853,8 @@
906 853 /**
907 854 * @param stdClass $form
908 855 * @param array $field
909 856 * @param array $errors
910 - *
911 857 * @return false|string
912 858 */
913 859 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
914 860 if ( empty( $field['custom_html'] ) ) {
@@ -918,15 +864,13 @@
918 864 $custom_html = $field['custom_html'];
919 865 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
920 866
921 867 $start = strpos( $custom_html, '[if error]' );
922 -
923 868 if ( false === $start ) {
924 869 return false;
925 870 }
926 871
927 872 $end = strpos( $custom_html, '[/if error]' );
928 -
929 873 if ( false === $end || $end < $start ) {
930 874 return false;
931 875 }
932 876
@@ -950,12 +894,10 @@
950 894 * submit in many browsers. Check to make sure the javascript to conditionally
951 895 * remove it is present if needed.
952 896 *
953 897 * @since 3.06.01
954 - *
955 898 * @param array $field
956 899 * @param array $add_html
957 - *
958 900 * @return void
959 901 */
960 902 private static function maybe_add_html_required( $field, array &$add_html ) {
961 903 $excluded_field_types =
@@ -974,9 +916,8 @@
974 916
975 917 /**
976 918 * @param array $field
977 919 * @param array $add_html
978 - *
979 920 * @return void
980 921 */
981 922 private static function add_shortcodes_to_html( $field, array &$add_html ) {
982 923 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -989,9 +930,8 @@
989 930
990 931 foreach ( $field['shortcodes'] as $k => $v ) {
991 932 if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
992 933 $subfield_name = $field['subfield_name'];
993 -
994 934 if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
995 935 continue;
996 936 }
997 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.
@@ -998,9 +938,8 @@
998 938 $k = 'aria-invalid';
999 939 $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1000 940 unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1001 941 }
1002 -
1003 942 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
1004 943 continue;
1005 944 }
1006 945
@@ -1021,9 +960,8 @@
1021 960 *
1022 961 * @since 6.11.2
1023 962 *
1024 963 * @param string $key The option key.
1025 - *
1026 964 * @return bool
1027 965 */
1028 966 private static function should_allow_input_attribute( $key ) {
1029 967 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1038,9 +976,8 @@
1038 976 * @since 3.0
1039 977 *
1040 978 * @param array $field
1041 979 * @param array $add_html
1042 - *
1043 980 * @return void
1044 981 */
1045 982 private static function add_pattern_attribute( $field, array &$add_html ) {
1046 983 $format_value = FrmField::get_option( $field, 'format' );
@@ -1054,21 +991,14 @@
1054 991 $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1055 992 }
1056 993 }
1057 994
1058 - /**
1059 - * @param mixed $opt
1060 - * @param mixed $opt_key
1061 - * @param array|object $field
1062 - *
1063 - * @return mixed
1064 - */
1065 995 public static function check_value( $opt, $opt_key, $field ) {
1066 996 if ( is_array( $opt ) ) {
1067 997 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1068 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
998 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1069 999 } else {
1070 - $opt = $opt['label'] ?? reset( $opt );
1000 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1071 1001 }
1072 1002 }
1073 1003
1074 1004 return $opt;
@@ -1073,16 +1003,11 @@
1073 1003
1074 1004 return $opt;
1075 1005 }
1076 1006
1077 - /**
1078 - * @param mixed $opt
1079 - *
1080 - * @return mixed
1081 - */
1082 1007 public static function check_label( $opt ) {
1083 1008 if ( is_array( $opt ) ) {
1084 - $opt = $opt['label'] ?? reset( $opt );
1009 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1085 1010 }
1086 1011
1087 1012 return $opt;
1088 1013 }