PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.10
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.10
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmFieldsController.php +62 -214 6.266.10 View file →
@@ -18,9 +18,8 @@
18 18
19 19 // Javascript may be included in some field settings.
20 20 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
21 21 $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array();
22 -
23 22 if ( empty( $fields ) ) {
24 23 wp_die();
25 24 }
26 25
@@ -34,9 +33,8 @@
34 33
35 34 foreach ( $fields as $field ) {
36 35 $field = htmlspecialchars_decode( nl2br( $field ) );
37 36 $field = json_decode( $field );
38 -
39 37 if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
40 38 // this field may have already been loaded
41 39 continue;
42 40 }
@@ -51,9 +49,9 @@
51 49 ob_start();
52 50 self::load_single_field( $field, $values );
53 51 $field_html[ absint( $field->id ) ] = ob_get_contents();
54 52 ob_end_clean();
55 - }//end foreach
53 + }
56 54
57 55 echo json_encode( $field_html );
58 56
59 57 wp_die();
@@ -65,15 +63,14 @@
65 63 public static function create() {
66 64 FrmAppHelper::permission_check( 'frm_edit_forms' );
67 65 check_ajax_referer( 'frm_ajax', 'nonce' );
68 66
69 - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
70 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
71 - $field_options = FrmAppHelper::get_post_param( 'field_options', array(), 'wp_kses_post' );
67 + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
68 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
72 69
73 70 do_action( 'frm_before_create_field', $field_type, $form_id );
74 71
75 - $field = self::include_new_field( $field_type, $form_id, $field_options );
72 + $field = self::include_new_field( $field_type, $form_id );
76 73
77 74 // this hook will allow for multiple fields to be added at once
78 75 do_action( 'frm_after_field_created', $field, $form_id );
79 76
@@ -84,19 +81,14 @@
84 81 * Set up and create a new field
85 82 *
86 83 * @param string $field_type
87 84 * @param int $form_id
88 - * @param array $field_options
89 85 *
90 - * @return array|false
86 + * @return array|bool
91 87 */
92 - public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
88 + public static function include_new_field( $field_type, $form_id ) {
93 89 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
94 90
95 - if ( ! empty( $field_options ) ) {
96 - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
97 - }
98 -
99 91 // When a new field is added to the form, flag it as draft and hide it from the front-end.
100 92 $field_values['field_options']['draft'] = 1;
101 93
102 94 /**
@@ -111,14 +103,12 @@
111 103
112 104 $field = self::get_field_array_from_id( $field_id );
113 105
114 106 $values = array();
115 -
116 107 if ( FrmAppHelper::pro_is_installed() ) {
117 108 $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
118 109
119 110 $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
120 -
121 111 if ( $parent_form_id ) {
122 112 $field['parent_form_id'] = $parent_form_id;
123 113 }
124 114 }
@@ -162,10 +152,8 @@
162 152 *
163 153 * @param array|int|object $field_object
164 154 * @param array $values
165 155 * @param int $form_id
166 - *
167 - * @return void
168 156 */
169 157 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
170 158 global $frm_vars;
171 159 $frm_vars['is_admin'] = true;
@@ -189,23 +177,12 @@
189 177 return;
190 178 }
191 179
192 180 if ( ! isset( $field ) && is_object( $field_object ) ) {
193 - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id;
181 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
194 182 $field = FrmFieldsHelper::setup_edit_vars( $field_object );
195 183 }
196 184
197 - /**
198 - * Filter for adding extra attributes to the field container.
199 - *
200 - * @since 6.23
201 - *
202 - * @param array $extra_field_attributes
203 - * @param array $field
204 - * @param array $display
205 - */
206 - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display );
207 -
208 185 $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
209 186 $li_classes .= ' ui-state-default widgets-holder-wrap';
210 187
211 188 require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
@@ -212,14 +189,8 @@
212 189 }
213 190
214 191 /**
215 192 * @since 3.0
216 - *
217 - * @param array $field
218 - * @param array $display
219 - * @param FrmFieldType $field_info
220 - *
221 - * @return string
222 193 */
223 194 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
224 195 $li_classes = $field_info->form_builder_classes( $display['type'] );
225 196 $li_classes .= ' frm_form_field frmstart ';
@@ -266,9 +237,8 @@
266 237 *
267 238 * @since 6.8.4
268 239 *
269 240 * @param array $bulk_edit_types
270 - *
271 241 * @return array
272 242 */
273 243 $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
274 244
@@ -281,9 +251,9 @@
281 251 $opts = explode( "\n", rtrim( $opts, "\n" ) );
282 252 $opts = array_map( 'trim', $opts );
283 253
284 254 $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
285 - $field['separate_value'] = $separate === 'true';
255 + $field['separate_value'] = ( $separate === 'true' );
286 256
287 257 if ( $field['separate_value'] ) {
288 258 foreach ( $opts as $opt_key => $opt ) {
289 259 if ( strpos( $opt, '|' ) !== false ) {
@@ -300,9 +270,8 @@
300 270
301 271 // Keep other options after bulk update.
302 272 if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
303 273 $other_array = array();
304 -
305 274 foreach ( $field['options'] as $opt_key => $opt ) {
306 275 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
307 276 $other_array[ $opt_key ] = $opt;
308 277 }
@@ -307,9 +276,8 @@
307 276 $other_array[ $opt_key ] = $opt;
308 277 }
309 278 unset( $opt_key, $opt );
310 279 }
311 -
312 280 if ( ! empty( $other_array ) ) {
313 281 $opts = array_merge( $opts, $other_array );
314 282 }
315 283 }
@@ -324,10 +292,8 @@
324 292 /**
325 293 * @since 4.0
326 294 *
327 295 * @param array $atts - Includes field array, field_obj, display array, values array.
328 - *
329 - * @return void
330 296 */
331 297 public static function load_single_field_settings( $atts ) {
332 298 $field = $atts['field'];
333 299 $field_obj = $atts['field_obj'];
@@ -360,9 +326,8 @@
360 326 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
361 327 }
362 328
363 329 $type_name = $all_field_types[ $field['type'] ]['name'];
364 -
365 330 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
366 331 $type_name = $all_field_types['divider|repeat']['name'];
367 332 }
368 333
@@ -395,9 +360,8 @@
395 360 * @since 4.0
396 361 *
397 362 * @param array $field
398 363 * @param array $atts
399 - *
400 364 * @return array
401 365 */
402 366 private static function default_value_types( $field, $atts ) {
403 367 $types = array(
@@ -403,32 +367,30 @@
403 367 $types = array(
404 368 'default_value' => array(
405 369 'class' => '',
406 370 'icon' => 'frm_icon_font frm_text2_icon',
407 - 'title' => __( 'Default Value', 'formidable' ),
371 + 'title' => __( 'Default Value (Text)', 'formidable' ),
408 372 'data' => array(
409 373 'frmshow' => '#default-value-for-',
410 374 ),
411 375 ),
412 376 'calc' => array(
413 - 'class' => 'frm_show_upgrade frm_noallow',
414 - 'title' => __( 'Calculate Value', 'formidable' ),
415 - 'icon' => 'frm_icon_font frm_calculator_icon',
416 - 'data' => array(
377 + 'class' => 'frm_show_upgrade frm_noallow',
378 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
379 + 'icon' => 'frm_icon_font frm_calculator_icon',
380 + 'data' => array(
417 381 'medium' => 'calculations',
418 382 'upgrade' => __( 'Calculator forms', 'formidable' ),
419 383 ),
420 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
421 384 ),
422 385 'get_values_field' => array(
423 - 'class' => 'frm_show_upgrade frm_noallow',
424 - 'title' => __( 'Lookup', 'formidable' ),
425 - 'icon' => 'frm_icon_font frm_search_icon',
426 - 'data' => array(
386 + 'class' => 'frm_show_upgrade frm_noallow',
387 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
388 + 'icon' => 'frm_icon_font frm_search_icon',
389 + 'data' => array(
427 390 'medium' => 'lookup',
428 391 'upgrade' => __( 'Lookup fields', 'formidable' ),
429 392 ),
430 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
431 393 ),
432 394 );
433 395
434 396 $types = apply_filters( 'frm_default_value_types', $types, $atts );
@@ -436,13 +398,11 @@
436 398 // Set active class.
437 399 $settings = array_keys( $types );
438 400 $active = 'default_value';
439 401
440 - if ( FrmAppHelper::pro_is_connected() ) {
441 - foreach ( $settings as $type ) {
442 - if ( ! empty( $field[ $type ] ) ) {
443 - $active = $type;
444 - }
402 + foreach ( $settings as $type ) {
403 + if ( ! empty( $field[ $type ] ) ) {
404 + $active = $type;
445 405 }
446 406 }
447 407
448 408 $types[ $active ]['class'] .= ' current';
@@ -450,13 +410,8 @@
450 410
451 411 return $types;
452 412 }
453 413
454 - /**
455 - * @param string $type
456 - *
457 - * @return string
458 - */
459 414 public static function change_type( $type ) {
460 415 $type_switch = array(
461 416 'scale' => 'radio',
462 417 'star' => 'radio',
@@ -464,9 +419,8 @@
464 419 'rte' => 'textarea',
465 420 'website' => 'url',
466 421 'image' => 'url',
467 422 );
468 -
469 423 if ( isset( $type_switch[ $type ] ) ) {
470 424 $type = $type_switch[ $type ];
471 425 }
472 426
@@ -482,18 +436,16 @@
482 436 return $type;
483 437 }
484 438
485 439 /**
486 - * @param array $settings
487 - * @param FrmFieldType|null $field_info
440 + * @param array $settings
441 + * @param object $field_info
488 442 *
489 443 * @return array
490 444 */
491 445 public static function display_field_options( $settings, $field_info = null ) {
492 446 if ( $field_info ) {
493 - $settings = $field_info->display_field_settings();
494 -
495 - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
447 + $settings = $field_info->display_field_settings();
496 448 $settings['field_data'] = $field_info->field;
497 449 }
498 450
499 451 return apply_filters( 'frm_display_field_options', $settings );
@@ -503,20 +455,16 @@
503 455 * Display the format option
504 456 *
505 457 * @since 3.0
506 458 *
507 - * @param array $field Field data.
508 - * @param bool $is_hidden Whether the format option should be hidden.
509 - *
510 - * @return void
459 + * @param array $field
511 460 */
512 - public static function show_format_option( $field, $is_hidden = false ) {
513 - $attributes = array(
514 - 'class' => 'frm-has-modal',
515 - 'id' => 'frm-field-format-custom-' . $field['id'],
516 - );
461 + public static function show_format_option( $field ) {
462 + $attributes = array();
463 + $attributes['class'] = 'frm-has-modal';
517 464
518 - if ( $is_hidden ) {
465 + if ( 'phone' === $field['type'] ) {
466 + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id'];
519 467 $attributes['class'] .= ' frm_hidden';
520 468 }
521 469
522 470 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
@@ -521,14 +469,8 @@
521 469
522 470 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
523 471 }
524 472
525 - /**
526 - * @param array $field
527 - * @param bool $echo
528 - *
529 - * @return string
530 - */
531 473 public static function input_html( $field, $echo = true ) {
532 474 $class = array();
533 475 self::add_input_classes( $field, $class );
534 476
@@ -554,14 +496,8 @@
554 496
555 497 return $add_html;
556 498 }
557 499
558 - /**
559 - * @param array $field
560 - * @param array $class
561 - *
562 - * @return void
563 - */
564 500 private static function add_input_classes( $field, array &$class ) {
565 501 if ( ! empty( $field['input_class'] ) ) {
566 502 $class[] = $field['input_class'];
567 503 }
@@ -574,14 +510,8 @@
574 510 $class[] = 'auto_width';
575 511 }
576 512 }
577 513
578 - /**
579 - * @param array $field
580 - * @param array $add_html
581 - *
582 - * @return void
583 - */
584 514 private static function add_html_size( $field, array &$add_html ) {
585 515 $size_fields = array(
586 516 'select',
587 517 'data',
@@ -609,14 +539,8 @@
609 539
610 540 self::add_html_cols( $field, $add_html );
611 541 }
612 542
613 - /**
614 - * @param array $field
615 - * @param array $add_html
616 - *
617 - * @return void
618 - */
619 543 private static function add_html_cols( $field, array &$add_html ) {
620 544 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
621 545 return;
622 546 }
@@ -640,14 +564,8 @@
640 564
641 565 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
642 566 }
643 567
644 - /**
645 - * @param array $field
646 - * @param array $add_html
647 - *
648 - * @return void
649 - */
650 568 private static function add_html_length( $field, array &$add_html ) {
651 569 // Check for max setting and if this field accepts maxlength.
652 570 $fields = array(
653 571 'textarea',
@@ -667,15 +585,8 @@
667 585
668 586 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
669 587 }
670 588
671 - /**
672 - * @param array $field
673 - * @param array $add_html
674 - * @param array $class
675 - *
676 - * @return void
677 - */
678 589 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
679 590 if ( $field['default_value'] != '' ) {
680 591 if ( is_array( $field['default_value'] ) ) {
681 592 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -684,15 +595,26 @@
684 595 }
685 596 }
686 597
687 598 $field['placeholder'] = self::prepare_placeholder( $field );
688 -
689 599 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
690 600 // don't include a json placeholder
691 601 return;
692 602 }
693 603
694 - self::add_placeholder_to_input( $field, $add_html );
604 + $frm_settings = FrmAppHelper::get_settings();
605 +
606 + if ( $frm_settings->use_html ) {
607 + self::add_placeholder_to_input( $field, $add_html );
608 + } else {
609 + self::add_frmval_to_input( $field, $add_html );
610 +
611 + $class[] = 'frm_toggle_default';
612 +
613 + if ( $field['value'] == $field['placeholder'] ) {
614 + $class[] = 'frm_default';
615 + }
616 + }
695 617 }
696 618
697 619 /**
698 620 * Prepares field placeholder.
@@ -699,13 +621,12 @@
699 621 *
700 622 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
701 623 *
702 624 * @param array $field Field array.
703 - *
704 625 * @return string
705 626 */
706 627 private static function prepare_placeholder( $field ) {
707 - $placeholder = $field['placeholder'] ?? '';
628 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
708 629
709 630 return $placeholder;
710 631 }
711 632
@@ -728,16 +649,12 @@
728 649 * Maybe add a blank placeholder option before any options
729 650 * in a dropdown.
730 651 *
731 652 * @since 4.04
732 - *
733 - * @param array|object $field
734 - *
735 653 * @return bool True if placeholder was added.
736 654 */
737 655 public static function add_placeholder_to_select( $field ) {
738 656 $placeholder = FrmField::get_option( $field, 'placeholder' );
739 -
740 657 if ( empty( $placeholder ) ) {
741 658 $placeholder = self::get_default_value_from_name( $field );
742 659 }
743 660
@@ -745,9 +662,8 @@
745 662 $autocomplete = FrmField::get_option( $field, 'autocom' );
746 663
747 664 if ( $autocomplete ) {
748 665 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
749 -
750 666 if ( $use_chosen ) {
751 667 $use_placeholder = '';
752 668 }
753 669 }
@@ -758,8 +674,13 @@
758 674 'value' => '',
759 675 'data-placeholder' => 'true',
760 676 );
761 677
678 + if ( $autocomplete && empty( $use_chosen ) ) {
679 + // This is required for Slim Select.
680 + $placeholder_attributes['data-placeholder'] = 'true';
681 + }
682 +
762 683 FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
763 684 return true;
764 685 }
765 686
@@ -766,14 +687,12 @@
766 687 return false;
767 688 }
768 689
769 690 /**
770 - * Use HTML5 placeholder with js fallback.
691 + * Use HMTL5 placeholder with js fallback
771 692 *
772 693 * @param array $field
773 694 * @param array $add_html
774 - *
775 - * @return void
776 695 */
777 696 private static function add_placeholder_to_input( $field, &$add_html ) {
778 697 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
779 698 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -779,14 +698,8 @@
779 698 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
780 699 }
781 700 }
782 701
783 - /**
784 - * @param array $field
785 - * @param array $add_html
786 - *
787 - * @return void
788 - */
789 702 private static function add_frmval_to_input( $field, &$add_html ) {
790 703 if ( $field['placeholder'] != '' ) {
791 704 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
792 705
@@ -799,14 +712,8 @@
799 712 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
800 713 }
801 714 }
802 715
803 - /**
804 - * @param array $field
805 - * @param array $add_html
806 - *
807 - * @return void
808 - */
809 716 private static function add_validation_messages( $field, array &$add_html ) {
810 717 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
811 718
812 719 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -830,9 +737,8 @@
830 737 *
831 738 * @since 6.9
832 739 *
833 740 * @param array|object $field
834 - *
835 741 * @return array
836 742 */
837 743 private static function get_validation_data_attribute_visibility_info( $field ) {
838 744 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -862,20 +768,16 @@
862 768 * @since 5.0.03
863 769 *
864 770 * @param array $field
865 771 * @param array $add_html
866 - *
867 - * @return void
868 772 */
869 773 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
870 774 $form = self::get_form_for_js_validation( $field );
871 -
872 775 if ( false === $form ) {
873 776 return;
874 777 }
875 778
876 779 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
877 -
878 780 if ( false !== $error_body ) {
879 781 $error_body = urlencode( $error_body );
880 782 $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
881 783 }
@@ -884,19 +786,16 @@
884 786 /**
885 787 * @since 5.0.03
886 788 *
887 789 * @param array $field
888 - *
889 790 * @return false|stdClass false if there is no form object found with JS validation active.
890 791 */
891 792 private static function get_form_for_js_validation( $field ) {
892 793 global $frm_vars;
893 -
894 794 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
895 795 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
896 796 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
897 797 }
898 -
899 798 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
900 799 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
901 800 }
902 801 }
@@ -906,9 +805,8 @@
906 805 /**
907 806 * @param stdClass $form
908 807 * @param array $field
909 808 * @param array $errors
910 - *
911 809 * @return false|string
912 810 */
913 811 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
914 812 if ( empty( $field['custom_html'] ) ) {
@@ -918,15 +816,13 @@
918 816 $custom_html = $field['custom_html'];
919 817 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
920 818
921 819 $start = strpos( $custom_html, '[if error]' );
922 -
923 820 if ( false === $start ) {
924 821 return false;
925 822 }
926 823
927 824 $end = strpos( $custom_html, '[/if error]' );
928 -
929 825 if ( false === $end || $end < $start ) {
930 826 return false;
931 827 }
932 828
@@ -950,13 +846,10 @@
950 846 * submit in many browsers. Check to make sure the javascript to conditionally
951 847 * remove it is present if needed.
952 848 *
953 849 * @since 3.06.01
954 - *
955 850 * @param array $field
956 851 * @param array $add_html
957 - *
958 - * @return void
959 852 */
960 853 private static function maybe_add_html_required( $field, array &$add_html ) {
961 854 $excluded_field_types =
962 855 FrmField::is_radio( $field ) ||
@@ -971,14 +864,8 @@
971 864
972 865 $add_html['aria-required'] = 'aria-required="true"';
973 866 }
974 867
975 - /**
976 - * @param array $field
977 - * @param array $add_html
978 - *
979 - * @return void
980 - */
981 868 private static function add_shortcodes_to_html( $field, array &$add_html ) {
982 869 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
983 870 return;
984 871 }
@@ -987,21 +874,9 @@
987 874 unset( $field['shortcodes']['autocomplete'] );
988 875 }
989 876
990 877 foreach ( $field['shortcodes'] as $k => $v ) {
991 - if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
992 - $subfield_name = $field['subfield_name'];
993 -
994 - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
995 - continue;
996 - }
997 - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
998 - $k = 'aria-invalid';
999 - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1000 - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1001 - }
1002 -
1003 - if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
878 + if ( 'opt' === $k ) {
1004 879 continue;
1005 880 }
1006 881
1007 882 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -1012,63 +887,41 @@
1012 887 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1013 888 }
1014 889
1015 890 unset( $k, $v );
1016 - }//end foreach
1017 - }
1018 -
1019 - /**
1020 - * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
1021 - *
1022 - * @since 6.11.2
1023 - *
1024 - * @param string $key The option key.
1025 - *
1026 - * @return bool
1027 - */
1028 - private static function should_allow_input_attribute( $key ) {
1029 - if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
1030 - return true;
1031 891 }
1032 - return FrmAppHelper::input_key_is_safe( $key );
1033 892 }
1034 893
1035 894 /**
1036 - * Add pattern attribute.
895 + * Add pattern attribute
1037 896 *
1038 897 * @since 3.0
1039 898 *
1040 899 * @param array $field
1041 900 * @param array $add_html
1042 - *
1043 - * @return void
1044 901 */
1045 902 private static function add_pattern_attribute( $field, array &$add_html ) {
1046 - $format_value = FrmField::get_option( $field, 'format' );
1047 - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
903 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1048 904 $format_field = FrmField::is_field_type( $field, 'text' );
1049 905
1050 906 if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
1051 - $format = FrmEntryValidate::phone_format( $field );
1052 - $format = substr( $format, 2, - 1 );
907 + $frm_settings = FrmAppHelper::get_settings();
1053 908
1054 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
909 + if ( $frm_settings->use_html ) {
910 + $format = FrmEntryValidate::phone_format( $field );
911 + $format = substr( $format, 2, - 1 );
912 +
913 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
914 + }
1055 915 }
1056 916 }
1057 917
1058 - /**
1059 - * @param mixed $opt
1060 - * @param mixed $opt_key
1061 - * @param array|object $field
1062 - *
1063 - * @return mixed
1064 - */
1065 918 public static function check_value( $opt, $opt_key, $field ) {
1066 919 if ( is_array( $opt ) ) {
1067 920 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1068 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
921 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1069 922 } else {
1070 - $opt = $opt['label'] ?? reset( $opt );
923 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1071 924 }
1072 925 }
1073 926
1074 927 return $opt;
@@ -1073,16 +926,11 @@
1073 926
1074 927 return $opt;
1075 928 }
1076 929
1077 - /**
1078 - * @param mixed $opt
1079 - *
1080 - * @return mixed
1081 - */
1082 930 public static function check_label( $opt ) {
1083 931 if ( is_array( $opt ) ) {
1084 - $opt = $opt['label'] ?? reset( $opt );
932 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1085 933 }
1086 934
1087 935 return $opt;
1088 936 }