PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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 +220 -160 6.5.26.13 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,10 +446,10 @@
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 object|null $field_info
410 452 *
411 453 * @return array
412 454 */
413 455 public static function display_field_options( $settings, $field_info = null ) {
@@ -424,11 +466,20 @@
424 466 *
425 467 * @since 3.0
426 468 *
427 469 * @param array $field
470 + * @return void
428 471 */
429 472 public static function show_format_option( $field ) {
430 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
473 + $attributes = array();
474 + $attributes['class'] = 'frm-has-modal';
475 +
476 + if ( 'phone' === $field['type'] ) {
477 + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id'];
478 + $attributes['class'] .= ' frm_hidden';
479 + }
480 +
481 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
431 482 }
432 483
433 484 public static function input_html( $field, $echo = true ) {
434 485 $class = array();
@@ -456,14 +507,19 @@
456 507
457 508 return $add_html;
458 509 }
459 510
511 + /**
512 + * @param array $field
513 + * @param array $class
514 + * @return void
515 + */
460 516 private static function add_input_classes( $field, array &$class ) {
461 - if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
517 + if ( ! empty( $field['input_class'] ) ) {
462 518 $class[] = $field['input_class'];
463 519 }
464 520
465 - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
521 + if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
466 522 return;
467 523 }
468 524
469 525 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -470,8 +526,13 @@
470 526 $class[] = 'auto_width';
471 527 }
472 528 }
473 529
530 + /**
531 + * @param array $field
532 + * @param array $add_html
533 + * @return void
534 + */
474 535 private static function add_html_size( $field, array &$add_html ) {
475 536 $size_fields = array(
476 537 'select',
477 538 'data',
@@ -480,9 +541,9 @@
480 541 'file',
481 542 'lookup',
482 543 );
483 544
484 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
545 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
485 546 return;
486 547 }
487 548
488 549 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -499,8 +560,13 @@
499 560
500 561 self::add_html_cols( $field, $add_html );
501 562 }
502 563
564 + /**
565 + * @param array $field
566 + * @param array $add_html
567 + * @return void
568 + */
503 569 private static function add_html_cols( $field, array &$add_html ) {
504 570 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
505 571 return;
506 572 }
@@ -524,8 +590,13 @@
524 590
525 591 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
526 592 }
527 593
594 + /**
595 + * @param array $field
596 + * @param array $add_html
597 + * @return void
598 + */
528 599 private static function add_html_length( $field, array &$add_html ) {
529 600 // Check for max setting and if this field accepts maxlength.
530 601 $fields = array(
531 602 'textarea',
@@ -533,9 +604,9 @@
533 604 'hidden',
534 605 'file',
535 606 );
536 607
537 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
608 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
538 609 return;
539 610 }
540 611
541 612 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -545,8 +616,14 @@
545 616
546 617 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
547 618 }
548 619
620 + /**
621 + * @param array $field
622 + * @param array $add_html
623 + * @param array $class
624 + * @return void
625 + */
549 626 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
550 627 if ( $field['default_value'] != '' ) {
551 628 if ( is_array( $field['default_value'] ) ) {
552 629 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -560,21 +637,9 @@
560 637 // don't include a json placeholder
561 638 return;
562 639 }
563 640
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 - }
641 + self::add_placeholder_to_input( $field, $add_html );
577 642 }
578 643
579 644 /**
580 645 * Prepares field placeholder.
@@ -617,14 +682,31 @@
617 682 if ( empty( $placeholder ) ) {
618 683 $placeholder = self::get_default_value_from_name( $field );
619 684 }
620 685
686 + $use_placeholder = $placeholder;
687 + $autocomplete = FrmField::get_option( $field, 'autocom' );
688 +
689 + if ( $autocomplete ) {
690 + $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
691 + if ( $use_chosen ) {
692 + $use_placeholder = '';
693 + }
694 + }
695 +
621 696 if ( $placeholder !== '' ) {
622 - ?>
623 - <option class="frm-select-placeholder" value="">
624 - <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
625 - </option>
626 - <?php
697 + $placeholder_attributes = array(
698 + 'class' => 'frm-select-placeholder',
699 + 'value' => '',
700 + 'data-placeholder' => 'true',
701 + );
702 +
703 + if ( $autocomplete && empty( $use_chosen ) ) {
704 + // This is required for Slim Select.
705 + $placeholder_attributes['data-placeholder'] = 'true';
706 + }
707 +
708 + FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
627 709 return true;
628 710 }
629 711
630 712 return false;
@@ -630,12 +712,13 @@
630 712 return false;
631 713 }
632 714
633 715 /**
634 - * Use HMTL5 placeholder with js fallback
716 + * Use HTML5 placeholder with js fallback.
635 717 *
636 718 * @param array $field
637 719 * @param array $add_html
720 + * @return void
638 721 */
639 722 private static function add_placeholder_to_input( $field, &$add_html ) {
640 723 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
641 724 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -641,8 +724,13 @@
641 724 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
642 725 }
643 726 }
644 727
728 + /**
729 + * @param array $field
730 + * @param array $add_html
731 + * @return void
732 + */
645 733 private static function add_frmval_to_input( $field, &$add_html ) {
646 734 if ( $field['placeholder'] != '' ) {
647 735 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
648 736
@@ -656,15 +744,17 @@
656 744 }
657 745 }
658 746
659 747 private static function add_validation_messages( $field, array &$add_html ) {
660 - if ( FrmField::is_required( $field ) ) {
748 + $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
749 +
750 + if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
661 751 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
662 752 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
663 753 self::maybe_add_html_required( $field, $add_html );
664 754 }
665 755
666 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
756 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
667 757 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
668 758 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
669 759 }
670 760
@@ -673,12 +763,45 @@
673 763 }
674 764 }
675 765
676 766 /**
767 + * Returns an array that contains field validation messages status.
768 + *
769 + * @since 6.9
770 + *
771 + * @param array|object $field
772 + * @return array
773 + */
774 + private static function get_validation_data_attribute_visibility_info( $field ) {
775 + if ( FrmField::get_field_type( $field ) === 'hidden' ) {
776 + $field_validation_data_attributes = array(
777 + 'data-invmsg' => false,
778 + 'data-reqmsg' => false,
779 + );
780 + } else {
781 + $field_validation_data_attributes = array(
782 + 'data-invmsg' => true,
783 + 'data-reqmsg' => true,
784 + );
785 + }
786 +
787 + /**
788 + * Allows controlling which field validation messages would be included in the field html.
789 + *
790 + * @since 6.9
791 + *
792 + * @param array $field_validation_messages_status
793 + * @param array|object $field
794 + */
795 + return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
796 + }
797 +
798 + /**
677 799 * @since 5.0.03
678 800 *
679 801 * @param array $field
680 802 * @param array $add_html
803 + * @return void
681 804 */
682 805 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
683 806 $form = self::get_form_for_js_validation( $field );
684 807 if ( false === $form ) {
@@ -695,9 +818,9 @@
695 818 /**
696 819 * @since 5.0.03
697 820 *
698 821 * @param array $field
699 - * @return stdClass|false false if there is no form object found with JS validation active.
822 + * @return false|stdClass false if there is no form object found with JS validation active.
700 823 */
701 824 private static function get_form_for_js_validation( $field ) {
702 825 global $frm_vars;
703 826 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
@@ -714,9 +837,9 @@
714 837 /**
715 838 * @param stdClass $form
716 839 * @param array $field
717 840 * @param array $errors
718 - * @return string|false
841 + * @return false|string
719 842 */
720 843 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
721 844 if ( empty( $field['custom_html'] ) ) {
722 845 return false;
@@ -757,8 +880,9 @@
757 880 *
758 881 * @since 3.06.01
759 882 * @param array $field
760 883 * @param array $add_html
884 + * @return void
761 885 */
762 886 private static function maybe_add_html_required( $field, array &$add_html ) {
763 887 $excluded_field_types =
764 888 FrmField::is_radio( $field ) ||
@@ -770,14 +894,16 @@
770 894 if ( $excluded_field_types ) {
771 895 return;
772 896 }
773 897
774 - $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
775 - if ( $include_html ) {
776 - $add_html['aria-required'] = 'aria-required="true"';
777 - }
898 + $add_html['aria-required'] = 'aria-required="true"';
778 899 }
779 900
901 + /**
902 + * @param array $field
903 + * @param array $add_html
904 + * @return void
905 + */
780 906 private static function add_shortcodes_to_html( $field, array &$add_html ) {
781 907 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
782 908 return;
783 909 }
@@ -786,9 +912,9 @@
786 912 unset( $field['shortcodes']['autocomplete'] );
787 913 }
788 914
789 915 foreach ( $field['shortcodes'] as $k => $v ) {
790 - if ( 'opt' === $k ) {
916 + if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
791 917 continue;
792 918 }
793 919
794 920 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -803,28 +929,40 @@
803 929 }
804 930 }
805 931
806 932 /**
807 - * Add pattern attribute
933 + * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
808 934 *
935 + * @since 6.11.2
936 + *
937 + * @param string $key The option key.
938 + * @return bool
939 + */
940 + private static function should_allow_input_attribute( $key ) {
941 + if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
942 + return true;
943 + }
944 + return FrmAppHelper::input_key_is_safe( $key );
945 + }
946 +
947 + /**
948 + * Add pattern attribute.
949 + *
809 950 * @since 3.0
810 951 *
811 952 * @param array $field
812 953 * @param array $add_html
954 + * @return void
813 955 */
814 956 private static function add_pattern_attribute( $field, array &$add_html ) {
815 957 $has_format = FrmField::is_option_true_in_array( $field, 'format' );
816 958 $format_field = FrmField::is_field_type( $field, 'text' );
817 959
818 - if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
819 - $frm_settings = FrmAppHelper::get_settings();
960 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
961 + $format = FrmEntryValidate::phone_format( $field );
962 + $format = substr( $format, 2, - 1 );
820 963
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 - }
964 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
827 965 }
828 966 }
829 967
830 968 public static function check_value( $opt, $opt_key, $field ) {
@@ -840,88 +978,10 @@
840 978 }
841 979
842 980 public static function check_label( $opt ) {
843 981 if ( is_array( $opt ) ) {
844 - $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
982 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
845 983 }
846 984
847 985 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 986 }
927 987 }