| @@ -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 | } |
| @@ -114,12 +111,25 @@ | ||
| 114 | 111 | |
| 115 | 112 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
| 116 | 113 | $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); |
| 117 | 114 | |
| 118 | - $new_field = FrmField::duplicate_single_field( $field_id, $form_id ); | |
| 115 | + $copy_field = FrmField::getOne( $field_id ); | |
| 116 | + if ( ! $copy_field ) { | |
| 117 | + wp_die(); | |
| 118 | + } | |
| 119 | 119 | |
| 120 | - if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) { | |
| 121 | - self::load_single_field( $new_field['field_id'], $new_field['values'] ); | |
| 120 | + do_action( 'frm_duplicate_field', $copy_field, $form_id ); | |
| 121 | + do_action( 'frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id ); | |
| 122 | + | |
| 123 | + $values = array( | |
| 124 | + 'id' => $copy_field->id, | |
| 125 | + ); | |
| 126 | + FrmFieldsHelper::fill_field( $values, $copy_field, $copy_field->form_id ); | |
| 127 | + $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values ); | |
| 128 | + | |
| 129 | + $field_id = FrmField::create( $values ); | |
| 130 | + if ( $field_id ) { | |
| 131 | + self::load_single_field( $field_id, $values ); | |
| 122 | 132 | } |
| 123 | 133 | |
| 124 | 134 | wp_die(); |
| 125 | 135 | } |
| @@ -181,18 +191,19 @@ | ||
| 181 | 191 | /** |
| 182 | 192 | * @since 3.0 |
| 183 | 193 | */ |
| 184 | 194 | private static function get_classes_for_builder_field( $field, $display, $field_info ) { |
| 185 | - $li_classes = $field_info->form_builder_classes( $display['type'] ); | |
| 186 | - $li_classes .= ' frm_form_field frmstart '; | |
| 195 | + $li_classes = $field_info->form_builder_classes( $display['type'] ); | |
| 196 | + $classes = isset( $field['classes'] ) ? $field['classes'] : ''; | |
| 187 | 197 | |
| 188 | - if ( isset( $field['classes'] ) ) { | |
| 189 | - $li_classes .= trim( $field['classes'] ) . ' '; | |
| 198 | + // Exclude alignright for now since we aren't using widths. | |
| 199 | + $classes = str_replace( ' frm_alignright ', ' ', $classes ); | |
| 200 | + if ( trim( $classes ) === 'frm_alignright' ) { | |
| 201 | + $classes = ''; | |
| 190 | 202 | } |
| 191 | 203 | |
| 192 | - $li_classes .= 'frmend'; | |
| 193 | - | |
| 194 | - if ( $field ) { | |
| 204 | + $li_classes .= ' frm_form_field frmstart ' . $classes . ' frmend'; | |
| 205 | + if ( ! empty( $field ) ) { | |
| 195 | 206 | $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field ); |
| 196 | 207 | } |
| 197 | 208 | |
| 198 | 209 | return $li_classes; |
| @@ -315,10 +326,9 @@ | ||
| 315 | 326 | |
| 316 | 327 | if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) { |
| 317 | 328 | $field['placeholder'] = implode( ', ', $field['placeholder'] ); |
| 318 | 329 | } |
| 319 | - | |
| 320 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php'; | |
| 330 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' ); | |
| 321 | 331 | } |
| 322 | 332 | |
| 323 | 333 | /** |
| 324 | 334 | * Get the list of default value types that can be toggled in the builder. |
| @@ -392,13 +402,10 @@ | ||
| 392 | 402 | $type = $type_switch[ $type ]; |
| 393 | 403 | } |
| 394 | 404 | |
| 395 | 405 | $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 ) ) { | |
| 406 | + $types = array_keys( $pro_fields ); | |
| 407 | + if ( in_array( $type, $types ) ) { | |
| 401 | 408 | $type = 'text'; |
| 402 | 409 | } |
| 403 | 410 | |
| 404 | 411 | return $type; |
| @@ -450,9 +457,9 @@ | ||
| 450 | 457 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
| 451 | 458 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
| 452 | 459 | |
| 453 | 460 | if ( $echo ) { |
| 454 | - echo $add_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 461 | + echo $add_html; // WPCS: XSS ok. | |
| 455 | 462 | } |
| 456 | 463 | |
| 457 | 464 | return $add_html; |
| 458 | 465 | } |
| @@ -500,9 +507,9 @@ | ||
| 500 | 507 | self::add_html_cols( $field, $add_html ); |
| 501 | 508 | } |
| 502 | 509 | |
| 503 | 510 | private static function add_html_cols( $field, array &$add_html ) { |
| 504 | - if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) { | |
| 511 | + if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) { | |
| 505 | 512 | return; |
| 506 | 513 | } |
| 507 | 514 | |
| 508 | 515 | // Convert to cols for textareas. |
| @@ -575,18 +582,16 @@ | ||
| 575 | 582 | } |
| 576 | 583 | } |
| 577 | 584 | } |
| 578 | 585 | |
| 579 | - /** | |
| 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. | |
| 585 | - * @return string | |
| 586 | - */ | |
| 587 | 586 | private static function prepare_placeholder( $field ) { |
| 587 | + $is_placeholder_field = FrmFieldsHelper::is_placeholder_field_type( $field['type'] ); | |
| 588 | + $is_combo_field = in_array( $field['type'], array( 'address', 'credit_card' ) ); | |
| 589 | + | |
| 588 | 590 | $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; |
| 591 | + if ( empty( $placeholder ) && $is_placeholder_field && ! $is_combo_field ) { | |
| 592 | + $placeholder = self::get_default_value_from_name( $field ); | |
| 593 | + } | |
| 589 | 594 | |
| 590 | 595 | return $placeholder; |
| 591 | 596 | } |
| 592 | 597 | |
| @@ -594,9 +599,8 @@ | ||
| 594 | 599 | * If the label position is "inside", |
| 595 | 600 | * get the label to use as the placeholder |
| 596 | 601 | * |
| 597 | 602 | * @since 2.05 |
| 598 | - * @since 5.4 Remove the logic code for "inside" label position. | |
| 599 | 603 | * |
| 600 | 604 | * @param array $field |
| 601 | 605 | * |
| 602 | 606 | * @return string |
| @@ -601,9 +605,19 @@ | ||
| 601 | 605 | * |
| 602 | 606 | * @return string |
| 603 | 607 | */ |
| 604 | 608 | public static function get_default_value_from_name( $field ) { |
| 605 | - return ''; | |
| 609 | + $position = FrmField::get_option( $field, 'label' ); | |
| 610 | + if ( $position == 'inside' ) { | |
| 611 | + $default_value = $field['name']; | |
| 612 | + if ( FrmField::is_required( $field ) ) { | |
| 613 | + $default_value .= ' ' . $field['required_indicator']; | |
| 614 | + } | |
| 615 | + } else { | |
| 616 | + $default_value = ''; | |
| 617 | + } | |
| 618 | + | |
| 619 | + return $default_value; | |
| 606 | 620 | } |
| 607 | 621 | |
| 608 | 622 | /** |
| 609 | 623 | * Maybe add a blank placeholder option before any options |
| @@ -666,93 +680,12 @@ | ||
| 666 | 680 | if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) { |
| 667 | 681 | $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
| 668 | 682 | $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"'; |
| 669 | 683 | } |
| 670 | - | |
| 671 | - if ( ! empty( $add_html['data-reqmsg'] ) || ! empty( $add_html['data-invmsg'] ) ) { | |
| 672 | - self::maybe_add_error_html_for_js_validation( $field, $add_html ); | |
| 673 | - } | |
| 674 | 684 | } |
| 675 | 685 | |
| 676 | 686 | /** |
| 677 | - * @since 5.0.03 | |
| 678 | - * | |
| 679 | - * @param array $field | |
| 680 | - * @param array $add_html | |
| 681 | - */ | |
| 682 | - private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) { | |
| 683 | - $form = self::get_form_for_js_validation( $field ); | |
| 684 | - if ( false === $form ) { | |
| 685 | - return; | |
| 686 | - } | |
| 687 | - | |
| 688 | - $error_body = self::pull_custom_error_body_from_custom_html( $form, $field ); | |
| 689 | - if ( false !== $error_body ) { | |
| 690 | - $error_body = urlencode( $error_body ); | |
| 691 | - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"'; | |
| 692 | - } | |
| 693 | - } | |
| 694 | - | |
| 695 | - /** | |
| 696 | - * @since 5.0.03 | |
| 697 | - * | |
| 698 | - * @param array $field | |
| 699 | - * @return stdClass|false false if there is no form object found with JS validation active. | |
| 700 | - */ | |
| 701 | - private static function get_form_for_js_validation( $field ) { | |
| 702 | - global $frm_vars; | |
| 703 | - if ( ! empty( $frm_vars['js_validate_forms'] ) ) { | |
| 704 | - if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) { | |
| 705 | - return $frm_vars['js_validate_forms'][ $field['form_id'] ]; | |
| 706 | - } | |
| 707 | - if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) { | |
| 708 | - return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ]; | |
| 709 | - } | |
| 710 | - } | |
| 711 | - return false; | |
| 712 | - } | |
| 713 | - | |
| 714 | - /** | |
| 715 | - * @param stdClass $form | |
| 716 | - * @param array $field | |
| 717 | - * @param array $errors | |
| 718 | - * @return string|false | |
| 719 | - */ | |
| 720 | - public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) { | |
| 721 | - if ( empty( $field['custom_html'] ) ) { | |
| 722 | - return false; | |
| 723 | - } | |
| 724 | - | |
| 725 | - $custom_html = $field['custom_html']; | |
| 726 | - $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form ); | |
| 727 | - | |
| 728 | - $start = strpos( $custom_html, '[if error]' ); | |
| 729 | - if ( false === $start ) { | |
| 730 | - return false; | |
| 731 | - } | |
| 732 | - | |
| 733 | - $end = strpos( $custom_html, '[/if error]' ); | |
| 734 | - if ( false === $end || $end < $start ) { | |
| 735 | - return false; | |
| 736 | - } | |
| 737 | - | |
| 738 | - $error_body = substr( $custom_html, $start + 10, $end - $start - 10 ); | |
| 739 | - $default_html = array( | |
| 740 | - '<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 | - '<div class="frm_error">[error]</div>', | |
| 743 | - '<div class="frm_error" role="alert">[error]</div>', | |
| 744 | - ); | |
| 745 | - | |
| 746 | - if ( in_array( $error_body, $default_html, true ) ) { | |
| 747 | - return false; | |
| 748 | - } | |
| 749 | - | |
| 750 | - return $error_body; | |
| 751 | - } | |
| 752 | - | |
| 753 | - /** | |
| 754 | - * If 'required' is added to a conditionally hidden field, the form won't | |
| 687 | + * If 'required' is added to a conditionall hidden field, the form won't | |
| 755 | 688 | * submit in many browsers. Check to make sure the javascript to conditionally |
| 756 | 689 | * remove it is present if needed. |
| 757 | 690 | * |
| 758 | 691 | * @since 3.06.01 |
| @@ -759,16 +692,9 @@ | ||
| 759 | 692 | * @param array $field |
| 760 | 693 | * @param array $add_html |
| 761 | 694 | */ |
| 762 | 695 | 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 ) { | |
| 696 | + if ( in_array( $field['type'], array( 'radio', 'checkbox', 'file', 'data', 'lookup' ) ) ) { | |
| 771 | 697 | return; |
| 772 | 698 | } |
| 773 | 699 | |
| 774 | 700 | $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' ); |
| @@ -781,12 +707,8 @@ | ||
| 781 | 707 | if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
| 782 | 708 | return; |
| 783 | 709 | } |
| 784 | 710 | |
| 785 | - if ( ! empty( $field['autocomplete'] ) ) { | |
| 786 | - unset( $field['shortcodes']['autocomplete'] ); | |
| 787 | - } | |
| 788 | - | |
| 789 | 711 | foreach ( $field['shortcodes'] as $k => $v ) { |
| 790 | 712 | if ( 'opt' === $k ) { |
| 791 | 713 | continue; |
| 792 | 714 | } |
| @@ -892,9 +814,12 @@ | ||
| 892 | 814 | * |
| 893 | 815 | * @deprecated 4.0 Moved to Pro for Other option only. |
| 894 | 816 | */ |
| 895 | 817 | public static function add_option() { |
| 896 | - _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' ); | |
| 818 | + _deprecated_function( __METHOD__, '4.0', 'FrmProFormsController::add_other_option' ); | |
| 819 | + if ( is_callable( 'FrmProFormsController::add_other_option' ) ) { | |
| 820 | + FrmProFormsController::add_other_option(); | |
| 821 | + } | |
| 897 | 822 | } |
| 898 | 823 | |
| 899 | 824 | /** |
| 900 | 825 | * @deprecated 4.0 |
| @@ -922,6 +847,22 @@ | ||
| 922 | 847 | * @return array |
| 923 | 848 | */ |
| 924 | 849 | public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
| 925 | 850 | return FrmDeprecated::include_single_field( $field_id, $values, $form_id ); |
| 851 | + } | |
| 852 | + | |
| 853 | + /** | |
| 854 | + * @deprecated 2.3 | |
| 855 | + * @codeCoverageIgnore | |
| 856 | + */ | |
| 857 | + public static function edit_option() { | |
| 858 | + FrmDeprecated::deprecated( __METHOD__, '2.3' ); | |
| 859 | + } | |
| 860 | + | |
| 861 | + /** | |
| 862 | + * @deprecated 2.3 | |
| 863 | + * @codeCoverageIgnore | |
| 864 | + */ | |
| 865 | + public static function delete_option() { | |
| 866 | + FrmDeprecated::deprecated( __METHOD__, '2.3' ); | |
| 926 | 867 | } |
| 927 | 868 | } |