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/controllers/FrmFieldsController.php +22 -114 6.266.19 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();
@@ -65,15 +63,14 @@
65 63 public static function create() {
66 64 FrmAppHelper::permission_check( 'frm_edit_forms' );
67 65 check_ajax_referer( 'frm_ajax', 'nonce' );
68 66
69 - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
70 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
71 - $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' );
72 69
73 70 do_action( 'frm_before_create_field', $field_type, $form_id );
74 71
75 - $field = self::include_new_field( $field_type, $form_id, $field_options );
72 + $field = self::include_new_field( $field_type, $form_id );
76 73
77 74 // this hook will allow for multiple fields to be added at once
78 75 do_action( 'frm_after_field_created', $field, $form_id );
79 76
@@ -84,19 +81,14 @@
84 81 * Set up and create a new field
85 82 *
86 83 * @param string $field_type
87 84 * @param int $form_id
88 - * @param array $field_options
89 85 *
90 86 * @return array|false
91 87 */
92 - public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
88 + public static function include_new_field( $field_type, $form_id ) {
93 89 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
94 90
95 - if ( ! empty( $field_options ) ) {
96 - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
97 - }
98 -
99 91 // When a new field is added to the form, flag it as draft and hide it from the front-end.
100 92 $field_values['field_options']['draft'] = 1;
101 93
102 94 /**
@@ -111,14 +103,12 @@
111 103
112 104 $field = self::get_field_array_from_id( $field_id );
113 105
114 106 $values = array();
115 -
116 107 if ( FrmAppHelper::pro_is_installed() ) {
117 108 $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
118 109
119 110 $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
120 -
121 111 if ( $parent_form_id ) {
122 112 $field['parent_form_id'] = $parent_form_id;
123 113 }
124 114 }
@@ -162,10 +152,8 @@
162 152 *
163 153 * @param array|int|object $field_object
164 154 * @param array $values
165 155 * @param int $form_id
166 - *
167 - * @return void
168 156 */
169 157 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
170 158 global $frm_vars;
171 159 $frm_vars['is_admin'] = true;
@@ -189,23 +177,12 @@
189 177 return;
190 178 }
191 179
192 180 if ( ! isset( $field ) && is_object( $field_object ) ) {
193 - $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;
194 182 $field = FrmFieldsHelper::setup_edit_vars( $field_object );
195 183 }
196 184
197 - /**
198 - * Filter for adding extra attributes to the field container.
199 - *
200 - * @since 6.23
201 - *
202 - * @param array $extra_field_attributes
203 - * @param array $field
204 - * @param array $display
205 - */
206 - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display );
207 -
208 185 $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
209 186 $li_classes .= ' ui-state-default widgets-holder-wrap';
210 187
211 188 require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
@@ -216,9 +193,8 @@
216 193 *
217 194 * @param array $field
218 195 * @param array $display
219 196 * @param FrmFieldType $field_info
220 - *
221 197 * @return string
222 198 */
223 199 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
224 200 $li_classes = $field_info->form_builder_classes( $display['type'] );
@@ -266,9 +242,8 @@
266 242 *
267 243 * @since 6.8.4
268 244 *
269 245 * @param array $bulk_edit_types
270 - *
271 246 * @return array
272 247 */
273 248 $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
274 249
@@ -300,9 +275,8 @@
300 275
301 276 // Keep other options after bulk update.
302 277 if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
303 278 $other_array = array();
304 -
305 279 foreach ( $field['options'] as $opt_key => $opt ) {
306 280 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
307 281 $other_array[ $opt_key ] = $opt;
308 282 }
@@ -307,9 +281,8 @@
307 281 $other_array[ $opt_key ] = $opt;
308 282 }
309 283 unset( $opt_key, $opt );
310 284 }
311 -
312 285 if ( ! empty( $other_array ) ) {
313 286 $opts = array_merge( $opts, $other_array );
314 287 }
315 288 }
@@ -324,9 +297,8 @@
324 297 /**
325 298 * @since 4.0
326 299 *
327 300 * @param array $atts - Includes field array, field_obj, display array, values array.
328 - *
329 301 * @return void
330 302 */
331 303 public static function load_single_field_settings( $atts ) {
332 304 $field = $atts['field'];
@@ -360,9 +332,8 @@
360 332 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
361 333 }
362 334
363 335 $type_name = $all_field_types[ $field['type'] ]['name'];
364 -
365 336 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
366 337 $type_name = $all_field_types['divider|repeat']['name'];
367 338 }
368 339
@@ -395,9 +366,8 @@
395 366 * @since 4.0
396 367 *
397 368 * @param array $field
398 369 * @param array $atts
399 - *
400 370 * @return array
401 371 */
402 372 private static function default_value_types( $field, $atts ) {
403 373 $types = array(
@@ -403,32 +373,30 @@
403 373 $types = array(
404 374 'default_value' => array(
405 375 'class' => '',
406 376 'icon' => 'frm_icon_font frm_text2_icon',
407 - 'title' => __( 'Default Value', 'formidable' ),
377 + 'title' => __( 'Default Value (Text)', 'formidable' ),
408 378 'data' => array(
409 379 'frmshow' => '#default-value-for-',
410 380 ),
411 381 ),
412 382 '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(
383 + 'class' => 'frm_show_upgrade frm_noallow',
384 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
385 + 'icon' => 'frm_icon_font frm_calculator_icon',
386 + 'data' => array(
417 387 'medium' => 'calculations',
418 388 'upgrade' => __( 'Calculator forms', 'formidable' ),
419 389 ),
420 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
421 390 ),
422 391 '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(
392 + 'class' => 'frm_show_upgrade frm_noallow',
393 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
394 + 'icon' => 'frm_icon_font frm_search_icon',
395 + 'data' => array(
427 396 'medium' => 'lookup',
428 397 'upgrade' => __( 'Lookup fields', 'formidable' ),
429 398 ),
430 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
431 399 ),
432 400 );
433 401
434 402 $types = apply_filters( 'frm_default_value_types', $types, $atts );
@@ -436,13 +404,11 @@
436 404 // Set active class.
437 405 $settings = array_keys( $types );
438 406 $active = 'default_value';
439 407
440 - if ( FrmAppHelper::pro_is_connected() ) {
441 - foreach ( $settings as $type ) {
442 - if ( ! empty( $field[ $type ] ) ) {
443 - $active = $type;
444 - }
408 + foreach ( $settings as $type ) {
409 + if ( ! empty( $field[ $type ] ) ) {
410 + $active = $type;
445 411 }
446 412 }
447 413
448 414 $types[ $active ]['class'] .= ' current';
@@ -452,9 +418,8 @@
452 418 }
453 419
454 420 /**
455 421 * @param string $type
456 - *
457 422 * @return string
458 423 */
459 424 public static function change_type( $type ) {
460 425 $type_switch = array(
@@ -464,9 +429,8 @@
464 429 'rte' => 'textarea',
465 430 'website' => 'url',
466 431 'image' => 'url',
467 432 );
468 -
469 433 if ( isset( $type_switch[ $type ] ) ) {
470 434 $type = $type_switch[ $type ];
471 435 }
472 436
@@ -505,9 +469,8 @@
505 469 * @since 3.0
506 470 *
507 471 * @param array $field Field data.
508 472 * @param bool $is_hidden Whether the format option should be hidden.
509 - *
510 473 * @return void
511 474 */
512 475 public static function show_format_option( $field, $is_hidden = false ) {
513 476 $attributes = array(
@@ -521,14 +484,8 @@
521 484
522 485 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
523 486 }
524 487
525 - /**
526 - * @param array $field
527 - * @param bool $echo
528 - *
529 - * @return string
530 - */
531 488 public static function input_html( $field, $echo = true ) {
532 489 $class = array();
533 490 self::add_input_classes( $field, $class );
534 491
@@ -557,9 +514,8 @@
557 514
558 515 /**
559 516 * @param array $field
560 517 * @param array $class
561 - *
562 518 * @return void
563 519 */
564 520 private static function add_input_classes( $field, array &$class ) {
565 521 if ( ! empty( $field['input_class'] ) ) {
@@ -577,9 +533,8 @@
577 533
578 534 /**
579 535 * @param array $field
580 536 * @param array $add_html
581 - *
582 537 * @return void
583 538 */
584 539 private static function add_html_size( $field, array &$add_html ) {
585 540 $size_fields = array(
@@ -612,9 +567,8 @@
612 567
613 568 /**
614 569 * @param array $field
615 570 * @param array $add_html
616 - *
617 571 * @return void
618 572 */
619 573 private static function add_html_cols( $field, array &$add_html ) {
620 574 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -643,9 +597,8 @@
643 597
644 598 /**
645 599 * @param array $field
646 600 * @param array $add_html
647 - *
648 601 * @return void
649 602 */
650 603 private static function add_html_length( $field, array &$add_html ) {
651 604 // Check for max setting and if this field accepts maxlength.
@@ -671,9 +624,8 @@
671 624 /**
672 625 * @param array $field
673 626 * @param array $add_html
674 627 * @param array $class
675 - *
676 628 * @return void
677 629 */
678 630 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
679 631 if ( $field['default_value'] != '' ) {
@@ -684,9 +636,8 @@
684 636 }
685 637 }
686 638
687 639 $field['placeholder'] = self::prepare_placeholder( $field );
688 -
689 640 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
690 641 // don't include a json placeholder
691 642 return;
692 643 }
@@ -699,13 +650,12 @@
699 650 *
700 651 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
701 652 *
702 653 * @param array $field Field array.
703 - *
704 654 * @return string
705 655 */
706 656 private static function prepare_placeholder( $field ) {
707 - $placeholder = $field['placeholder'] ?? '';
657 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
708 658
709 659 return $placeholder;
710 660 }
711 661
@@ -728,16 +678,12 @@
728 678 * Maybe add a blank placeholder option before any options
729 679 * in a dropdown.
730 680 *
731 681 * @since 4.04
732 - *
733 - * @param array|object $field
734 - *
735 682 * @return bool True if placeholder was added.
736 683 */
737 684 public static function add_placeholder_to_select( $field ) {
738 685 $placeholder = FrmField::get_option( $field, 'placeholder' );
739 -
740 686 if ( empty( $placeholder ) ) {
741 687 $placeholder = self::get_default_value_from_name( $field );
742 688 }
743 689
@@ -745,9 +691,8 @@
745 691 $autocomplete = FrmField::get_option( $field, 'autocom' );
746 692
747 693 if ( $autocomplete ) {
748 694 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
749 -
750 695 if ( $use_chosen ) {
751 696 $use_placeholder = '';
752 697 }
753 698 }
@@ -770,9 +715,8 @@
770 715 * Use HTML5 placeholder with js fallback.
771 716 *
772 717 * @param array $field
773 718 * @param array $add_html
774 - *
775 719 * @return void
776 720 */
777 721 private static function add_placeholder_to_input( $field, &$add_html ) {
778 722 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -782,9 +726,8 @@
782 726
783 727 /**
784 728 * @param array $field
785 729 * @param array $add_html
786 - *
787 730 * @return void
788 731 */
789 732 private static function add_frmval_to_input( $field, &$add_html ) {
790 733 if ( $field['placeholder'] != '' ) {
@@ -799,14 +742,8 @@
799 742 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
800 743 }
801 744 }
802 745
803 - /**
804 - * @param array $field
805 - * @param array $add_html
806 - *
807 - * @return void
808 - */
809 746 private static function add_validation_messages( $field, array &$add_html ) {
810 747 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
811 748
812 749 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -830,9 +767,8 @@
830 767 *
831 768 * @since 6.9
832 769 *
833 770 * @param array|object $field
834 - *
835 771 * @return array
836 772 */
837 773 private static function get_validation_data_attribute_visibility_info( $field ) {
838 774 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -862,20 +798,17 @@
862 798 * @since 5.0.03
863 799 *
864 800 * @param array $field
865 801 * @param array $add_html
866 - *
867 802 * @return void
868 803 */
869 804 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
870 805 $form = self::get_form_for_js_validation( $field );
871 -
872 806 if ( false === $form ) {
873 807 return;
874 808 }
875 809
876 810 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
877 -
878 811 if ( false !== $error_body ) {
879 812 $error_body = urlencode( $error_body );
880 813 $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
881 814 }
@@ -884,19 +817,16 @@
884 817 /**
885 818 * @since 5.0.03
886 819 *
887 820 * @param array $field
888 - *
889 821 * @return false|stdClass false if there is no form object found with JS validation active.
890 822 */
891 823 private static function get_form_for_js_validation( $field ) {
892 824 global $frm_vars;
893 -
894 825 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
895 826 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
896 827 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
897 828 }
898 -
899 829 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
900 830 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
901 831 }
902 832 }
@@ -906,9 +836,8 @@
906 836 /**
907 837 * @param stdClass $form
908 838 * @param array $field
909 839 * @param array $errors
910 - *
911 840 * @return false|string
912 841 */
913 842 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
914 843 if ( empty( $field['custom_html'] ) ) {
@@ -918,15 +847,13 @@
918 847 $custom_html = $field['custom_html'];
919 848 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
920 849
921 850 $start = strpos( $custom_html, '[if error]' );
922 -
923 851 if ( false === $start ) {
924 852 return false;
925 853 }
926 854
927 855 $end = strpos( $custom_html, '[/if error]' );
928 -
929 856 if ( false === $end || $end < $start ) {
930 857 return false;
931 858 }
932 859
@@ -950,12 +877,10 @@
950 877 * submit in many browsers. Check to make sure the javascript to conditionally
951 878 * remove it is present if needed.
952 879 *
953 880 * @since 3.06.01
954 - *
955 881 * @param array $field
956 882 * @param array $add_html
957 - *
958 883 * @return void
959 884 */
960 885 private static function maybe_add_html_required( $field, array &$add_html ) {
961 886 $excluded_field_types =
@@ -974,9 +899,8 @@
974 899
975 900 /**
976 901 * @param array $field
977 902 * @param array $add_html
978 - *
979 903 * @return void
980 904 */
981 905 private static function add_shortcodes_to_html( $field, array &$add_html ) {
982 906 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -989,9 +913,8 @@
989 913
990 914 foreach ( $field['shortcodes'] as $k => $v ) {
991 915 if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
992 916 $subfield_name = $field['subfield_name'];
993 -
994 917 if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
995 918 continue;
996 919 }
997 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.
@@ -998,9 +921,8 @@
998 921 $k = 'aria-invalid';
999 922 $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1000 923 unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1001 924 }
1002 -
1003 925 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
1004 926 continue;
1005 927 }
1006 928
@@ -1021,9 +943,8 @@
1021 943 *
1022 944 * @since 6.11.2
1023 945 *
1024 946 * @param string $key The option key.
1025 - *
1026 947 * @return bool
1027 948 */
1028 949 private static function should_allow_input_attribute( $key ) {
1029 950 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1038,9 +959,8 @@
1038 959 * @since 3.0
1039 960 *
1040 961 * @param array $field
1041 962 * @param array $add_html
1042 - *
1043 963 * @return void
1044 964 */
1045 965 private static function add_pattern_attribute( $field, array &$add_html ) {
1046 966 $format_value = FrmField::get_option( $field, 'format' );
@@ -1054,21 +974,14 @@
1054 974 $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1055 975 }
1056 976 }
1057 977
1058 - /**
1059 - * @param mixed $opt
1060 - * @param mixed $opt_key
1061 - * @param array|object $field
1062 - *
1063 - * @return mixed
1064 - */
1065 978 public static function check_value( $opt, $opt_key, $field ) {
1066 979 if ( is_array( $opt ) ) {
1067 980 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1068 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
981 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1069 982 } else {
1070 - $opt = $opt['label'] ?? reset( $opt );
983 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1071 984 }
1072 985 }
1073 986
1074 987 return $opt;
@@ -1073,16 +986,11 @@
1073 986
1074 987 return $opt;
1075 988 }
1076 989
1077 - /**
1078 - * @param mixed $opt
1079 - *
1080 - * @return mixed
1081 - */
1082 990 public static function check_label( $opt ) {
1083 991 if ( is_array( $opt ) ) {
1084 - $opt = $opt['label'] ?? reset( $opt );
992 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1085 993 }
1086 994
1087 995 return $opt;
1088 996 }