PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.10.03
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.10.03
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 +67 -107 6.44.10.03 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 }
@@ -569,18 +583,21 @@
569 583 }
570 584 }
571 585
572 586 /**
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.
587 + * @param array $field
578 588 * @return string
579 589 */
580 590 private static function prepare_placeholder( $field ) {
581 - $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
591 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
592 + $placeholder_is_blank = empty( $placeholder ) && '0' !== $placeholder;
593 + $is_placeholder_field = FrmFieldsHelper::is_placeholder_field_type( $field['type'] );
594 + $is_combo_field = in_array( $field['type'], array( 'address', 'credit_card' ), true );
582 595
596 + if ( $placeholder_is_blank && $is_placeholder_field && ! $is_combo_field ) {
597 + $placeholder = self::get_default_value_from_name( $field );
598 + }
599 +
583 600 return $placeholder;
584 601 }
585 602
586 603 /**
@@ -587,9 +604,8 @@
587 604 * If the label position is "inside",
588 605 * get the label to use as the placeholder
589 606 *
590 607 * @since 2.05
591 - * @since 5.4 Remove the logic code for "inside" label position.
592 608 *
593 609 * @param array $field
594 610 *
595 611 * @return string
@@ -594,9 +610,19 @@
594 610 *
595 611 * @return string
596 612 */
597 613 public static function get_default_value_from_name( $field ) {
598 - return '';
614 + $position = FrmField::get_option( $field, 'label' );
615 + if ( $position == 'inside' ) {
616 + $default_value = $field['name'];
617 + if ( FrmField::is_required( $field ) ) {
618 + $default_value .= ' ' . $field['required_indicator'];
619 + }
620 + } else {
621 + $default_value = '';
622 + }
623 +
624 + return $default_value;
599 625 }
600 626
601 627 /**
602 628 * Maybe add a blank placeholder option before any options
@@ -659,93 +685,12 @@
659 685 if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
660 686 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
661 687 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
662 688 }
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 689 }
668 690
669 691 /**
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
692 + * If 'required' is added to a conditionall hidden field, the form won't
748 693 * submit in many browsers. Check to make sure the javascript to conditionally
749 694 * remove it is present if needed.
750 695 *
751 696 * @since 3.06.01
@@ -752,9 +697,9 @@
752 697 * @param array $field
753 698 * @param array $add_html
754 699 */
755 700 private static function maybe_add_html_required( $field, array &$add_html ) {
756 - if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) {
701 + if ( in_array( $field['type'], array( 'radio', 'checkbox', 'file', 'data', 'lookup' ) ) ) {
757 702 return;
758 703 }
759 704
760 705 $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
@@ -767,12 +712,8 @@
767 712 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
768 713 return;
769 714 }
770 715
771 - if ( ! empty( $field['autocomplete'] ) ) {
772 - unset( $field['shortcodes']['autocomplete'] );
773 - }
774 -
775 716 foreach ( $field['shortcodes'] as $k => $v ) {
776 717 if ( 'opt' === $k ) {
777 718 continue;
778 719 }
@@ -878,9 +819,12 @@
878 819 *
879 820 * @deprecated 4.0 Moved to Pro for Other option only.
880 821 */
881 822 public static function add_option() {
882 - _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
823 + _deprecated_function( __METHOD__, '4.0', 'FrmProFormsController::add_other_option' );
824 + if ( is_callable( 'FrmProFormsController::add_other_option' ) ) {
825 + FrmProFormsController::add_other_option();
826 + }
883 827 }
884 828
885 829 /**
886 830 * @deprecated 4.0
@@ -908,6 +852,22 @@
908 852 * @return array
909 853 */
910 854 public static function include_single_field( $field_id, $values, $form_id = 0 ) {
911 855 return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
856 + }
857 +
858 + /**
859 + * @deprecated 2.3
860 + * @codeCoverageIgnore
861 + */
862 + public static function edit_option() {
863 + FrmDeprecated::deprecated( __METHOD__, '2.3' );
864 + }
865 +
866 + /**
867 + * @deprecated 2.3
868 + * @codeCoverageIgnore
869 + */
870 + public static function delete_option() {
871 + FrmDeprecated::deprecated( __METHOD__, '2.3' );
912 872 }
913 873 }