PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.15
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.15
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 +223 -161 6.56.15 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,31 @@
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 + if ( $autocomplete && empty( $use_chosen ) ) {
706 + // This is required for Slim Select.
707 + $placeholder_attributes['data-placeholder'] = 'true';
708 + }
709 +
710 + FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
627 711 return true;
628 712 }
629 713
630 714 return false;
@@ -630,12 +714,13 @@
630 714 return false;
631 715 }
632 716
633 717 /**
634 - * Use HMTL5 placeholder with js fallback
718 + * Use HTML5 placeholder with js fallback.
635 719 *
636 720 * @param array $field
637 721 * @param array $add_html
722 + * @return void
638 723 */
639 724 private static function add_placeholder_to_input( $field, &$add_html ) {
640 725 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
641 726 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -641,8 +726,13 @@
641 726 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
642 727 }
643 728 }
644 729
730 + /**
731 + * @param array $field
732 + * @param array $add_html
733 + * @return void
734 + */
645 735 private static function add_frmval_to_input( $field, &$add_html ) {
646 736 if ( $field['placeholder'] != '' ) {
647 737 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
648 738
@@ -656,15 +746,17 @@
656 746 }
657 747 }
658 748
659 749 private static function add_validation_messages( $field, array &$add_html ) {
660 - if ( FrmField::is_required( $field ) ) {
750 + $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
751 +
752 + if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
661 753 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
662 754 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
663 755 self::maybe_add_html_required( $field, $add_html );
664 756 }
665 757
666 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
758 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
667 759 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
668 760 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
669 761 }
670 762
@@ -673,12 +765,45 @@
673 765 }
674 766 }
675 767
676 768 /**
769 + * Returns an array that contains field validation messages status.
770 + *
771 + * @since 6.9
772 + *
773 + * @param array|object $field
774 + * @return array
775 + */
776 + private static function get_validation_data_attribute_visibility_info( $field ) {
777 + if ( FrmField::get_field_type( $field ) === 'hidden' ) {
778 + $field_validation_data_attributes = array(
779 + 'data-invmsg' => false,
780 + 'data-reqmsg' => false,
781 + );
782 + } else {
783 + $field_validation_data_attributes = array(
784 + 'data-invmsg' => true,
785 + 'data-reqmsg' => true,
786 + );
787 + }
788 +
789 + /**
790 + * Allows controlling which field validation messages would be included in the field html.
791 + *
792 + * @since 6.9
793 + *
794 + * @param array $field_validation_messages_status
795 + * @param array|object $field
796 + */
797 + return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
798 + }
799 +
800 + /**
677 801 * @since 5.0.03
678 802 *
679 803 * @param array $field
680 804 * @param array $add_html
805 + * @return void
681 806 */
682 807 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
683 808 $form = self::get_form_for_js_validation( $field );
684 809 if ( false === $form ) {
@@ -695,9 +820,9 @@
695 820 /**
696 821 * @since 5.0.03
697 822 *
698 823 * @param array $field
699 - * @return stdClass|false false if there is no form object found with JS validation active.
824 + * @return false|stdClass false if there is no form object found with JS validation active.
700 825 */
701 826 private static function get_form_for_js_validation( $field ) {
702 827 global $frm_vars;
703 828 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
@@ -714,9 +839,9 @@
714 839 /**
715 840 * @param stdClass $form
716 841 * @param array $field
717 842 * @param array $errors
718 - * @return string|false
843 + * @return false|string
719 844 */
720 845 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
721 846 if ( empty( $field['custom_html'] ) ) {
722 847 return false;
@@ -757,8 +882,9 @@
757 882 *
758 883 * @since 3.06.01
759 884 * @param array $field
760 885 * @param array $add_html
886 + * @return void
761 887 */
762 888 private static function maybe_add_html_required( $field, array &$add_html ) {
763 889 $excluded_field_types =
764 890 FrmField::is_radio( $field ) ||
@@ -770,14 +896,16 @@
770 896 if ( $excluded_field_types ) {
771 897 return;
772 898 }
773 899
774 - $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
775 - if ( $include_html ) {
776 - $add_html['aria-required'] = 'aria-required="true"';
777 - }
900 + $add_html['aria-required'] = 'aria-required="true"';
778 901 }
779 902
903 + /**
904 + * @param array $field
905 + * @param array $add_html
906 + * @return void
907 + */
780 908 private static function add_shortcodes_to_html( $field, array &$add_html ) {
781 909 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
782 910 return;
783 911 }
@@ -786,9 +914,9 @@
786 914 unset( $field['shortcodes']['autocomplete'] );
787 915 }
788 916
789 917 foreach ( $field['shortcodes'] as $k => $v ) {
790 - if ( 'opt' === $k ) {
918 + if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
791 919 continue;
792 920 }
793 921
794 922 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -803,28 +931,40 @@
803 931 }
804 932 }
805 933
806 934 /**
807 - * Add pattern attribute
935 + * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
808 936 *
937 + * @since 6.11.2
938 + *
939 + * @param string $key The option key.
940 + * @return bool
941 + */
942 + private static function should_allow_input_attribute( $key ) {
943 + if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
944 + return true;
945 + }
946 + return FrmAppHelper::input_key_is_safe( $key );
947 + }
948 +
949 + /**
950 + * Add pattern attribute.
951 + *
809 952 * @since 3.0
810 953 *
811 954 * @param array $field
812 955 * @param array $add_html
956 + * @return void
813 957 */
814 958 private static function add_pattern_attribute( $field, array &$add_html ) {
815 959 $has_format = FrmField::is_option_true_in_array( $field, 'format' );
816 960 $format_field = FrmField::is_field_type( $field, 'text' );
817 961
818 - if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
819 - $frm_settings = FrmAppHelper::get_settings();
962 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
963 + $format = FrmEntryValidate::phone_format( $field );
964 + $format = substr( $format, 2, - 1 );
820 965
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 - }
966 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
827 967 }
828 968 }
829 969
830 970 public static function check_value( $opt, $opt_key, $field ) {
@@ -840,88 +980,10 @@
840 980 }
841 981
842 982 public static function check_label( $opt ) {
843 983 if ( is_array( $opt ) ) {
844 - $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
984 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
845 985 }
846 986
847 987 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 988 }
927 989 }