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 +78 -123 6.55.0 View file →
@@ -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,13 +191,23 @@
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'] );
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 +
186 206 $li_classes .= ' frm_form_field frmstart ';
187 207
188 - if ( isset( $field['classes'] ) ) {
189 - $li_classes .= trim( $field['classes'] ) . ' ';
208 + if ( $classes ) {
209 + $li_classes .= $classes . ' ';
190 210 }
191 211
192 212 $li_classes .= 'frmend';
193 213
@@ -315,10 +335,9 @@
315 335
316 336 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
317 337 $field['placeholder'] = implode( ', ', $field['placeholder'] );
318 338 }
319 -
320 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
339 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
321 340 }
322 341
323 342 /**
324 343 * Get the list of default value types that can be toggled in the builder.
@@ -392,13 +411,10 @@
392 411 $type = $type_switch[ $type ];
393 412 }
394 413
395 414 $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 ) ) {
415 + $types = array_keys( $pro_fields );
416 + if ( in_array( $type, $types ) ) {
401 417 $type = 'text';
402 418 }
403 419
404 420 return $type;
@@ -450,9 +466,9 @@
450 466 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
451 467 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
452 468
453 469 if ( $echo ) {
454 - echo $add_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
470 + echo $add_html; // WPCS: XSS ok.
455 471 }
456 472
457 473 return $add_html;
458 474 }
@@ -500,9 +516,9 @@
500 516 self::add_html_cols( $field, $add_html );
501 517 }
502 518
503 519 private static function add_html_cols( $field, array &$add_html ) {
504 - if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
520 + if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
505 521 return;
506 522 }
507 523
508 524 // Convert to cols for textareas.
@@ -576,18 +592,21 @@
576 592 }
577 593 }
578 594
579 595 /**
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.
596 + * @param array $field
585 597 * @return string
586 598 */
587 599 private static function prepare_placeholder( $field ) {
588 - $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 );
589 604
605 + if ( $placeholder_is_blank && $is_placeholder_field && ! $is_combo_field ) {
606 + $placeholder = self::get_default_value_from_name( $field );
607 + }
608 +
590 609 return $placeholder;
591 610 }
592 611
593 612 /**
@@ -594,9 +613,8 @@
594 613 * If the label position is "inside",
595 614 * get the label to use as the placeholder
596 615 *
597 616 * @since 2.05
598 - * @since 5.4 Remove the logic code for "inside" label position.
599 617 *
600 618 * @param array $field
601 619 *
602 620 * @return string
@@ -601,9 +619,19 @@
601 619 *
602 620 * @return string
603 621 */
604 622 public static function get_default_value_from_name( $field ) {
605 - 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;
606 634 }
607 635
608 636 /**
609 637 * Maybe add a blank placeholder option before any options
@@ -666,93 +694,12 @@
666 694 if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
667 695 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
668 696 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
669 697 }
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 698 }
675 699
676 700 /**
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
701 + * If 'required' is added to a conditionall hidden field, the form won't
755 702 * submit in many browsers. Check to make sure the javascript to conditionally
756 703 * remove it is present if needed.
757 704 *
758 705 * @since 3.06.01
@@ -759,16 +706,9 @@
759 706 * @param array $field
760 707 * @param array $add_html
761 708 */
762 709 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 ) {
710 + if ( in_array( $field['type'], array( 'radio', 'checkbox', 'file', 'data', 'lookup' ) ) ) {
771 711 return;
772 712 }
773 713
774 714 $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
@@ -781,12 +721,8 @@
781 721 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
782 722 return;
783 723 }
784 724
785 - if ( ! empty( $field['autocomplete'] ) ) {
786 - unset( $field['shortcodes']['autocomplete'] );
787 - }
788 -
789 725 foreach ( $field['shortcodes'] as $k => $v ) {
790 726 if ( 'opt' === $k ) {
791 727 continue;
792 728 }
@@ -892,9 +828,12 @@
892 828 *
893 829 * @deprecated 4.0 Moved to Pro for Other option only.
894 830 */
895 831 public static function add_option() {
896 - _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 + }
897 836 }
898 837
899 838 /**
900 839 * @deprecated 4.0
@@ -922,6 +861,22 @@
922 861 * @return array
923 862 */
924 863 public static function include_single_field( $field_id, $values, $form_id = 0 ) {
925 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' );
926 881 }
927 882 }