| @@ -63,15 +63,14 @@ | ||
| 63 | 63 | public static function create() { |
| 64 | 64 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 65 | 65 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 66 | 66 | |
| 67 | - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); | |
| 68 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 69 | - $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' ); | |
| 70 | 69 | |
| 71 | 70 | do_action( 'frm_before_create_field', $field_type, $form_id ); |
| 72 | 71 | |
| 73 | - $field = self::include_new_field( $field_type, $form_id, $field_options ); | |
| 72 | + $field = self::include_new_field( $field_type, $form_id ); | |
| 74 | 73 | |
| 75 | 74 | // this hook will allow for multiple fields to be added at once |
| 76 | 75 | do_action( 'frm_after_field_created', $field, $form_id ); |
| 77 | 76 | |
| @@ -82,19 +81,14 @@ | ||
| 82 | 81 | * Set up and create a new field |
| 83 | 82 | * |
| 84 | 83 | * @param string $field_type |
| 85 | 84 | * @param int $form_id |
| 86 | - * @param array $field_options | |
| 87 | 85 | * |
| 88 | 86 | * @return array|false |
| 89 | 87 | */ |
| 90 | - public static function include_new_field( $field_type, $form_id, $field_options = array() ) { | |
| 88 | + public static function include_new_field( $field_type, $form_id ) { | |
| 91 | 89 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
| 92 | 90 | |
| 93 | - if ( ! empty( $field_options ) ) { | |
| 94 | - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options ); | |
| 95 | - } | |
| 96 | - | |
| 97 | 91 | // When a new field is added to the form, flag it as draft and hide it from the front-end. |
| 98 | 92 | $field_values['field_options']['draft'] = 1; |
| 99 | 93 | |
| 100 | 94 | /** |
| @@ -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'; |
| @@ -390,32 +373,30 @@ | ||
| 390 | 373 | $types = array( |
| 391 | 374 | 'default_value' => array( |
| 392 | 375 | 'class' => '', |
| 393 | 376 | 'icon' => 'frm_icon_font frm_text2_icon', |
| 394 | - 'title' => __( 'Default Value', 'formidable' ), | |
| 377 | + 'title' => __( 'Default Value (Text)', 'formidable' ), | |
| 395 | 378 | 'data' => array( |
| 396 | 379 | 'frmshow' => '#default-value-for-', |
| 397 | 380 | ), |
| 398 | 381 | ), |
| 399 | 382 | 'calc' => array( |
| 400 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 401 | - 'title' => __( 'Calculate Value', 'formidable' ), | |
| 402 | - 'icon' => 'frm_icon_font frm_calculator_icon', | |
| 403 | - '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( | |
| 404 | 387 | 'medium' => 'calculations', |
| 405 | 388 | 'upgrade' => __( 'Calculator forms', 'formidable' ), |
| 406 | 389 | ), |
| 407 | - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ), | |
| 408 | 390 | ), |
| 409 | 391 | 'get_values_field' => array( |
| 410 | - 'class' => 'frm_show_upgrade frm_noallow', | |
| 411 | - 'title' => __( 'Lookup', 'formidable' ), | |
| 412 | - 'icon' => 'frm_icon_font frm_search_icon', | |
| 413 | - '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( | |
| 414 | 396 | 'medium' => 'lookup', |
| 415 | 397 | 'upgrade' => __( 'Lookup fields', 'formidable' ), |
| 416 | 398 | ), |
| 417 | - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ), | |
| 418 | 399 | ), |
| 419 | 400 | ); |
| 420 | 401 | |
| 421 | 402 | $types = apply_filters( 'frm_default_value_types', $types, $atts ); |
| @@ -423,13 +404,11 @@ | ||
| 423 | 404 | // Set active class. |
| 424 | 405 | $settings = array_keys( $types ); |
| 425 | 406 | $active = 'default_value'; |
| 426 | 407 | |
| 427 | - if ( FrmAppHelper::pro_is_connected() ) { | |
| 428 | - foreach ( $settings as $type ) { | |
| 429 | - if ( ! empty( $field[ $type ] ) ) { | |
| 430 | - $active = $type; | |
| 431 | - } | |
| 408 | + foreach ( $settings as $type ) { | |
| 409 | + if ( ! empty( $field[ $type ] ) ) { | |
| 410 | + $active = $type; | |
| 432 | 411 | } |
| 433 | 412 | } |
| 434 | 413 | |
| 435 | 414 | $types[ $active ]['class'] .= ' current'; |
| @@ -488,19 +467,17 @@ | ||
| 488 | 467 | * Display the format option |
| 489 | 468 | * |
| 490 | 469 | * @since 3.0 |
| 491 | 470 | * |
| 492 | - * @param array $field Field data. | |
| 493 | - * @param bool $is_hidden Whether the format option should be hidden. | |
| 471 | + * @param array $field | |
| 494 | 472 | * @return void |
| 495 | 473 | */ |
| 496 | - public static function show_format_option( $field, $is_hidden = false ) { | |
| 497 | - $attributes = array( | |
| 498 | - 'class' => 'frm-has-modal', | |
| 499 | - 'id' => 'frm-field-format-custom-' . $field['id'], | |
| 500 | - ); | |
| 474 | + public static function show_format_option( $field ) { | |
| 475 | + $attributes = array(); | |
| 476 | + $attributes['class'] = 'frm-has-modal'; | |
| 501 | 477 | |
| 502 | - if ( $is_hidden ) { | |
| 478 | + if ( 'phone' === $field['type'] ) { | |
| 479 | + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id']; | |
| 503 | 480 | $attributes['class'] .= ' frm_hidden'; |
| 504 | 481 | } |
| 505 | 482 | |
| 506 | 483 | include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php'; |
| @@ -674,9 +651,9 @@ | ||
| 674 | 651 | * @param array $field Field array. |
| 675 | 652 | * @return string |
| 676 | 653 | */ |
| 677 | 654 | private static function prepare_placeholder( $field ) { |
| 678 | - $placeholder = $field['placeholder'] ?? ''; | |
| 655 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 679 | 656 | |
| 680 | 657 | return $placeholder; |
| 681 | 658 | } |
| 682 | 659 | |
| @@ -724,8 +701,13 @@ | ||
| 724 | 701 | 'value' => '', |
| 725 | 702 | 'data-placeholder' => 'true', |
| 726 | 703 | ); |
| 727 | 704 | |
| 705 | + if ( $autocomplete && empty( $use_chosen ) ) { | |
| 706 | + // This is required for Slim Select. | |
| 707 | + $placeholder_attributes['data-placeholder'] = 'true'; | |
| 708 | + } | |
| 709 | + | |
| 728 | 710 | FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes ); |
| 729 | 711 | return true; |
| 730 | 712 | } |
| 731 | 713 | |
| @@ -932,18 +914,8 @@ | ||
| 932 | 914 | unset( $field['shortcodes']['autocomplete'] ); |
| 933 | 915 | } |
| 934 | 916 | |
| 935 | 917 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 936 | - if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) { | |
| 937 | - $subfield_name = $field['subfield_name']; | |
| 938 | - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) { | |
| 939 | - continue; | |
| 940 | - } | |
| 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. | |
| 942 | - $k = 'aria-invalid'; | |
| 943 | - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ]; | |
| 944 | - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ); | |
| 945 | - } | |
| 946 | 918 | if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) { |
| 947 | 919 | continue; |
| 948 | 920 | } |
| 949 | 921 | |
| @@ -955,9 +927,9 @@ | ||
| 955 | 927 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
| 956 | 928 | } |
| 957 | 929 | |
| 958 | 930 | unset( $k, $v ); |
| 959 | - }//end foreach | |
| 931 | + } | |
| 960 | 932 | } |
| 961 | 933 | |
| 962 | 934 | /** |
| 963 | 935 | * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed. |
| @@ -983,10 +955,9 @@ | ||
| 983 | 955 | * @param array $add_html |
| 984 | 956 | * @return void |
| 985 | 957 | */ |
| 986 | 958 | private static function add_pattern_attribute( $field, array &$add_html ) { |
| 987 | - $format_value = FrmField::get_option( $field, 'format' ); | |
| 988 | - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ); | |
| 959 | + $has_format = FrmField::is_option_true_in_array( $field, 'format' ); | |
| 989 | 960 | $format_field = FrmField::is_field_type( $field, 'text' ); |
| 990 | 961 | |
| 991 | 962 | if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) { |
| 992 | 963 | $format = FrmEntryValidate::phone_format( $field ); |
| @@ -998,11 +969,11 @@ | ||
| 998 | 969 | |
| 999 | 970 | public static function check_value( $opt, $opt_key, $field ) { |
| 1000 | 971 | if ( is_array( $opt ) ) { |
| 1001 | 972 | if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
| 1002 | - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt ); | |
| 973 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); | |
| 1003 | 974 | } else { |
| 1004 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 975 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1005 | 976 | } |
| 1006 | 977 | } |
| 1007 | 978 | |
| 1008 | 979 | return $opt; |
| @@ -1009,9 +980,9 @@ | ||
| 1009 | 980 | } |
| 1010 | 981 | |
| 1011 | 982 | public static function check_label( $opt ) { |
| 1012 | 983 | if ( is_array( $opt ) ) { |
| 1013 | - $opt = $opt['label'] ?? reset( $opt ); | |
| 984 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); | |
| 1014 | 985 | } |
| 1015 | 986 | |
| 1016 | 987 | return $opt; |
| 1017 | 988 | } |