PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.19
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.19
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 +255 -171 6.36.19 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 - * @return array|bool
86 + * @return array|false
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,30 +167,35 @@
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
193 + *
194 + * @param array $field
195 + * @param array $display
196 + * @param FrmFieldType $field_info
197 + * @return string
180 198 */
181 199 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
182 200 $li_classes = $field_info->form_builder_classes( $display['type'] );
183 201 $li_classes .= ' frm_form_field frmstart ';
@@ -203,10 +221,11 @@
203 221 FrmField::destroy( $field_id );
204 222 wp_die();
205 223 }
206 224
207 - /* Field Options */
208 -
225 + /**
226 + * Field Options.
227 + */
209 228 public static function import_options() {
210 229 FrmAppHelper::permission_check( 'frm_edit_forms' );
211 230 check_ajax_referer( 'frm_ajax', 'nonce' );
212 231
@@ -213,12 +232,23 @@
213 232 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
214 233 return;
215 234 }
216 235
217 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
218 - $field = FrmField::getOne( $field_id );
236 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
237 + $field = FrmField::getOne( $field_id );
238 + $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
219 239
220 - if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
240 + /**
241 + * Filter to add new fields that will support import_options/Bulk Edit Options.
242 + *
243 + * @since 6.8.4
244 + *
245 + * @param array $bulk_edit_types
246 + * @return array
247 + */
248 + $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
249 +
250 + if ( ! in_array( $field->type, $bulk_edit_types, true ) ) {
221 251 return;
222 252 }
223 253
224 254 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -225,15 +255,15 @@
225 255 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
226 256 $opts = explode( "\n", rtrim( $opts, "\n" ) );
227 257 $opts = array_map( 'trim', $opts );
228 258
229 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
230 - $field['separate_value'] = ( $separate === 'true' );
259 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
260 + $field['separate_value'] = $separate === 'true';
231 261
232 262 if ( $field['separate_value'] ) {
233 263 foreach ( $opts as $opt_key => $opt ) {
234 264 if ( strpos( $opt, '|' ) !== false ) {
235 - $vals = explode( '|', $opt );
265 + $vals = explode( '|', $opt );
236 266 $opts[ $opt_key ] = array(
237 267 'label' => trim( $vals[0] ),
238 268 'value' => trim( $vals[1] ),
239 269 );
@@ -267,8 +297,9 @@
267 297 /**
268 298 * @since 4.0
269 299 *
270 300 * @param array $atts - Includes field array, field_obj, display array, values array.
301 + * @return void
271 302 */
272 303 public static function load_single_field_settings( $atts ) {
273 304 $field = $atts['field'];
274 305 $field_obj = $atts['field_obj'];
@@ -283,13 +314,13 @@
283 314 if ( ! isset( $field['read_only'] ) ) {
284 315 $field['read_only'] = false;
285 316 }
286 317
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();
318 + $field_selection_data = self::maybe_define_field_selection_data();
319 + $all_field_types = $field_selection_data->all_field_types;
320 + $disabled_fields = $field_selection_data->disabled_fields;
321 + $frm_settings = FrmAppHelper::get_settings();
322 + $field_types = FrmFieldTypeOptionData::get_field_types( $field['type'] );
292 323
293 324 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
294 325 // Add fallback for an add-on field type that has been deactivated.
295 326 $all_field_types[ $field['type'] ] = array(
@@ -312,20 +343,36 @@
312 343
313 344 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
314 345 $field['placeholder'] = implode( ', ', $field['placeholder'] );
315 346 }
316 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
347 +
348 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
317 349 }
318 350
319 351 /**
352 + * @since 6.9.1
353 + *
354 + * @return FrmFieldSelectionData
355 + */
356 + private static function maybe_define_field_selection_data() {
357 + if ( ! isset( self::$field_selection_data ) ) {
358 + self::$field_selection_data = new FrmFieldSelectionData();
359 + }
360 + return self::$field_selection_data;
361 + }
362 +
363 + /**
320 364 * Get the list of default value types that can be toggled in the builder.
321 365 *
322 366 * @since 4.0
367 + *
368 + * @param array $field
369 + * @param array $atts
323 370 * @return array
324 371 */
325 372 private static function default_value_types( $field, $atts ) {
326 373 $types = array(
327 - 'default_value' => array(
374 + 'default_value' => array(
328 375 'class' => '',
329 376 'icon' => 'frm_icon_font frm_text2_icon',
330 377 'title' => __( 'Default Value (Text)', 'formidable' ),
331 378 'data' => array(
@@ -331,9 +378,9 @@
331 378 'data' => array(
332 379 'frmshow' => '#default-value-for-',
333 380 ),
334 381 ),
335 - 'calc' => array(
382 + 'calc' => array(
336 383 'class' => 'frm_show_upgrade frm_noallow',
337 384 'title' => __( 'Default Value (Calculation)', 'formidable' ),
338 385 'icon' => 'frm_icon_font frm_calculator_icon',
339 386 'data' => array(
@@ -353,13 +400,8 @@
353 400 );
354 401
355 402 $types = apply_filters( 'frm_default_value_types', $types, $atts );
356 403
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 404 // Set active class.
363 405 $settings = array_keys( $types );
364 406 $active = 'default_value';
365 407
@@ -374,8 +416,12 @@
374 416
375 417 return $types;
376 418 }
377 419
420 + /**
421 + * @param string $type
422 + * @return string
423 + */
378 424 public static function change_type( $type ) {
379 425 $type_switch = array(
380 426 'scale' => 'radio',
381 427 'star' => 'radio',
@@ -388,10 +434,13 @@
388 434 $type = $type_switch[ $type ];
389 435 }
390 436
391 437 $pro_fields = FrmField::pro_field_selection();
392 - $types = array_keys( $pro_fields );
393 - if ( in_array( $type, $types ) ) {
438 + // We want to keep credit_card types as credit card types for Stripe Lite.
439 + // The credit_card key is set for backward compatibility.
440 + unset( $pro_fields['credit_card'] );
441 +
442 + if ( array_key_exists( $type, $pro_fields ) ) {
394 443 $type = 'text';
395 444 }
396 445
397 446 return $type;
@@ -397,16 +446,18 @@
397 446 return $type;
398 447 }
399 448
400 449 /**
401 - * @param array $settings
402 - * @param object $field_info
450 + * @param array $settings
451 + * @param FrmFieldType|null $field_info
403 452 *
404 453 * @return array
405 454 */
406 455 public static function display_field_options( $settings, $field_info = null ) {
407 456 if ( $field_info ) {
408 - $settings = $field_info->display_field_settings();
457 + $settings = $field_info->display_field_settings();
458 +
459 + // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
409 460 $settings['field_data'] = $field_info->field;
410 461 }
411 462
412 463 return apply_filters( 'frm_display_field_options', $settings );
@@ -416,12 +467,23 @@
416 467 * Display the format option
417 468 *
418 469 * @since 3.0
419 470 *
420 - * @param array $field
471 + * @param array $field Field data.
472 + * @param bool $is_hidden Whether the format option should be hidden.
473 + * @return void
421 474 */
422 - public static function show_format_option( $field ) {
423 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
475 + public static function show_format_option( $field, $is_hidden = false ) {
476 + $attributes = array(
477 + 'class' => 'frm-has-modal',
478 + 'id' => 'frm-field-format-custom-' . $field['id'],
479 + );
480 +
481 + if ( $is_hidden ) {
482 + $attributes['class'] .= ' frm_hidden';
483 + }
484 +
485 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
424 486 }
425 487
426 488 public static function input_html( $field, $echo = true ) {
427 489 $class = array();
@@ -449,14 +511,19 @@
449 511
450 512 return $add_html;
451 513 }
452 514
515 + /**
516 + * @param array $field
517 + * @param array $class
518 + * @return void
519 + */
453 520 private static function add_input_classes( $field, array &$class ) {
454 - if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
521 + if ( ! empty( $field['input_class'] ) ) {
455 522 $class[] = $field['input_class'];
456 523 }
457 524
458 - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
525 + if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
459 526 return;
460 527 }
461 528
462 529 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -463,8 +530,13 @@
463 530 $class[] = 'auto_width';
464 531 }
465 532 }
466 533
534 + /**
535 + * @param array $field
536 + * @param array $add_html
537 + * @return void
538 + */
467 539 private static function add_html_size( $field, array &$add_html ) {
468 540 $size_fields = array(
469 541 'select',
470 542 'data',
@@ -473,9 +545,9 @@
473 545 'file',
474 546 'lookup',
475 547 );
476 548
477 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
549 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
478 550 return;
479 551 }
480 552
481 553 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -492,10 +564,15 @@
492 564
493 565 self::add_html_cols( $field, $add_html );
494 566 }
495 567
568 + /**
569 + * @param array $field
570 + * @param array $add_html
571 + * @return void
572 + */
496 573 private static function add_html_cols( $field, array &$add_html ) {
497 - if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
574 + if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
498 575 return;
499 576 }
500 577
501 578 // Convert to cols for textareas.
@@ -517,8 +594,13 @@
517 594
518 595 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
519 596 }
520 597
598 + /**
599 + * @param array $field
600 + * @param array $add_html
601 + * @return void
602 + */
521 603 private static function add_html_length( $field, array &$add_html ) {
522 604 // Check for max setting and if this field accepts maxlength.
523 605 $fields = array(
524 606 'textarea',
@@ -526,9 +608,9 @@
526 608 'hidden',
527 609 'file',
528 610 );
529 611
530 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
612 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
531 613 return;
532 614 }
533 615
534 616 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -538,8 +620,14 @@
538 620
539 621 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
540 622 }
541 623
624 + /**
625 + * @param array $field
626 + * @param array $add_html
627 + * @param array $class
628 + * @return void
629 + */
542 630 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
543 631 if ( $field['default_value'] != '' ) {
544 632 if ( is_array( $field['default_value'] ) ) {
545 633 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -553,21 +641,9 @@
553 641 // don't include a json placeholder
554 642 return;
555 643 }
556 644
557 - $frm_settings = FrmAppHelper::get_settings();
558 -
559 - if ( $frm_settings->use_html ) {
560 - self::add_placeholder_to_input( $field, $add_html );
561 - } else {
562 - self::add_frmval_to_input( $field, $add_html );
563 -
564 - $class[] = 'frm_toggle_default';
565 -
566 - if ( $field['value'] == $field['placeholder'] ) {
567 - $class[] = 'frm_default';
568 - }
569 - }
645 + self::add_placeholder_to_input( $field, $add_html );
570 646 }
571 647
572 648 /**
573 649 * Prepares field placeholder.
@@ -610,14 +686,26 @@
610 686 if ( empty( $placeholder ) ) {
611 687 $placeholder = self::get_default_value_from_name( $field );
612 688 }
613 689
690 + $use_placeholder = $placeholder;
691 + $autocomplete = FrmField::get_option( $field, 'autocom' );
692 +
693 + if ( $autocomplete ) {
694 + $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
695 + if ( $use_chosen ) {
696 + $use_placeholder = '';
697 + }
698 + }
699 +
614 700 if ( $placeholder !== '' ) {
615 - ?>
616 - <option value="">
617 - <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
618 - </option>
619 - <?php
701 + $placeholder_attributes = array(
702 + 'class' => 'frm-select-placeholder',
703 + 'value' => '',
704 + 'data-placeholder' => 'true',
705 + );
706 +
707 + FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
620 708 return true;
621 709 }
622 710
623 711 return false;
@@ -623,12 +711,13 @@
623 711 return false;
624 712 }
625 713
626 714 /**
627 - * Use HMTL5 placeholder with js fallback
715 + * Use HTML5 placeholder with js fallback.
628 716 *
629 717 * @param array $field
630 718 * @param array $add_html
719 + * @return void
631 720 */
632 721 private static function add_placeholder_to_input( $field, &$add_html ) {
633 722 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
634 723 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -634,8 +723,13 @@
634 723 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
635 724 }
636 725 }
637 726
727 + /**
728 + * @param array $field
729 + * @param array $add_html
730 + * @return void
731 + */
638 732 private static function add_frmval_to_input( $field, &$add_html ) {
639 733 if ( $field['placeholder'] != '' ) {
640 734 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
641 735
@@ -649,15 +743,17 @@
649 743 }
650 744 }
651 745
652 746 private static function add_validation_messages( $field, array &$add_html ) {
653 - if ( FrmField::is_required( $field ) ) {
747 + $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
748 +
749 + if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
654 750 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
655 751 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
656 752 self::maybe_add_html_required( $field, $add_html );
657 753 }
658 754
659 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
755 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
660 756 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
661 757 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
662 758 }
663 759
@@ -666,12 +762,45 @@
666 762 }
667 763 }
668 764
669 765 /**
766 + * Returns an array that contains field validation messages status.
767 + *
768 + * @since 6.9
769 + *
770 + * @param array|object $field
771 + * @return array
772 + */
773 + private static function get_validation_data_attribute_visibility_info( $field ) {
774 + if ( FrmField::get_field_type( $field ) === 'hidden' ) {
775 + $field_validation_data_attributes = array(
776 + 'data-invmsg' => false,
777 + 'data-reqmsg' => false,
778 + );
779 + } else {
780 + $field_validation_data_attributes = array(
781 + 'data-invmsg' => true,
782 + 'data-reqmsg' => true,
783 + );
784 + }
785 +
786 + /**
787 + * Allows controlling which field validation messages would be included in the field html.
788 + *
789 + * @since 6.9
790 + *
791 + * @param array $field_validation_messages_status
792 + * @param array|object $field
793 + */
794 + return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
795 + }
796 +
797 + /**
670 798 * @since 5.0.03
671 799 *
672 800 * @param array $field
673 801 * @param array $add_html
802 + * @return void
674 803 */
675 804 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
676 805 $form = self::get_form_for_js_validation( $field );
677 806 if ( false === $form ) {
@@ -688,9 +817,9 @@
688 817 /**
689 818 * @since 5.0.03
690 819 *
691 820 * @param array $field
692 - * @return stdClass|false false if there is no form object found with JS validation active.
821 + * @return false|stdClass false if there is no form object found with JS validation active.
693 822 */
694 823 private static function get_form_for_js_validation( $field ) {
695 824 global $frm_vars;
696 825 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
@@ -707,9 +836,9 @@
707 836 /**
708 837 * @param stdClass $form
709 838 * @param array $field
710 839 * @param array $errors
711 - * @return string|false
840 + * @return false|string
712 841 */
713 842 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
714 843 if ( empty( $field['custom_html'] ) ) {
715 844 return false;
@@ -750,20 +879,30 @@
750 879 *
751 880 * @since 3.06.01
752 881 * @param array $field
753 882 * @param array $add_html
883 + * @return void
754 884 */
755 885 private static function maybe_add_html_required( $field, array &$add_html ) {
756 - if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) {
886 + $excluded_field_types =
887 + FrmField::is_radio( $field ) ||
888 + FrmField::is_checkbox( $field ) ||
889 + FrmField::is_field_type( $field, 'file' ) ||
890 + FrmField::is_field_type( $field, 'nps' ) ||
891 + FrmField::is_field_type( $field, 'scale' );
892 +
893 + if ( $excluded_field_types ) {
757 894 return;
758 895 }
759 896
760 - $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
761 - if ( $include_html ) {
762 - $add_html['aria-required'] = 'aria-required="true"';
763 - }
897 + $add_html['aria-required'] = 'aria-required="true"';
764 898 }
765 899
900 + /**
901 + * @param array $field
902 + * @param array $add_html
903 + * @return void
904 + */
766 905 private static function add_shortcodes_to_html( $field, array &$add_html ) {
767 906 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
768 907 return;
769 908 }
@@ -772,9 +911,19 @@
772 911 unset( $field['shortcodes']['autocomplete'] );
773 912 }
774 913
775 914 foreach ( $field['shortcodes'] as $k => $v ) {
776 - if ( 'opt' === $k ) {
915 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
916 + $subfield_name = $field['subfield_name'];
917 + if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
918 + continue;
919 + }
920 + // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
921 + $k = 'aria-invalid';
922 + $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
923 + unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
924 + }
925 + if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
777 926 continue;
778 927 }
779 928
780 929 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -785,32 +934,45 @@
785 934 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
786 935 }
787 936
788 937 unset( $k, $v );
938 + }//end foreach
939 + }
940 +
941 + /**
942 + * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
943 + *
944 + * @since 6.11.2
945 + *
946 + * @param string $key The option key.
947 + * @return bool
948 + */
949 + private static function should_allow_input_attribute( $key ) {
950 + if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
951 + return true;
789 952 }
953 + return FrmAppHelper::input_key_is_safe( $key );
790 954 }
791 955
792 956 /**
793 - * Add pattern attribute
957 + * Add pattern attribute.
794 958 *
795 959 * @since 3.0
796 960 *
797 961 * @param array $field
798 962 * @param array $add_html
963 + * @return void
799 964 */
800 965 private static function add_pattern_attribute( $field, array &$add_html ) {
801 - $has_format = FrmField::is_option_true_in_array( $field, 'format' );
966 + $format_value = FrmField::get_option( $field, 'format' );
967 + $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
802 968 $format_field = FrmField::is_field_type( $field, 'text' );
803 969
804 - if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
805 - $frm_settings = FrmAppHelper::get_settings();
970 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
971 + $format = FrmEntryValidate::phone_format( $field );
972 + $format = substr( $format, 2, - 1 );
806 973
807 - if ( $frm_settings->use_html ) {
808 - $format = FrmEntryValidate::phone_format( $field );
809 - $format = substr( $format, 2, - 1 );
810 -
811 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
812 - }
974 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
813 975 }
814 976 }
815 977
816 978 public static function check_value( $opt, $opt_key, $field ) {
@@ -826,88 +988,10 @@
826 988 }
827 989
828 990 public static function check_label( $opt ) {
829 991 if ( is_array( $opt ) ) {
830 - $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
992 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
831 993 }
832 994
833 995 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 996 }
913 997 }