| @@ -79,14 +79,11 @@ | ||
| 79 | 79 | * @return array|bool |
| 80 | 80 | */ |
| 81 | 81 | public static function include_new_field( $field_type, $form_id ) { |
| 82 | 82 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
| 83 | + $field_values = apply_filters( 'frm_before_field_created', $field_values ); | |
| 83 | 84 | |
| 84 | - /** | |
| 85 | - * @param array $field_values | |
| 86 | - */ | |
| 87 | - $field_values = apply_filters( 'frm_before_field_created', $field_values ); | |
| 88 | - $field_id = FrmField::create( $field_values ); | |
| 85 | + $field_id = FrmField::create( $field_values ); | |
| 89 | 86 | |
| 90 | 87 | if ( ! $field_id ) { |
| 91 | 88 | return false; |
| 92 | 89 | } |
| @@ -181,13 +178,23 @@ | ||
| 181 | 178 | /** |
| 182 | 179 | * @since 3.0 |
| 183 | 180 | */ |
| 184 | 181 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 185 | - $li_classes = $field_info->form_builder_classes( $display['type'] ); | |
| 182 | + $li_classes = $field_info->form_builder_classes( $display['type'] ); | |
| 183 | + $classes = isset( $field['classes'] ) ? $field['classes'] : ''; | |
| 184 | + | |
| 185 | + // Exclude alignright for now since we aren't using widths. | |
| 186 | + $classes = str_replace( ' frm_alignright ', ' ', $classes ); | |
| 187 | + $classes = trim( $classes ); | |
| 188 | + | |
| 189 | + if ( 'frm_alignright' === $classes ) { | |
| 190 | + $classes = ''; | |
| 191 | + } | |
| 192 | + | |
| 186 | 193 | $li_classes .= ' frm_form_field frmstart '; |
| 187 | 194 | |
| 188 | - if ( isset( $field['classes'] ) ) { | |
| 189 | - $li_classes .= trim( $field['classes'] ) . ' '; | |
| 195 | + if ( $classes ) { | |
| 196 | + $li_classes .= $classes . ' '; | |
| 190 | 197 | } |
| 191 | 198 | |
| 192 | 199 | $li_classes .= 'frmend'; |
| 193 | 200 | |
| @@ -315,10 +322,9 @@ | ||
| 315 | 322 | |
| 316 | 323 | if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) { |
| 317 | 324 | $field['placeholder'] = implode( ', ', $field['placeholder'] ); |
| 318 | 325 | } |
| 319 | - | |
| 320 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php'; | |
| 326 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' ); | |
| 321 | 327 | } |
| 322 | 328 | |
| 323 | 329 | /** |
| 324 | 330 | * Get the list of default value types that can be toggled in the builder. |
| @@ -392,13 +398,10 @@ | ||
| 392 | 398 | $type = $type_switch[ $type ]; |
| 393 | 399 | } |
| 394 | 400 | |
| 395 | 401 | $pro_fields = FrmField::pro_field_selection(); |
| 396 | - // We want to keep credit_card types as credit card types for Stripe Lite. | |
| 397 | - // The credit_card key is set for backward compatibility. | |
| 398 | - unset( $pro_fields['credit_card'] ); | |
| 399 | - | |
| 400 | - if ( array_key_exists( $type, $pro_fields ) ) { | |
| 402 | + $types = array_keys( $pro_fields ); | |
| 403 | + if ( in_array( $type, $types ) ) { | |
| 401 | 404 | $type = 'text'; |
| 402 | 405 | } |
| 403 | 406 | |
| 404 | 407 | return $type; |
| @@ -450,9 +453,9 @@ | ||
| 450 | 453 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
| 451 | 454 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
| 452 | 455 | |
| 453 | 456 | if ( $echo ) { |
| 454 | - echo $add_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 457 | + echo $add_html; // WPCS: XSS ok. | |
| 455 | 458 | } |
| 456 | 459 | |
| 457 | 460 | return $add_html; |
| 458 | 461 | } |
| @@ -500,9 +503,9 @@ | ||
| 500 | 503 | self::add_html_cols( $field, $add_html ); |
| 501 | 504 | } |
| 502 | 505 | |
| 503 | 506 | private static function add_html_cols( $field, array &$add_html ) { |
| 504 | - if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { | |
| 507 | + if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) { | |
| 505 | 508 | return; |
| 506 | 509 | } |
| 507 | 510 | |
| 508 | 511 | // Convert to cols for textareas. |
| @@ -576,18 +579,21 @@ | ||
| 576 | 579 | } |
| 577 | 580 | } |
| 578 | 581 | |
| 579 | 582 | /** |
| 580 | - * Prepares field placeholder. | |
| 581 | - * | |
| 582 | - * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore. | |
| 583 | - * | |
| 584 | - * @param array $field Field array. | |
| 583 | + * @param array $field | |
| 585 | 584 | * @return string |
| 586 | 585 | */ |
| 587 | 586 | private static function prepare_placeholder( $field ) { |
| 588 | - $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 587 | + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; | |
| 588 | + $placeholder_is_blank = empty( $placeholder ) && '0' !== $placeholder; | |
| 589 | + $is_placeholder_field = FrmFieldsHelper::is_placeholder_field_type( $field['type'] ); | |
| 590 | + $is_combo_field = in_array( $field['type'], array( 'address', 'credit_card' ), true ); | |
| 589 | 591 | |
| 592 | + if ( $placeholder_is_blank && $is_placeholder_field && ! $is_combo_field ) { | |
| 593 | + $placeholder = self::get_default_value_from_name( $field ); | |
| 594 | + } | |
| 595 | + | |
| 590 | 596 | return $placeholder; |
| 591 | 597 | } |
| 592 | 598 | |
| 593 | 599 | /** |
| @@ -594,9 +600,8 @@ | ||
| 594 | 600 | * If the label position is "inside", |
| 595 | 601 | * get the label to use as the placeholder |
| 596 | 602 | * |
| 597 | 603 | * @since 2.05 |
| 598 | - * @since 5.4 Remove the logic code for "inside" label position. | |
| 599 | 604 | * |
| 600 | 605 | * @param array $field |
| 601 | 606 | * |
| 602 | 607 | * @return string |
| @@ -601,9 +606,19 @@ | ||
| 601 | 606 | * |
| 602 | 607 | * @return string |
| 603 | 608 | */ |
| 604 | 609 | public static function get_default_value_from_name( $field ) { |
| 605 | - return ''; | |
| 610 | + $position = FrmField::get_option( $field, 'label' ); | |
| 611 | + if ( $position == 'inside' ) { | |
| 612 | + $default_value = $field['name']; | |
| 613 | + if ( FrmField::is_required( $field ) ) { | |
| 614 | + $default_value .= ' ' . $field['required_indicator']; | |
| 615 | + } | |
| 616 | + } else { | |
| 617 | + $default_value = ''; | |
| 618 | + } | |
| 619 | + | |
| 620 | + return $default_value; | |
| 606 | 621 | } |
| 607 | 622 | |
| 608 | 623 | /** |
| 609 | 624 | * Maybe add a blank placeholder option before any options |
| @@ -619,9 +634,9 @@ | ||
| 619 | 634 | } |
| 620 | 635 | |
| 621 | 636 | if ( $placeholder !== '' ) { |
| 622 | 637 | ?> |
| 623 | - <option class="frm-select-placeholder" value=""> | |
| 638 | + <option value=""> | |
| 624 | 639 | <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?> |
| 625 | 640 | </option> |
| 626 | 641 | <?php |
| 627 | 642 | return true; |
| @@ -737,11 +752,9 @@ | ||
| 737 | 752 | |
| 738 | 753 | $error_body = substr( $custom_html, $start + 10, $end - $start - 10 ); |
| 739 | 754 | $default_html = array( |
| 740 | 755 | '<div class="frm_error" id="frm_error_field_[key]">[error]</div>', |
| 741 | - '<div class="frm_error" role="alert" id="frm_error_field_[key]">[error]</div>', | |
| 742 | 756 | '<div class="frm_error">[error]</div>', |
| 743 | - '<div class="frm_error" role="alert">[error]</div>', | |
| 744 | 757 | ); |
| 745 | 758 | |
| 746 | 759 | if ( in_array( $error_body, $default_html, true ) ) { |
| 747 | 760 | return false; |
| @@ -759,16 +772,9 @@ | ||
| 759 | 772 | * @param array $field |
| 760 | 773 | * @param array $add_html |
| 761 | 774 | */ |
| 762 | 775 | private static function maybe_add_html_required( $field, array &$add_html ) { |
| 763 | - $excluded_field_types = | |
| 764 | - FrmField::is_radio( $field ) || | |
| 765 | - FrmField::is_checkbox( $field ) || | |
| 766 | - FrmField::is_field_type( $field, 'file' ) || | |
| 767 | - FrmField::is_field_type( $field, 'nps' ) || | |
| 768 | - FrmField::is_field_type( $field, 'scale' ); | |
| 769 | - | |
| 770 | - if ( $excluded_field_types ) { | |
| 776 | + if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) { | |
| 771 | 777 | return; |
| 772 | 778 | } |
| 773 | 779 | |
| 774 | 780 | $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' ); |
| @@ -781,12 +787,8 @@ | ||
| 781 | 787 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| 782 | 788 | return; |
| 783 | 789 | } |
| 784 | 790 | |
| 785 | - if ( ! empty( $field['autocomplete'] ) ) { | |
| 786 | - unset( $field['shortcodes']['autocomplete'] ); | |
| 787 | - } | |
| 788 | - | |
| 789 | 791 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 790 | 792 | if ( 'opt' === $k ) { |
| 791 | 793 | continue; |
| 792 | 794 | } |
| @@ -892,9 +894,12 @@ | ||
| 892 | 894 | * |
| 893 | 895 | * @deprecated 4.0 Moved to Pro for Other option only. |
| 894 | 896 | */ |
| 895 | 897 | public static function add_option() { |
| 896 | - _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' ); | |
| 898 | + _deprecated_function( __METHOD__, '4.0', 'FrmProFormsController::add_other_option' ); | |
| 899 | + if ( is_callable( 'FrmProFormsController::add_other_option' ) ) { | |
| 900 | + FrmProFormsController::add_other_option(); | |
| 901 | + } | |
| 897 | 902 | } |
| 898 | 903 | |
| 899 | 904 | /** |
| 900 | 905 | * @deprecated 4.0 |
| @@ -922,6 +927,22 @@ | ||
| 922 | 927 | * @return array |
| 923 | 928 | */ |
| 924 | 929 | public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
| 925 | 930 | return FrmDeprecated::include_single_field( $field_id, $values, $form_id ); |
| 931 | + } | |
| 932 | + | |
| 933 | + /** | |
| 934 | + * @deprecated 2.3 | |
| 935 | + * @codeCoverageIgnore | |
| 936 | + */ | |
| 937 | + public static function edit_option() { | |
| 938 | + FrmDeprecated::deprecated( __METHOD__, '2.3' ); | |
| 939 | + } | |
| 940 | + | |
| 941 | + /** | |
| 942 | + * @deprecated 2.3 | |
| 943 | + * @codeCoverageIgnore | |
| 944 | + */ | |
| 945 | + public static function delete_option() { | |
| 946 | + FrmDeprecated::deprecated( __METHOD__, '2.3' ); | |
| 926 | 947 | } |
| 927 | 948 | } |