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 +241 -167 6.36.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,18 +80,24 @@
73 80 /**
74 81 * Set up and create a new field
75 82 *
76 83 * @param string $field_type
77 - * @param integer $form_id
84 + * @param int $form_id
78 85 *
79 - * @return array|bool
86 + * @return array|false
80 87 */
81 88 public static function include_new_field( $field_type, $form_id ) {
82 89 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
90 +
91 + // When a new field is added to the form, flag it as draft and hide it from the front-end.
92 + $field_values['field_options']['draft'] = 1;
93 +
94 + /**
95 + * @param array $field_values
96 + */
83 97 $field_values = apply_filters( 'frm_before_field_created', $field_values );
98 + $field_id = FrmField::create( $field_values );
84 99
85 - $field_id = FrmField::create( $field_values );
86 -
87 100 if ( ! $field_id ) {
88 101 return false;
89 102 }
90 103
@@ -136,11 +149,11 @@
136 149
137 150 /**
138 151 * @since 3.0
139 152 *
140 - * @param int|array|object $field_object
141 - * @param array $values
142 - * @param int $form_id
153 + * @param array|int|object $field_object
154 + * @param array $values
155 + * @param int $form_id
143 156 */
144 157 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
145 158 global $frm_vars;
146 159 $frm_vars['is_admin'] = true;
@@ -154,30 +167,35 @@
154 167
155 168 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
156 169 $display = self::display_field_options( array(), $field_obj );
157 170
158 - $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
159 - $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) );
171 + $ajax_loading = ! empty( $values['ajax_load'] );
172 + $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
160 173
161 174 if ( $ajax_loading && $ajax_this_field ) {
162 175 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
163 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' );
164 - } else {
165 - if ( ! isset( $field ) && is_object( $field_object ) ) {
166 - $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
176 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php';
177 + return;
178 + }
167 179
168 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
169 - }
180 + if ( ! isset( $field ) && is_object( $field_object ) ) {
181 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
182 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
183 + }
170 184
171 - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
172 - $li_classes .= ' ui-state-default widgets-holder-wrap';
185 + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
186 + $li_classes .= ' ui-state-default widgets-holder-wrap';
173 187
174 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
175 - }
188 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
176 189 }
177 190
178 191 /**
179 192 * @since 3.0
193 + *
194 + * @param array $field
195 + * @param array $display
196 + * @param FrmFieldType $field_info
197 + * @return string
180 198 */
181 199 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
182 200 $li_classes = $field_info->form_builder_classes( $display['type'] );
183 201 $li_classes .= ' frm_form_field frmstart ';
@@ -203,10 +221,11 @@
203 221 FrmField::destroy( $field_id );
204 222 wp_die();
205 223 }
206 224
207 - /* Field Options */
208 -
225 + /**
226 + * Field Options.
227 + */
209 228 public static function import_options() {
210 229 FrmAppHelper::permission_check( 'frm_edit_forms' );
211 230 check_ajax_referer( 'frm_ajax', 'nonce' );
212 231
@@ -213,12 +232,23 @@
213 232 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
214 233 return;
215 234 }
216 235
217 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
218 - $field = FrmField::getOne( $field_id );
236 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
237 + $field = FrmField::getOne( $field_id );
238 + $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
219 239
220 - if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
240 + /**
241 + * Filter to add new fields that will support import_options/Bulk Edit Options.
242 + *
243 + * @since 6.8.4
244 + *
245 + * @param array $bulk_edit_types
246 + * @return array
247 + */
248 + $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
249 +
250 + if ( ! in_array( $field->type, $bulk_edit_types, true ) ) {
221 251 return;
222 252 }
223 253
224 254 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -225,15 +255,15 @@
225 255 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
226 256 $opts = explode( "\n", rtrim( $opts, "\n" ) );
227 257 $opts = array_map( 'trim', $opts );
228 258
229 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
230 - $field['separate_value'] = ( $separate === 'true' );
259 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
260 + $field['separate_value'] = $separate === 'true';
231 261
232 262 if ( $field['separate_value'] ) {
233 263 foreach ( $opts as $opt_key => $opt ) {
234 264 if ( strpos( $opt, '|' ) !== false ) {
235 - $vals = explode( '|', $opt );
265 + $vals = explode( '|', $opt );
236 266 $opts[ $opt_key ] = array(
237 267 'label' => trim( $vals[0] ),
238 268 'value' => trim( $vals[1] ),
239 269 );
@@ -267,8 +297,9 @@
267 297 /**
268 298 * @since 4.0
269 299 *
270 300 * @param array $atts - Includes field array, field_obj, display array, values array.
301 + * @return void
271 302 */
272 303 public static function load_single_field_settings( $atts ) {
273 304 $field = $atts['field'];
274 305 $field_obj = $atts['field_obj'];
@@ -283,13 +314,13 @@
283 314 if ( ! isset( $field['read_only'] ) ) {
284 315 $field['read_only'] = false;
285 316 }
286 317
287 - $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
288 - $pro_field_selection = FrmField::pro_field_selection();
289 - $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
290 - $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
291 - $frm_settings = FrmAppHelper::get_settings();
318 + $field_selection_data = self::maybe_define_field_selection_data();
319 + $all_field_types = $field_selection_data->all_field_types;
320 + $disabled_fields = $field_selection_data->disabled_fields;
321 + $frm_settings = FrmAppHelper::get_settings();
322 + $field_types = FrmFieldTypeOptionData::get_field_types( $field['type'] );
292 323
293 324 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
294 325 // Add fallback for an add-on field type that has been deactivated.
295 326 $all_field_types[ $field['type'] ] = array(
@@ -312,20 +343,36 @@
312 343
313 344 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
314 345 $field['placeholder'] = implode( ', ', $field['placeholder'] );
315 346 }
316 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
347 +
348 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
317 349 }
318 350
319 351 /**
352 + * @since 6.9.1
353 + *
354 + * @return FrmFieldSelectionData
355 + */
356 + private static function maybe_define_field_selection_data() {
357 + if ( ! isset( self::$field_selection_data ) ) {
358 + self::$field_selection_data = new FrmFieldSelectionData();
359 + }
360 + return self::$field_selection_data;
361 + }
362 +
363 + /**
320 364 * Get the list of default value types that can be toggled in the builder.
321 365 *
322 366 * @since 4.0
367 + *
368 + * @param array $field
369 + * @param array $atts
323 370 * @return array
324 371 */
325 372 private static function default_value_types( $field, $atts ) {
326 373 $types = array(
327 - 'default_value' => array(
374 + 'default_value' => array(
328 375 'class' => '',
329 376 'icon' => 'frm_icon_font frm_text2_icon',
330 377 'title' => __( 'Default Value (Text)', 'formidable' ),
331 378 'data' => array(
@@ -331,9 +378,9 @@
331 378 'data' => array(
332 379 'frmshow' => '#default-value-for-',
333 380 ),
334 381 ),
335 - 'calc' => array(
382 + 'calc' => array(
336 383 'class' => 'frm_show_upgrade frm_noallow',
337 384 'title' => __( 'Default Value (Calculation)', 'formidable' ),
338 385 'icon' => 'frm_icon_font frm_calculator_icon',
339 386 'data' => array(
@@ -353,13 +400,8 @@
353 400 );
354 401
355 402 $types = apply_filters( 'frm_default_value_types', $types, $atts );
356 403
357 - if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
358 - // Prevent settings from showing in 2 spots.
359 - unset( $types['calc'], $types['get_values_field'] );
360 - }
361 -
362 404 // Set active class.
363 405 $settings = array_keys( $types );
364 406 $active = 'default_value';
365 407
@@ -374,8 +416,12 @@
374 416
375 417 return $types;
376 418 }
377 419
420 + /**
421 + * @param string $type
422 + * @return string
423 + */
378 424 public static function change_type( $type ) {
379 425 $type_switch = array(
380 426 'scale' => 'radio',
381 427 'star' => 'radio',
@@ -388,10 +434,13 @@
388 434 $type = $type_switch[ $type ];
389 435 }
390 436
391 437 $pro_fields = FrmField::pro_field_selection();
392 - $types = array_keys( $pro_fields );
393 - if ( in_array( $type, $types ) ) {
438 + // We want to keep credit_card types as credit card types for Stripe Lite.
439 + // The credit_card key is set for backward compatibility.
440 + unset( $pro_fields['credit_card'] );
441 +
442 + if ( array_key_exists( $type, $pro_fields ) ) {
394 443 $type = 'text';
395 444 }
396 445
397 446 return $type;
@@ -397,10 +446,10 @@
397 446 return $type;
398 447 }
399 448
400 449 /**
401 - * @param array $settings
402 - * @param object $field_info
450 + * @param array $settings
451 + * @param object|null $field_info
403 452 *
404 453 * @return array
405 454 */
406 455 public static function display_field_options( $settings, $field_info = null ) {
@@ -417,11 +466,20 @@
417 466 *
418 467 * @since 3.0
419 468 *
420 469 * @param array $field
470 + * @return void
421 471 */
422 472 public static function show_format_option( $field ) {
423 - 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';
424 482 }
425 483
426 484 public static function input_html( $field, $echo = true ) {
427 485 $class = array();
@@ -449,14 +507,19 @@
449 507
450 508 return $add_html;
451 509 }
452 510
511 + /**
512 + * @param array $field
513 + * @param array $class
514 + * @return void
515 + */
453 516 private static function add_input_classes( $field, array &$class ) {
454 - if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
517 + if ( ! empty( $field['input_class'] ) ) {
455 518 $class[] = $field['input_class'];
456 519 }
457 520
458 - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
521 + if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
459 522 return;
460 523 }
461 524
462 525 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -463,8 +526,13 @@
463 526 $class[] = 'auto_width';
464 527 }
465 528 }
466 529
530 + /**
531 + * @param array $field
532 + * @param array $add_html
533 + * @return void
534 + */
467 535 private static function add_html_size( $field, array &$add_html ) {
468 536 $size_fields = array(
469 537 'select',
470 538 'data',
@@ -473,9 +541,9 @@
473 541 'file',
474 542 'lookup',
475 543 );
476 544
477 - 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 ) ) {
478 546 return;
479 547 }
480 548
481 549 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -492,10 +560,15 @@
492 560
493 561 self::add_html_cols( $field, $add_html );
494 562 }
495 563
564 + /**
565 + * @param array $field
566 + * @param array $add_html
567 + * @return void
568 + */
496 569 private static function add_html_cols( $field, array &$add_html ) {
497 - if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
570 + if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
498 571 return;
499 572 }
500 573
501 574 // Convert to cols for textareas.
@@ -517,8 +590,13 @@
517 590
518 591 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
519 592 }
520 593
594 + /**
595 + * @param array $field
596 + * @param array $add_html
597 + * @return void
598 + */
521 599 private static function add_html_length( $field, array &$add_html ) {
522 600 // Check for max setting and if this field accepts maxlength.
523 601 $fields = array(
524 602 'textarea',
@@ -526,9 +604,9 @@
526 604 'hidden',
527 605 'file',
528 606 );
529 607
530 - 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 ) ) {
531 609 return;
532 610 }
533 611
534 612 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -538,8 +616,14 @@
538 616
539 617 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
540 618 }
541 619
620 + /**
621 + * @param array $field
622 + * @param array $add_html
623 + * @param array $class
624 + * @return void
625 + */
542 626 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
543 627 if ( $field['default_value'] != '' ) {
544 628 if ( is_array( $field['default_value'] ) ) {
545 629 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -553,21 +637,9 @@
553 637 // don't include a json placeholder
554 638 return;
555 639 }
556 640
557 - $frm_settings = FrmAppHelper::get_settings();
558 -
559 - if ( $frm_settings->use_html ) {
560 - self::add_placeholder_to_input( $field, $add_html );
561 - } else {
562 - self::add_frmval_to_input( $field, $add_html );
563 -
564 - $class[] = 'frm_toggle_default';
565 -
566 - if ( $field['value'] == $field['placeholder'] ) {
567 - $class[] = 'frm_default';
568 - }
569 - }
641 + self::add_placeholder_to_input( $field, $add_html );
570 642 }
571 643
572 644 /**
573 645 * Prepares field placeholder.
@@ -610,14 +682,31 @@
610 682 if ( empty( $placeholder ) ) {
611 683 $placeholder = self::get_default_value_from_name( $field );
612 684 }
613 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 +
614 696 if ( $placeholder !== '' ) {
615 - ?>
616 - <option value="">
617 - <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
618 - </option>
619 - <?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 );
620 709 return true;
621 710 }
622 711
623 712 return false;
@@ -623,12 +712,13 @@
623 712 return false;
624 713 }
625 714
626 715 /**
627 - * Use HMTL5 placeholder with js fallback
716 + * Use HTML5 placeholder with js fallback.
628 717 *
629 718 * @param array $field
630 719 * @param array $add_html
720 + * @return void
631 721 */
632 722 private static function add_placeholder_to_input( $field, &$add_html ) {
633 723 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
634 724 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -634,8 +724,13 @@
634 724 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
635 725 }
636 726 }
637 727
728 + /**
729 + * @param array $field
730 + * @param array $add_html
731 + * @return void
732 + */
638 733 private static function add_frmval_to_input( $field, &$add_html ) {
639 734 if ( $field['placeholder'] != '' ) {
640 735 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
641 736
@@ -649,15 +744,17 @@
649 744 }
650 745 }
651 746
652 747 private static function add_validation_messages( $field, array &$add_html ) {
653 - 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'] ) ) {
654 751 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
655 752 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
656 753 self::maybe_add_html_required( $field, $add_html );
657 754 }
658 755
659 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
756 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
660 757 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
661 758 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
662 759 }
663 760
@@ -666,12 +763,45 @@
666 763 }
667 764 }
668 765
669 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 + /**
670 799 * @since 5.0.03
671 800 *
672 801 * @param array $field
673 802 * @param array $add_html
803 + * @return void
674 804 */
675 805 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
676 806 $form = self::get_form_for_js_validation( $field );
677 807 if ( false === $form ) {
@@ -688,9 +818,9 @@
688 818 /**
689 819 * @since 5.0.03
690 820 *
691 821 * @param array $field
692 - * @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.
693 823 */
694 824 private static function get_form_for_js_validation( $field ) {
695 825 global $frm_vars;
696 826 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
@@ -707,9 +837,9 @@
707 837 /**
708 838 * @param stdClass $form
709 839 * @param array $field
710 840 * @param array $errors
711 - * @return string|false
841 + * @return false|string
712 842 */
713 843 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
714 844 if ( empty( $field['custom_html'] ) ) {
715 845 return false;
@@ -750,20 +880,30 @@
750 880 *
751 881 * @since 3.06.01
752 882 * @param array $field
753 883 * @param array $add_html
884 + * @return void
754 885 */
755 886 private static function maybe_add_html_required( $field, array &$add_html ) {
756 - if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) {
887 + $excluded_field_types =
888 + FrmField::is_radio( $field ) ||
889 + FrmField::is_checkbox( $field ) ||
890 + FrmField::is_field_type( $field, 'file' ) ||
891 + FrmField::is_field_type( $field, 'nps' ) ||
892 + FrmField::is_field_type( $field, 'scale' );
893 +
894 + if ( $excluded_field_types ) {
757 895 return;
758 896 }
759 897
760 - $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
761 - if ( $include_html ) {
762 - $add_html['aria-required'] = 'aria-required="true"';
763 - }
898 + $add_html['aria-required'] = 'aria-required="true"';
764 899 }
765 900
901 + /**
902 + * @param array $field
903 + * @param array $add_html
904 + * @return void
905 + */
766 906 private static function add_shortcodes_to_html( $field, array &$add_html ) {
767 907 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
768 908 return;
769 909 }
@@ -772,9 +912,9 @@
772 912 unset( $field['shortcodes']['autocomplete'] );
773 913 }
774 914
775 915 foreach ( $field['shortcodes'] as $k => $v ) {
776 - if ( 'opt' === $k ) {
916 + if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
777 917 continue;
778 918 }
779 919
780 920 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -789,28 +929,40 @@
789 929 }
790 930 }
791 931
792 932 /**
793 - * Add pattern attribute
933 + * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
794 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 + *
795 950 * @since 3.0
796 951 *
797 952 * @param array $field
798 953 * @param array $add_html
954 + * @return void
799 955 */
800 956 private static function add_pattern_attribute( $field, array &$add_html ) {
801 957 $has_format = FrmField::is_option_true_in_array( $field, 'format' );
802 958 $format_field = FrmField::is_field_type( $field, 'text' );
803 959
804 - if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
805 - $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 );
806 963
807 - if ( $frm_settings->use_html ) {
808 - $format = FrmEntryValidate::phone_format( $field );
809 - $format = substr( $format, 2, - 1 );
810 -
811 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
812 - }
964 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
813 965 }
814 966 }
815 967
816 968 public static function check_value( $opt, $opt_key, $field ) {
@@ -826,88 +978,10 @@
826 978 }
827 979
828 980 public static function check_label( $opt ) {
829 981 if ( is_array( $opt ) ) {
830 - $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
982 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
831 983 }
832 984
833 985 return $opt;
834 - }
835 -
836 - /**
837 - * @deprecated 4.0
838 - */
839 - public static function update_ajax_option() {
840 - _deprecated_function( __METHOD__, '4.0' );
841 - FrmAppHelper::permission_check( 'frm_edit_forms' );
842 - check_ajax_referer( 'frm_ajax', 'nonce' );
843 -
844 - $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
845 - if ( ! $field_id ) {
846 - wp_die();
847 - }
848 -
849 - $field = FrmField::getOne( $field_id );
850 -
851 - if ( isset( $_POST['separate_value'] ) ) {
852 - $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
853 -
854 - $field->field_options['separate_value'] = $new_val;
855 - unset( $new_val );
856 - }
857 -
858 - FrmField::update(
859 - $field_id,
860 - array(
861 - 'field_options' => $field->field_options,
862 - 'form_id' => $field->form_id,
863 - )
864 - );
865 - wp_die();
866 - }
867 -
868 - /**
869 - * @deprecated 4.0
870 - */
871 - public static function import_choices() {
872 - _deprecated_function( __METHOD__, '4.0' );
873 - wp_die();
874 - }
875 -
876 - /**
877 - * Add Single Option or Other Option.
878 - *
879 - * @deprecated 4.0 Moved to Pro for Other option only.
880 - */
881 - public static function add_option() {
882 - _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
883 - }
884 -
885 - /**
886 - * @deprecated 4.0
887 - */
888 - public static function update_order() {
889 - FrmDeprecated::update_order();
890 - }
891 -
892 - /**
893 - * @deprecated 3.0
894 - * @codeCoverageIgnore
895 - */
896 - public static function edit_name( $field = 'name', $id = '' ) {
897 - FrmDeprecated::edit_name( $field, $id );
898 - }
899 -
900 - /**
901 - * @deprecated 3.0
902 - * @codeCoverageIgnore
903 - *
904 - * @param int $field_id
905 - * @param array $values
906 - * @param int $form_id
907 - *
908 - * @return array
909 - */
910 - public static function include_single_field( $field_id, $values, $form_id = 0 ) {
911 - return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
912 986 }
913 987 }