PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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 +72 -103 6.35.0 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,13 +191,23 @@
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'] );
195 + $li_classes = $field_info->form_builder_classes( $display['type'] );
196 + $classes = isset( $field['classes'] ) ? $field['classes'] : '';
197 +
198 + // Exclude alignright for now since we aren't using widths.
199 + $classes = str_replace( ' frm_alignright ', ' ', $classes );
200 + $classes = trim( $classes );
201 +
202 + if ( 'frm_alignright' === $classes ) {
203 + $classes = '';
204 + }
205 +
183 206 $li_classes .= ' frm_form_field frmstart ';
184 207
185 - if ( isset( $field['classes'] ) ) {
186 - $li_classes .= trim( $field['classes'] ) . ' ';
208 + if ( $classes ) {
209 + $li_classes .= $classes . ' ';
187 210 }
188 211
189 212 $li_classes .= 'frmend';
190 213
@@ -443,9 +466,9 @@
443 466 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
444 467 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
445 468
446 469 if ( $echo ) {
447 - echo $add_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
470 + echo $add_html; // WPCS: XSS ok.
448 471 }
449 472
450 473 return $add_html;
451 474 }
@@ -569,18 +592,21 @@
569 592 }
570 593 }
571 594
572 595 /**
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.
596 + * @param array $field
578 597 * @return string
579 598 */
580 599 private static function prepare_placeholder( $field ) {
581 - $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
600 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
601 + $placeholder_is_blank = empty( $placeholder ) && '0' !== $placeholder;
602 + $is_placeholder_field = FrmFieldsHelper::is_placeholder_field_type( $field['type'] );
603 + $is_combo_field = in_array( $field['type'], array( 'address', 'credit_card' ), true );
582 604
605 + if ( $placeholder_is_blank && $is_placeholder_field && ! $is_combo_field ) {
606 + $placeholder = self::get_default_value_from_name( $field );
607 + }
608 +
583 609 return $placeholder;
584 610 }
585 611
586 612 /**
@@ -587,9 +613,8 @@
587 613 * If the label position is "inside",
588 614 * get the label to use as the placeholder
589 615 *
590 616 * @since 2.05
591 - * @since 5.4 Remove the logic code for "inside" label position.
592 617 *
593 618 * @param array $field
594 619 *
595 620 * @return string
@@ -594,9 +619,19 @@
594 619 *
595 620 * @return string
596 621 */
597 622 public static function get_default_value_from_name( $field ) {
598 - return '';
623 + $position = FrmField::get_option( $field, 'label' );
624 + if ( $position == 'inside' ) {
625 + $default_value = $field['name'];
626 + if ( FrmField::is_required( $field ) ) {
627 + $default_value .= ' ' . $field['required_indicator'];
628 + }
629 + } else {
630 + $default_value = '';
631 + }
632 +
633 + return $default_value;
599 634 }
600 635
601 636 /**
602 637 * Maybe add a blank placeholder option before any options
@@ -659,93 +694,12 @@
659 694 if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
660 695 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
661 696 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
662 697 }
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 698 }
668 699
669 700 /**
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
701 + * If 'required' is added to a conditionall hidden field, the form won't
748 702 * submit in many browsers. Check to make sure the javascript to conditionally
749 703 * remove it is present if needed.
750 704 *
751 705 * @since 3.06.01
@@ -752,9 +706,9 @@
752 706 * @param array $field
753 707 * @param array $add_html
754 708 */
755 709 private static function maybe_add_html_required( $field, array &$add_html ) {
756 - if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) {
710 + if ( in_array( $field['type'], array( 'radio', 'checkbox', 'file', 'data', 'lookup' ) ) ) {
757 711 return;
758 712 }
759 713
760 714 $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
@@ -767,12 +721,8 @@
767 721 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
768 722 return;
769 723 }
770 724
771 - if ( ! empty( $field['autocomplete'] ) ) {
772 - unset( $field['shortcodes']['autocomplete'] );
773 - }
774 -
775 725 foreach ( $field['shortcodes'] as $k => $v ) {
776 726 if ( 'opt' === $k ) {
777 727 continue;
778 728 }
@@ -878,9 +828,12 @@
878 828 *
879 829 * @deprecated 4.0 Moved to Pro for Other option only.
880 830 */
881 831 public static function add_option() {
882 - _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
832 + _deprecated_function( __METHOD__, '4.0', 'FrmProFormsController::add_other_option' );
833 + if ( is_callable( 'FrmProFormsController::add_other_option' ) ) {
834 + FrmProFormsController::add_other_option();
835 + }
883 836 }
884 837
885 838 /**
886 839 * @deprecated 4.0
@@ -908,6 +861,22 @@
908 861 * @return array
909 862 */
910 863 public static function include_single_field( $field_id, $values, $form_id = 0 ) {
911 864 return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
865 + }
866 +
867 + /**
868 + * @deprecated 2.3
869 + * @codeCoverageIgnore
870 + */
871 + public static function edit_option() {
872 + FrmDeprecated::deprecated( __METHOD__, '2.3' );
873 + }
874 +
875 + /**
876 + * @deprecated 2.3
877 + * @codeCoverageIgnore
878 + */
879 + public static function delete_option() {
880 + FrmDeprecated::deprecated( __METHOD__, '2.3' );
912 881 }
913 882 }