PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.07.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.07.01
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 +64 -109 6.34.07.01 View file →
@@ -111,12 +111,25 @@
111 111
112 112 $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
113 113 $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
114 114
115 - $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 + }
116 119
117 - if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) {
118 - 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 );
119 132 }
120 133
121 134 wp_die();
122 135 }
@@ -178,18 +191,19 @@
178 191 /**
179 192 * @since 3.0
180 193 */
181 194 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
182 - $li_classes = $field_info->form_builder_classes( $display['type'] );
183 - $li_classes .= ' frm_form_field frmstart ';
195 + $li_classes = $field_info->form_builder_classes( $display['type'] );
196 + $classes = isset( $field['classes'] ) ? $field['classes'] : '';
184 197
185 - if ( isset( $field['classes'] ) ) {
186 - $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 = '';
187 202 }
188 203
189 - $li_classes .= 'frmend';
190 -
191 - if ( $field ) {
204 + $li_classes .= ' frm_form_field frmstart ' . $classes . ' frmend';
205 + if ( ! empty( $field ) ) {
192 206 $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
193 207 }
194 208
195 209 return $li_classes;
@@ -443,9 +457,9 @@
443 457 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
444 458 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
445 459
446 460 if ( $echo ) {
447 - echo $add_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
461 + echo $add_html; // WPCS: XSS ok.
448 462 }
449 463
450 464 return $add_html;
451 465 }
@@ -568,18 +582,16 @@
568 582 }
569 583 }
570 584 }
571 585
572 - /**
573 - * Prepares field placeholder.
574 - *
575 - * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
576 - *
577 - * @param array $field Field array.
578 - * @return string
579 - */
580 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 +
581 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 + }
582 594
583 595 return $placeholder;
584 596 }
585 597
@@ -587,9 +599,8 @@
587 599 * If the label position is "inside",
588 600 * get the label to use as the placeholder
589 601 *
590 602 * @since 2.05
591 - * @since 5.4 Remove the logic code for "inside" label position.
592 603 *
593 604 * @param array $field
594 605 *
595 606 * @return string
@@ -594,9 +605,19 @@
594 605 *
595 606 * @return string
596 607 */
597 608 public static function get_default_value_from_name( $field ) {
598 - 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;
599 620 }
600 621
601 622 /**
602 623 * Maybe add a blank placeholder option before any options
@@ -659,93 +680,12 @@
659 680 if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
660 681 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
661 682 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
662 683 }
663 -
664 - if ( ! empty( $add_html['data-reqmsg'] ) || ! empty( $add_html['data-invmsg'] ) ) {
665 - self::maybe_add_error_html_for_js_validation( $field, $add_html );
666 - }
667 684 }
668 685
669 686 /**
670 - * @since 5.0.03
671 - *
672 - * @param array $field
673 - * @param array $add_html
674 - */
675 - private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
676 - $form = self::get_form_for_js_validation( $field );
677 - if ( false === $form ) {
678 - return;
679 - }
680 -
681 - $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
682 - if ( false !== $error_body ) {
683 - $error_body = urlencode( $error_body );
684 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
685 - }
686 - }
687 -
688 - /**
689 - * @since 5.0.03
690 - *
691 - * @param array $field
692 - * @return stdClass|false false if there is no form object found with JS validation active.
693 - */
694 - private static function get_form_for_js_validation( $field ) {
695 - global $frm_vars;
696 - if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
697 - if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
698 - return $frm_vars['js_validate_forms'][ $field['form_id'] ];
699 - }
700 - if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
701 - return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
702 - }
703 - }
704 - return false;
705 - }
706 -
707 - /**
708 - * @param stdClass $form
709 - * @param array $field
710 - * @param array $errors
711 - * @return string|false
712 - */
713 - public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
714 - if ( empty( $field['custom_html'] ) ) {
715 - return false;
716 - }
717 -
718 - $custom_html = $field['custom_html'];
719 - $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
720 -
721 - $start = strpos( $custom_html, '[if error]' );
722 - if ( false === $start ) {
723 - return false;
724 - }
725 -
726 - $end = strpos( $custom_html, '[/if error]' );
727 - if ( false === $end || $end < $start ) {
728 - return false;
729 - }
730 -
731 - $error_body = substr( $custom_html, $start + 10, $end - $start - 10 );
732 - $default_html = array(
733 - '<div class="frm_error" id="frm_error_field_[key]">[error]</div>',
734 - '<div class="frm_error" role="alert" id="frm_error_field_[key]">[error]</div>',
735 - '<div class="frm_error">[error]</div>',
736 - '<div class="frm_error" role="alert">[error]</div>',
737 - );
738 -
739 - if ( in_array( $error_body, $default_html, true ) ) {
740 - return false;
741 - }
742 -
743 - return $error_body;
744 - }
745 -
746 - /**
747 - * 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
748 688 * submit in many browsers. Check to make sure the javascript to conditionally
749 689 * remove it is present if needed.
750 690 *
751 691 * @since 3.06.01
@@ -752,9 +692,9 @@
752 692 * @param array $field
753 693 * @param array $add_html
754 694 */
755 695 private static function maybe_add_html_required( $field, array &$add_html ) {
756 - if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) {
696 + if ( in_array( $field['type'], array( 'radio', 'checkbox', 'file', 'data', 'lookup' ) ) ) {
757 697 return;
758 698 }
759 699
760 700 $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
@@ -767,12 +707,8 @@
767 707 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
768 708 return;
769 709 }
770 710
771 - if ( ! empty( $field['autocomplete'] ) ) {
772 - unset( $field['shortcodes']['autocomplete'] );
773 - }
774 -
775 711 foreach ( $field['shortcodes'] as $k => $v ) {
776 712 if ( 'opt' === $k ) {
777 713 continue;
778 714 }
@@ -878,9 +814,12 @@
878 814 *
879 815 * @deprecated 4.0 Moved to Pro for Other option only.
880 816 */
881 817 public static function add_option() {
882 - _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 + }
883 822 }
884 823
885 824 /**
886 825 * @deprecated 4.0
@@ -908,6 +847,22 @@
908 847 * @return array
909 848 */
910 849 public static function include_single_field( $field_id, $values, $form_id = 0 ) {
911 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' );
912 867 }
913 868 }