PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.10
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.10
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 +164 -140 6.46.10 View file →
@@ -4,8 +4,15 @@
4 4 }
5 5
6 6 class FrmFieldsController {
7 7
8 + /**
9 + * This is stored statically so we can re-use this data for every field.
10 + *
11 + * @var FrmFieldSelectionData|null
12 + */
13 + private static $field_selection_data;
14 +
8 15 public static function load_field() {
9 16 FrmAppHelper::permission_check( 'frm_edit_forms' );
10 17 check_ajax_referer( 'frm_ajax', 'nonce' );
11 18
@@ -73,18 +80,24 @@
73 80 /**
74 81 * Set up and create a new field
75 82 *
76 83 * @param string $field_type
77 - * @param integer $form_id
84 + * @param int $form_id
78 85 *
79 86 * @return array|bool
80 87 */
81 88 public static function include_new_field( $field_type, $form_id ) {
82 89 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
90 +
91 + // When a new field is added to the form, flag it as draft and hide it from the front-end.
92 + $field_values['field_options']['draft'] = 1;
93 +
94 + /**
95 + * @param array $field_values
96 + */
83 97 $field_values = apply_filters( 'frm_before_field_created', $field_values );
98 + $field_id = FrmField::create( $field_values );
84 99
85 - $field_id = FrmField::create( $field_values );
86 -
87 100 if ( ! $field_id ) {
88 101 return false;
89 102 }
90 103
@@ -136,11 +149,11 @@
136 149
137 150 /**
138 151 * @since 3.0
139 152 *
140 - * @param int|array|object $field_object
141 - * @param array $values
142 - * @param int $form_id
153 + * @param array|int|object $field_object
154 + * @param array $values
155 + * @param int $form_id
143 156 */
144 157 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
145 158 global $frm_vars;
146 159 $frm_vars['is_admin'] = true;
@@ -154,26 +167,26 @@
154 167
155 168 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
156 169 $display = self::display_field_options( array(), $field_obj );
157 170
158 - $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
159 - $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) );
171 + $ajax_loading = ! empty( $values['ajax_load'] );
172 + $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
160 173
161 174 if ( $ajax_loading && $ajax_this_field ) {
162 175 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
163 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' );
164 - } else {
165 - if ( ! isset( $field ) && is_object( $field_object ) ) {
166 - $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
176 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php';
177 + return;
178 + }
167 179
168 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
169 - }
180 + if ( ! isset( $field ) && is_object( $field_object ) ) {
181 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
182 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
183 + }
170 184
171 - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
172 - $li_classes .= ' ui-state-default widgets-holder-wrap';
185 + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
186 + $li_classes .= ' ui-state-default widgets-holder-wrap';
173 187
174 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
175 - }
188 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
176 189 }
177 190
178 191 /**
179 192 * @since 3.0
@@ -203,10 +216,11 @@
203 216 FrmField::destroy( $field_id );
204 217 wp_die();
205 218 }
206 219
207 - /* Field Options */
208 -
220 + /**
221 + * Field Options.
222 + */
209 223 public static function import_options() {
210 224 FrmAppHelper::permission_check( 'frm_edit_forms' );
211 225 check_ajax_referer( 'frm_ajax', 'nonce' );
212 226
@@ -213,12 +227,23 @@
213 227 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
214 228 return;
215 229 }
216 230
217 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
218 - $field = FrmField::getOne( $field_id );
231 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
232 + $field = FrmField::getOne( $field_id );
233 + $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
219 234
220 - if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
235 + /**
236 + * Filter to add new fields that will support import_options/Bulk Edit Options.
237 + *
238 + * @since 6.8.4
239 + *
240 + * @param array $bulk_edit_types
241 + * @return array
242 + */
243 + $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
244 +
245 + if ( ! in_array( $field->type, $bulk_edit_types, true ) ) {
221 246 return;
222 247 }
223 248
224 249 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -225,15 +250,15 @@
225 250 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
226 251 $opts = explode( "\n", rtrim( $opts, "\n" ) );
227 252 $opts = array_map( 'trim', $opts );
228 253
229 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
254 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
230 255 $field['separate_value'] = ( $separate === 'true' );
231 256
232 257 if ( $field['separate_value'] ) {
233 258 foreach ( $opts as $opt_key => $opt ) {
234 259 if ( strpos( $opt, '|' ) !== false ) {
235 - $vals = explode( '|', $opt );
260 + $vals = explode( '|', $opt );
236 261 $opts[ $opt_key ] = array(
237 262 'label' => trim( $vals[0] ),
238 263 'value' => trim( $vals[1] ),
239 264 );
@@ -283,13 +308,13 @@
283 308 if ( ! isset( $field['read_only'] ) ) {
284 309 $field['read_only'] = false;
285 310 }
286 311
287 - $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
288 - $pro_field_selection = FrmField::pro_field_selection();
289 - $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
290 - $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
291 - $frm_settings = FrmAppHelper::get_settings();
312 + $field_selection_data = self::maybe_define_field_selection_data();
313 + $all_field_types = $field_selection_data->all_field_types;
314 + $disabled_fields = $field_selection_data->disabled_fields;
315 + $frm_settings = FrmAppHelper::get_settings();
316 + $field_types = FrmFieldTypeOptionData::get_field_types( $field['type'] );
292 317
293 318 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
294 319 // Add fallback for an add-on field type that has been deactivated.
295 320 $all_field_types[ $field['type'] ] = array(
@@ -312,20 +337,36 @@
312 337
313 338 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
314 339 $field['placeholder'] = implode( ', ', $field['placeholder'] );
315 340 }
316 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
341 +
342 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
317 343 }
318 344
319 345 /**
346 + * @since 6.9.1
347 + *
348 + * @return FrmFieldSelectionData
349 + */
350 + private static function maybe_define_field_selection_data() {
351 + if ( ! isset( self::$field_selection_data ) ) {
352 + self::$field_selection_data = new FrmFieldSelectionData();
353 + }
354 + return self::$field_selection_data;
355 + }
356 +
357 + /**
320 358 * Get the list of default value types that can be toggled in the builder.
321 359 *
322 360 * @since 4.0
361 + *
362 + * @param array $field
363 + * @param array $atts
323 364 * @return array
324 365 */
325 366 private static function default_value_types( $field, $atts ) {
326 367 $types = array(
327 - 'default_value' => array(
368 + 'default_value' => array(
328 369 'class' => '',
329 370 'icon' => 'frm_icon_font frm_text2_icon',
330 371 'title' => __( 'Default Value (Text)', 'formidable' ),
331 372 'data' => array(
@@ -331,9 +372,9 @@
331 372 'data' => array(
332 373 'frmshow' => '#default-value-for-',
333 374 ),
334 375 ),
335 - 'calc' => array(
376 + 'calc' => array(
336 377 'class' => 'frm_show_upgrade frm_noallow',
337 378 'title' => __( 'Default Value (Calculation)', 'formidable' ),
338 379 'icon' => 'frm_icon_font frm_calculator_icon',
339 380 'data' => array(
@@ -353,13 +394,8 @@
353 394 );
354 395
355 396 $types = apply_filters( 'frm_default_value_types', $types, $atts );
356 397
357 - if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
358 - // Prevent settings from showing in 2 spots.
359 - unset( $types['calc'], $types['get_values_field'] );
360 - }
361 -
362 398 // Set active class.
363 399 $settings = array_keys( $types );
364 400 $active = 'default_value';
365 401
@@ -388,10 +424,13 @@
388 424 $type = $type_switch[ $type ];
389 425 }
390 426
391 427 $pro_fields = FrmField::pro_field_selection();
392 - $types = array_keys( $pro_fields );
393 - if ( in_array( $type, $types ) ) {
428 + // We want to keep credit_card types as credit card types for Stripe Lite.
429 + // The credit_card key is set for backward compatibility.
430 + unset( $pro_fields['credit_card'] );
431 +
432 + if ( array_key_exists( $type, $pro_fields ) ) {
394 433 $type = 'text';
395 434 }
396 435
397 436 return $type;
@@ -397,9 +436,9 @@
397 436 return $type;
398 437 }
399 438
400 439 /**
401 - * @param array $settings
440 + * @param array $settings
402 441 * @param object $field_info
403 442 *
404 443 * @return array
405 444 */
@@ -419,9 +458,17 @@
419 458 *
420 459 * @param array $field
421 460 */
422 461 public static function show_format_option( $field ) {
423 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
462 + $attributes = array();
463 + $attributes['class'] = 'frm-has-modal';
464 +
465 + if ( 'phone' === $field['type'] ) {
466 + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id'];
467 + $attributes['class'] .= ' frm_hidden';
468 + }
469 +
470 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
424 471 }
425 472
426 473 public static function input_html( $field, $echo = true ) {
427 474 $class = array();
@@ -450,13 +497,13 @@
450 497 return $add_html;
451 498 }
452 499
453 500 private static function add_input_classes( $field, array &$class ) {
454 - if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
501 + if ( ! empty( $field['input_class'] ) ) {
455 502 $class[] = $field['input_class'];
456 503 }
457 504
458 - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
505 + if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
459 506 return;
460 507 }
461 508
462 509 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -473,9 +520,9 @@
473 520 'file',
474 521 'lookup',
475 522 );
476 523
477 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
524 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
478 525 return;
479 526 }
480 527
481 528 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -493,9 +540,9 @@
493 540 self::add_html_cols( $field, $add_html );
494 541 }
495 542
496 543 private static function add_html_cols( $field, array &$add_html ) {
497 - if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
544 + if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
498 545 return;
499 546 }
500 547
501 548 // Convert to cols for textareas.
@@ -526,9 +573,9 @@
526 573 'hidden',
527 574 'file',
528 575 );
529 576
530 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
577 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
531 578 return;
532 579 }
533 580
534 581 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -610,14 +657,31 @@
610 657 if ( empty( $placeholder ) ) {
611 658 $placeholder = self::get_default_value_from_name( $field );
612 659 }
613 660
661 + $use_placeholder = $placeholder;
662 + $autocomplete = FrmField::get_option( $field, 'autocom' );
663 +
664 + if ( $autocomplete ) {
665 + $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
666 + if ( $use_chosen ) {
667 + $use_placeholder = '';
668 + }
669 + }
670 +
614 671 if ( $placeholder !== '' ) {
615 - ?>
616 - <option value="">
617 - <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
618 - </option>
619 - <?php
672 + $placeholder_attributes = array(
673 + 'class' => 'frm-select-placeholder',
674 + 'value' => '',
675 + 'data-placeholder' => 'true',
676 + );
677 +
678 + if ( $autocomplete && empty( $use_chosen ) ) {
679 + // This is required for Slim Select.
680 + $placeholder_attributes['data-placeholder'] = 'true';
681 + }
682 +
683 + FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
620 684 return true;
621 685 }
622 686
623 687 return false;
@@ -649,15 +713,17 @@
649 713 }
650 714 }
651 715
652 716 private static function add_validation_messages( $field, array &$add_html ) {
653 - if ( FrmField::is_required( $field ) ) {
717 + $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
718 +
719 + if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
654 720 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
655 721 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
656 722 self::maybe_add_html_required( $field, $add_html );
657 723 }
658 724
659 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
725 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
660 726 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
661 727 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
662 728 }
663 729
@@ -666,8 +732,40 @@
666 732 }
667 733 }
668 734
669 735 /**
736 + * Returns an array that contains field validation messages status.
737 + *
738 + * @since 6.9
739 + *
740 + * @param array|object $field
741 + * @return array
742 + */
743 + private static function get_validation_data_attribute_visibility_info( $field ) {
744 + if ( FrmField::get_field_type( $field ) === 'hidden' ) {
745 + $field_validation_data_attributes = array(
746 + 'data-invmsg' => false,
747 + 'data-reqmsg' => false,
748 + );
749 + } else {
750 + $field_validation_data_attributes = array(
751 + 'data-invmsg' => true,
752 + 'data-reqmsg' => true,
753 + );
754 + }
755 +
756 + /**
757 + * Allows controlling which field validation messages would be included in the field html.
758 + *
759 + * @since 6.9
760 + *
761 + * @param array $field_validation_messages_status
762 + * @param array|object $field
763 + */
764 + return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
765 + }
766 +
767 + /**
670 768 * @since 5.0.03
671 769 *
672 770 * @param array $field
673 771 * @param array $add_html
@@ -688,9 +786,9 @@
688 786 /**
689 787 * @since 5.0.03
690 788 *
691 789 * @param array $field
692 - * @return stdClass|false false if there is no form object found with JS validation active.
790 + * @return false|stdClass false if there is no form object found with JS validation active.
693 791 */
694 792 private static function get_form_for_js_validation( $field ) {
695 793 global $frm_vars;
696 794 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
@@ -707,9 +805,9 @@
707 805 /**
708 806 * @param stdClass $form
709 807 * @param array $field
710 808 * @param array $errors
711 - * @return string|false
809 + * @return false|string
712 810 */
713 811 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
714 812 if ( empty( $field['custom_html'] ) ) {
715 813 return false;
@@ -752,16 +850,20 @@
752 850 * @param array $field
753 851 * @param array $add_html
754 852 */
755 853 private static function maybe_add_html_required( $field, array &$add_html ) {
756 - if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) {
854 + $excluded_field_types =
855 + FrmField::is_radio( $field ) ||
856 + FrmField::is_checkbox( $field ) ||
857 + FrmField::is_field_type( $field, 'file' ) ||
858 + FrmField::is_field_type( $field, 'nps' ) ||
859 + FrmField::is_field_type( $field, 'scale' );
860 +
861 + if ( $excluded_field_types ) {
757 862 return;
758 863 }
759 864
760 - $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
761 - if ( $include_html ) {
762 - $add_html['aria-required'] = 'aria-required="true"';
763 - }
865 + $add_html['aria-required'] = 'aria-required="true"';
764 866 }
765 867
766 868 private static function add_shortcodes_to_html( $field, array &$add_html ) {
767 869 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -800,9 +902,9 @@
800 902 private static function add_pattern_attribute( $field, array &$add_html ) {
801 903 $has_format = FrmField::is_option_true_in_array( $field, 'format' );
802 904 $format_field = FrmField::is_field_type( $field, 'text' );
803 905
804 - if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
906 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
805 907 $frm_settings = FrmAppHelper::get_settings();
806 908
807 909 if ( $frm_settings->use_html ) {
808 910 $format = FrmEntryValidate::phone_format( $field );
@@ -830,84 +932,6 @@
830 932 $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
831 933 }
832 934
833 935 return $opt;
834 - }
835 -
836 - /**
837 - * @deprecated 4.0
838 - */
839 - public static function update_ajax_option() {
840 - _deprecated_function( __METHOD__, '4.0' );
841 - FrmAppHelper::permission_check( 'frm_edit_forms' );
842 - check_ajax_referer( 'frm_ajax', 'nonce' );
843 -
844 - $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
845 - if ( ! $field_id ) {
846 - wp_die();
847 - }
848 -
849 - $field = FrmField::getOne( $field_id );
850 -
851 - if ( isset( $_POST['separate_value'] ) ) {
852 - $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
853 -
854 - $field->field_options['separate_value'] = $new_val;
855 - unset( $new_val );
856 - }
857 -
858 - FrmField::update(
859 - $field_id,
860 - array(
861 - 'field_options' => $field->field_options,
862 - 'form_id' => $field->form_id,
863 - )
864 - );
865 - wp_die();
866 - }
867 -
868 - /**
869 - * @deprecated 4.0
870 - */
871 - public static function import_choices() {
872 - _deprecated_function( __METHOD__, '4.0' );
873 - wp_die();
874 - }
875 -
876 - /**
877 - * Add Single Option or Other Option.
878 - *
879 - * @deprecated 4.0 Moved to Pro for Other option only.
880 - */
881 - public static function add_option() {
882 - _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
883 - }
884 -
885 - /**
886 - * @deprecated 4.0
887 - */
888 - public static function update_order() {
889 - FrmDeprecated::update_order();
890 - }
891 -
892 - /**
893 - * @deprecated 3.0
894 - * @codeCoverageIgnore
895 - */
896 - public static function edit_name( $field = 'name', $id = '' ) {
897 - FrmDeprecated::edit_name( $field, $id );
898 - }
899 -
900 - /**
901 - * @deprecated 3.0
902 - * @codeCoverageIgnore
903 - *
904 - * @param int $field_id
905 - * @param array $values
906 - * @param int $form_id
907 - *
908 - * @return array
909 - */
910 - public static function include_single_field( $field_id, $values, $form_id = 0 ) {
911 - return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
912 936 }
913 937 }