PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16.3
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 +228 -161 6.56.16.3 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,15 +80,18 @@
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 );
83 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 +
84 94 /**
85 95 * @param array $field_values
86 96 */
87 97 $field_values = apply_filters( 'frm_before_field_created', $field_values );
@@ -139,11 +149,11 @@
139 149
140 150 /**
141 151 * @since 3.0
142 152 *
143 - * @param int|array|object $field_object
144 - * @param array $values
145 - * @param int $form_id
153 + * @param array|int|object $field_object
154 + * @param array $values
155 + * @param int $form_id
146 156 */
147 157 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
148 158 global $frm_vars;
149 159 $frm_vars['is_admin'] = true;
@@ -157,30 +167,35 @@
157 167
158 168 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
159 169 $display = self::display_field_options( array(), $field_obj );
160 170
161 - $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
162 - $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 );
163 173
164 174 if ( $ajax_loading && $ajax_this_field ) {
165 175 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
166 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' );
167 - } else {
168 - if ( ! isset( $field ) && is_object( $field_object ) ) {
169 - $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 + }
170 179
171 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
172 - }
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 + }
173 184
174 - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
175 - $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';
176 187
177 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
178 - }
188 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
179 189 }
180 190
181 191 /**
182 192 * @since 3.0
193 + *
194 + * @param array $field
195 + * @param array $display
196 + * @param FrmFieldType $field_info
197 + * @return string
183 198 */
184 199 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
185 200 $li_classes = $field_info->form_builder_classes( $display['type'] );
186 201 $li_classes .= ' frm_form_field frmstart ';
@@ -206,10 +221,11 @@
206 221 FrmField::destroy( $field_id );
207 222 wp_die();
208 223 }
209 224
210 - /* Field Options */
211 -
225 + /**
226 + * Field Options.
227 + */
212 228 public static function import_options() {
213 229 FrmAppHelper::permission_check( 'frm_edit_forms' );
214 230 check_ajax_referer( 'frm_ajax', 'nonce' );
215 231
@@ -216,12 +232,23 @@
216 232 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
217 233 return;
218 234 }
219 235
220 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
221 - $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' );
222 239
223 - 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 ) ) {
224 251 return;
225 252 }
226 253
227 254 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -228,15 +255,15 @@
228 255 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
229 256 $opts = explode( "\n", rtrim( $opts, "\n" ) );
230 257 $opts = array_map( 'trim', $opts );
231 258
232 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
233 - $field['separate_value'] = ( $separate === 'true' );
259 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
260 + $field['separate_value'] = $separate === 'true';
234 261
235 262 if ( $field['separate_value'] ) {
236 263 foreach ( $opts as $opt_key => $opt ) {
237 264 if ( strpos( $opt, '|' ) !== false ) {
238 - $vals = explode( '|', $opt );
265 + $vals = explode( '|', $opt );
239 266 $opts[ $opt_key ] = array(
240 267 'label' => trim( $vals[0] ),
241 268 'value' => trim( $vals[1] ),
242 269 );
@@ -270,8 +297,9 @@
270 297 /**
271 298 * @since 4.0
272 299 *
273 300 * @param array $atts - Includes field array, field_obj, display array, values array.
301 + * @return void
274 302 */
275 303 public static function load_single_field_settings( $atts ) {
276 304 $field = $atts['field'];
277 305 $field_obj = $atts['field_obj'];
@@ -286,13 +314,13 @@
286 314 if ( ! isset( $field['read_only'] ) ) {
287 315 $field['read_only'] = false;
288 316 }
289 317
290 - $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
291 - $pro_field_selection = FrmField::pro_field_selection();
292 - $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
293 - $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
294 - $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'] );
295 323
296 324 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
297 325 // Add fallback for an add-on field type that has been deactivated.
298 326 $all_field_types[ $field['type'] ] = array(
@@ -320,16 +348,31 @@
320 348 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
321 349 }
322 350
323 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 + /**
324 364 * Get the list of default value types that can be toggled in the builder.
325 365 *
326 366 * @since 4.0
367 + *
368 + * @param array $field
369 + * @param array $atts
327 370 * @return array
328 371 */
329 372 private static function default_value_types( $field, $atts ) {
330 373 $types = array(
331 - 'default_value' => array(
374 + 'default_value' => array(
332 375 'class' => '',
333 376 'icon' => 'frm_icon_font frm_text2_icon',
334 377 'title' => __( 'Default Value (Text)', 'formidable' ),
335 378 'data' => array(
@@ -335,9 +378,9 @@
335 378 'data' => array(
336 379 'frmshow' => '#default-value-for-',
337 380 ),
338 381 ),
339 - 'calc' => array(
382 + 'calc' => array(
340 383 'class' => 'frm_show_upgrade frm_noallow',
341 384 'title' => __( 'Default Value (Calculation)', 'formidable' ),
342 385 'icon' => 'frm_icon_font frm_calculator_icon',
343 386 'data' => array(
@@ -357,13 +400,8 @@
357 400 );
358 401
359 402 $types = apply_filters( 'frm_default_value_types', $types, $atts );
360 403
361 - if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
362 - // Prevent settings from showing in 2 spots.
363 - unset( $types['calc'], $types['get_values_field'] );
364 - }
365 -
366 404 // Set active class.
367 405 $settings = array_keys( $types );
368 406 $active = 'default_value';
369 407
@@ -378,8 +416,12 @@
378 416
379 417 return $types;
380 418 }
381 419
420 + /**
421 + * @param string $type
422 + * @return string
423 + */
382 424 public static function change_type( $type ) {
383 425 $type_switch = array(
384 426 'scale' => 'radio',
385 427 'star' => 'radio',
@@ -404,16 +446,18 @@
404 446 return $type;
405 447 }
406 448
407 449 /**
408 - * @param array $settings
409 - * @param object $field_info
450 + * @param array $settings
451 + * @param FrmFieldType|null $field_info
410 452 *
411 453 * @return array
412 454 */
413 455 public static function display_field_options( $settings, $field_info = null ) {
414 456 if ( $field_info ) {
415 - $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.
416 460 $settings['field_data'] = $field_info->field;
417 461 }
418 462
419 463 return apply_filters( 'frm_display_field_options', $settings );
@@ -424,11 +468,20 @@
424 468 *
425 469 * @since 3.0
426 470 *
427 471 * @param array $field
472 + * @return void
428 473 */
429 474 public static function show_format_option( $field ) {
430 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
475 + $attributes = array();
476 + $attributes['class'] = 'frm-has-modal';
477 +
478 + if ( 'phone' === $field['type'] ) {
479 + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id'];
480 + $attributes['class'] .= ' frm_hidden';
481 + }
482 +
483 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
431 484 }
432 485
433 486 public static function input_html( $field, $echo = true ) {
434 487 $class = array();
@@ -456,14 +509,19 @@
456 509
457 510 return $add_html;
458 511 }
459 512
513 + /**
514 + * @param array $field
515 + * @param array $class
516 + * @return void
517 + */
460 518 private static function add_input_classes( $field, array &$class ) {
461 - if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
519 + if ( ! empty( $field['input_class'] ) ) {
462 520 $class[] = $field['input_class'];
463 521 }
464 522
465 - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
523 + if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
466 524 return;
467 525 }
468 526
469 527 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -470,8 +528,13 @@
470 528 $class[] = 'auto_width';
471 529 }
472 530 }
473 531
532 + /**
533 + * @param array $field
534 + * @param array $add_html
535 + * @return void
536 + */
474 537 private static function add_html_size( $field, array &$add_html ) {
475 538 $size_fields = array(
476 539 'select',
477 540 'data',
@@ -480,9 +543,9 @@
480 543 'file',
481 544 'lookup',
482 545 );
483 546
484 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
547 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
485 548 return;
486 549 }
487 550
488 551 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -499,8 +562,13 @@
499 562
500 563 self::add_html_cols( $field, $add_html );
501 564 }
502 565
566 + /**
567 + * @param array $field
568 + * @param array $add_html
569 + * @return void
570 + */
503 571 private static function add_html_cols( $field, array &$add_html ) {
504 572 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
505 573 return;
506 574 }
@@ -524,8 +592,13 @@
524 592
525 593 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
526 594 }
527 595
596 + /**
597 + * @param array $field
598 + * @param array $add_html
599 + * @return void
600 + */
528 601 private static function add_html_length( $field, array &$add_html ) {
529 602 // Check for max setting and if this field accepts maxlength.
530 603 $fields = array(
531 604 'textarea',
@@ -533,9 +606,9 @@
533 606 'hidden',
534 607 'file',
535 608 );
536 609
537 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
610 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
538 611 return;
539 612 }
540 613
541 614 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -545,8 +618,14 @@
545 618
546 619 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
547 620 }
548 621
622 + /**
623 + * @param array $field
624 + * @param array $add_html
625 + * @param array $class
626 + * @return void
627 + */
549 628 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
550 629 if ( $field['default_value'] != '' ) {
551 630 if ( is_array( $field['default_value'] ) ) {
552 631 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -560,21 +639,9 @@
560 639 // don't include a json placeholder
561 640 return;
562 641 }
563 642
564 - $frm_settings = FrmAppHelper::get_settings();
565 -
566 - if ( $frm_settings->use_html ) {
567 - self::add_placeholder_to_input( $field, $add_html );
568 - } else {
569 - self::add_frmval_to_input( $field, $add_html );
570 -
571 - $class[] = 'frm_toggle_default';
572 -
573 - if ( $field['value'] == $field['placeholder'] ) {
574 - $class[] = 'frm_default';
575 - }
576 - }
643 + self::add_placeholder_to_input( $field, $add_html );
577 644 }
578 645
579 646 /**
580 647 * Prepares field placeholder.
@@ -617,14 +684,26 @@
617 684 if ( empty( $placeholder ) ) {
618 685 $placeholder = self::get_default_value_from_name( $field );
619 686 }
620 687
688 + $use_placeholder = $placeholder;
689 + $autocomplete = FrmField::get_option( $field, 'autocom' );
690 +
691 + if ( $autocomplete ) {
692 + $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
693 + if ( $use_chosen ) {
694 + $use_placeholder = '';
695 + }
696 + }
697 +
621 698 if ( $placeholder !== '' ) {
622 - ?>
623 - <option value="">
624 - <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
625 - </option>
626 - <?php
699 + $placeholder_attributes = array(
700 + 'class' => 'frm-select-placeholder',
701 + 'value' => '',
702 + 'data-placeholder' => 'true',
703 + );
704 +
705 + FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
627 706 return true;
628 707 }
629 708
630 709 return false;
@@ -630,12 +709,13 @@
630 709 return false;
631 710 }
632 711
633 712 /**
634 - * Use HMTL5 placeholder with js fallback
713 + * Use HTML5 placeholder with js fallback.
635 714 *
636 715 * @param array $field
637 716 * @param array $add_html
717 + * @return void
638 718 */
639 719 private static function add_placeholder_to_input( $field, &$add_html ) {
640 720 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
641 721 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -641,8 +721,13 @@
641 721 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
642 722 }
643 723 }
644 724
725 + /**
726 + * @param array $field
727 + * @param array $add_html
728 + * @return void
729 + */
645 730 private static function add_frmval_to_input( $field, &$add_html ) {
646 731 if ( $field['placeholder'] != '' ) {
647 732 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
648 733
@@ -656,15 +741,17 @@
656 741 }
657 742 }
658 743
659 744 private static function add_validation_messages( $field, array &$add_html ) {
660 - if ( FrmField::is_required( $field ) ) {
745 + $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
746 +
747 + if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
661 748 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
662 749 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
663 750 self::maybe_add_html_required( $field, $add_html );
664 751 }
665 752
666 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
753 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
667 754 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
668 755 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
669 756 }
670 757
@@ -673,12 +760,45 @@
673 760 }
674 761 }
675 762
676 763 /**
764 + * Returns an array that contains field validation messages status.
765 + *
766 + * @since 6.9
767 + *
768 + * @param array|object $field
769 + * @return array
770 + */
771 + private static function get_validation_data_attribute_visibility_info( $field ) {
772 + if ( FrmField::get_field_type( $field ) === 'hidden' ) {
773 + $field_validation_data_attributes = array(
774 + 'data-invmsg' => false,
775 + 'data-reqmsg' => false,
776 + );
777 + } else {
778 + $field_validation_data_attributes = array(
779 + 'data-invmsg' => true,
780 + 'data-reqmsg' => true,
781 + );
782 + }
783 +
784 + /**
785 + * Allows controlling which field validation messages would be included in the field html.
786 + *
787 + * @since 6.9
788 + *
789 + * @param array $field_validation_messages_status
790 + * @param array|object $field
791 + */
792 + return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
793 + }
794 +
795 + /**
677 796 * @since 5.0.03
678 797 *
679 798 * @param array $field
680 799 * @param array $add_html
800 + * @return void
681 801 */
682 802 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
683 803 $form = self::get_form_for_js_validation( $field );
684 804 if ( false === $form ) {
@@ -695,9 +815,9 @@
695 815 /**
696 816 * @since 5.0.03
697 817 *
698 818 * @param array $field
699 - * @return stdClass|false false if there is no form object found with JS validation active.
819 + * @return false|stdClass false if there is no form object found with JS validation active.
700 820 */
701 821 private static function get_form_for_js_validation( $field ) {
702 822 global $frm_vars;
703 823 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
@@ -714,9 +834,9 @@
714 834 /**
715 835 * @param stdClass $form
716 836 * @param array $field
717 837 * @param array $errors
718 - * @return string|false
838 + * @return false|string
719 839 */
720 840 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
721 841 if ( empty( $field['custom_html'] ) ) {
722 842 return false;
@@ -757,8 +877,9 @@
757 877 *
758 878 * @since 3.06.01
759 879 * @param array $field
760 880 * @param array $add_html
881 + * @return void
761 882 */
762 883 private static function maybe_add_html_required( $field, array &$add_html ) {
763 884 $excluded_field_types =
764 885 FrmField::is_radio( $field ) ||
@@ -770,14 +891,16 @@
770 891 if ( $excluded_field_types ) {
771 892 return;
772 893 }
773 894
774 - $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
775 - if ( $include_html ) {
776 - $add_html['aria-required'] = 'aria-required="true"';
777 - }
895 + $add_html['aria-required'] = 'aria-required="true"';
778 896 }
779 897
898 + /**
899 + * @param array $field
900 + * @param array $add_html
901 + * @return void
902 + */
780 903 private static function add_shortcodes_to_html( $field, array &$add_html ) {
781 904 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
782 905 return;
783 906 }
@@ -786,9 +909,19 @@
786 909 unset( $field['shortcodes']['autocomplete'] );
787 910 }
788 911
789 912 foreach ( $field['shortcodes'] as $k => $v ) {
790 - if ( 'opt' === $k ) {
913 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
914 + $subfield_name = $field['subfield_name'];
915 + if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
916 + continue;
917 + }
918 + // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
919 + $k = 'aria-invalid';
920 + $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
921 + unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
922 + }
923 + if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
791 924 continue;
792 925 }
793 926
794 927 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -799,32 +932,44 @@
799 932 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
800 933 }
801 934
802 935 unset( $k, $v );
936 + }//end foreach
937 + }
938 +
939 + /**
940 + * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
941 + *
942 + * @since 6.11.2
943 + *
944 + * @param string $key The option key.
945 + * @return bool
946 + */
947 + private static function should_allow_input_attribute( $key ) {
948 + if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
949 + return true;
803 950 }
951 + return FrmAppHelper::input_key_is_safe( $key );
804 952 }
805 953
806 954 /**
807 - * Add pattern attribute
955 + * Add pattern attribute.
808 956 *
809 957 * @since 3.0
810 958 *
811 959 * @param array $field
812 960 * @param array $add_html
961 + * @return void
813 962 */
814 963 private static function add_pattern_attribute( $field, array &$add_html ) {
815 964 $has_format = FrmField::is_option_true_in_array( $field, 'format' );
816 965 $format_field = FrmField::is_field_type( $field, 'text' );
817 966
818 - if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
819 - $frm_settings = FrmAppHelper::get_settings();
967 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
968 + $format = FrmEntryValidate::phone_format( $field );
969 + $format = substr( $format, 2, - 1 );
820 970
821 - if ( $frm_settings->use_html ) {
822 - $format = FrmEntryValidate::phone_format( $field );
823 - $format = substr( $format, 2, - 1 );
824 -
825 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
826 - }
971 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
827 972 }
828 973 }
829 974
830 975 public static function check_value( $opt, $opt_key, $field ) {
@@ -840,88 +985,10 @@
840 985 }
841 986
842 987 public static function check_label( $opt ) {
843 988 if ( is_array( $opt ) ) {
844 - $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
989 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
845 990 }
846 991
847 992 return $opt;
848 - }
849 -
850 - /**
851 - * @deprecated 4.0
852 - */
853 - public static function update_ajax_option() {
854 - _deprecated_function( __METHOD__, '4.0' );
855 - FrmAppHelper::permission_check( 'frm_edit_forms' );
856 - check_ajax_referer( 'frm_ajax', 'nonce' );
857 -
858 - $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
859 - if ( ! $field_id ) {
860 - wp_die();
861 - }
862 -
863 - $field = FrmField::getOne( $field_id );
864 -
865 - if ( isset( $_POST['separate_value'] ) ) {
866 - $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
867 -
868 - $field->field_options['separate_value'] = $new_val;
869 - unset( $new_val );
870 - }
871 -
872 - FrmField::update(
873 - $field_id,
874 - array(
875 - 'field_options' => $field->field_options,
876 - 'form_id' => $field->form_id,
877 - )
878 - );
879 - wp_die();
880 - }
881 -
882 - /**
883 - * @deprecated 4.0
884 - */
885 - public static function import_choices() {
886 - _deprecated_function( __METHOD__, '4.0' );
887 - wp_die();
888 - }
889 -
890 - /**
891 - * Add Single Option or Other Option.
892 - *
893 - * @deprecated 4.0 Moved to Pro for Other option only.
894 - */
895 - public static function add_option() {
896 - _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
897 - }
898 -
899 - /**
900 - * @deprecated 4.0
901 - */
902 - public static function update_order() {
903 - FrmDeprecated::update_order();
904 - }
905 -
906 - /**
907 - * @deprecated 3.0
908 - * @codeCoverageIgnore
909 - */
910 - public static function edit_name( $field = 'name', $id = '' ) {
911 - FrmDeprecated::edit_name( $field, $id );
912 - }
913 -
914 - /**
915 - * @deprecated 3.0
916 - * @codeCoverageIgnore
917 - *
918 - * @param int $field_id
919 - * @param array $values
920 - * @param int $form_id
921 - *
922 - * @return array
923 - */
924 - public static function include_single_field( $field_id, $values, $form_id = 0 ) {
925 - return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
926 993 }
927 994 }