PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.23
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.23
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 +276 -175 6.46.23 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
@@ -56,14 +63,15 @@
56 63 public static function create() {
57 64 FrmAppHelper::permission_check( 'frm_edit_forms' );
58 65 check_ajax_referer( 'frm_ajax', 'nonce' );
59 66
60 - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
61 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
67 + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
68 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
69 + $field_options = FrmAppHelper::get_post_param( 'field_options', array(), 'wp_kses_post' );
62 70
63 71 do_action( 'frm_before_create_field', $field_type, $form_id );
64 72
65 - $field = self::include_new_field( $field_type, $form_id );
73 + $field = self::include_new_field( $field_type, $form_id, $field_options );
66 74
67 75 // this hook will allow for multiple fields to be added at once
68 76 do_action( 'frm_after_field_created', $field, $form_id );
69 77
@@ -73,18 +81,29 @@
73 81 /**
74 82 * Set up and create a new field
75 83 *
76 84 * @param string $field_type
77 - * @param integer $form_id
85 + * @param int $form_id
86 + * @param array $field_options
78 87 *
79 - * @return array|bool
88 + * @return array|false
80 89 */
81 - public static function include_new_field( $field_type, $form_id ) {
90 + public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
82 91 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
92 +
93 + if ( ! empty( $field_options ) ) {
94 + $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
95 + }
96 +
97 + // When a new field is added to the form, flag it as draft and hide it from the front-end.
98 + $field_values['field_options']['draft'] = 1;
99 +
100 + /**
101 + * @param array $field_values
102 + */
83 103 $field_values = apply_filters( 'frm_before_field_created', $field_values );
104 + $field_id = FrmField::create( $field_values );
84 105
85 - $field_id = FrmField::create( $field_values );
86 -
87 106 if ( ! $field_id ) {
88 107 return false;
89 108 }
90 109
@@ -136,11 +155,11 @@
136 155
137 156 /**
138 157 * @since 3.0
139 158 *
140 - * @param int|array|object $field_object
141 - * @param array $values
142 - * @param int $form_id
159 + * @param array|int|object $field_object
160 + * @param array $values
161 + * @param int $form_id
143 162 */
144 163 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
145 164 global $frm_vars;
146 165 $frm_vars['is_admin'] = true;
@@ -154,30 +173,46 @@
154 173
155 174 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
156 175 $display = self::display_field_options( array(), $field_obj );
157 176
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' ) );
177 + $ajax_loading = ! empty( $values['ajax_load'] );
178 + $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
160 179
161 180 if ( $ajax_loading && $ajax_this_field ) {
162 181 $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;
182 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php';
183 + return;
184 + }
167 185
168 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
169 - }
186 + if ( ! isset( $field ) && is_object( $field_object ) ) {
187 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
188 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
189 + }
170 190
171 - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
172 - $li_classes .= ' ui-state-default widgets-holder-wrap';
191 + /**
192 + * Filter for adding extra attributes to the field container.
193 + *
194 + * @since 6.23
195 + *
196 + * @param array $extra_field_attributes
197 + * @param array $field
198 + * @param array $display
199 + */
200 + $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display );
173 201
174 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
175 - }
202 + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
203 + $li_classes .= ' ui-state-default widgets-holder-wrap';
204 +
205 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
176 206 }
177 207
178 208 /**
179 209 * @since 3.0
210 + *
211 + * @param array $field
212 + * @param array $display
213 + * @param FrmFieldType $field_info
214 + * @return string
180 215 */
181 216 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
182 217 $li_classes = $field_info->form_builder_classes( $display['type'] );
183 218 $li_classes .= ' frm_form_field frmstart ';
@@ -203,10 +238,11 @@
203 238 FrmField::destroy( $field_id );
204 239 wp_die();
205 240 }
206 241
207 - /* Field Options */
208 -
242 + /**
243 + * Field Options.
244 + */
209 245 public static function import_options() {
210 246 FrmAppHelper::permission_check( 'frm_edit_forms' );
211 247 check_ajax_referer( 'frm_ajax', 'nonce' );
212 248
@@ -213,12 +249,23 @@
213 249 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
214 250 return;
215 251 }
216 252
217 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
218 - $field = FrmField::getOne( $field_id );
253 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
254 + $field = FrmField::getOne( $field_id );
255 + $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
219 256
220 - if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
257 + /**
258 + * Filter to add new fields that will support import_options/Bulk Edit Options.
259 + *
260 + * @since 6.8.4
261 + *
262 + * @param array $bulk_edit_types
263 + * @return array
264 + */
265 + $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
266 +
267 + if ( ! in_array( $field->type, $bulk_edit_types, true ) ) {
221 268 return;
222 269 }
223 270
224 271 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -225,15 +272,15 @@
225 272 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
226 273 $opts = explode( "\n", rtrim( $opts, "\n" ) );
227 274 $opts = array_map( 'trim', $opts );
228 275
229 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
230 - $field['separate_value'] = ( $separate === 'true' );
276 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
277 + $field['separate_value'] = $separate === 'true';
231 278
232 279 if ( $field['separate_value'] ) {
233 280 foreach ( $opts as $opt_key => $opt ) {
234 281 if ( strpos( $opt, '|' ) !== false ) {
235 - $vals = explode( '|', $opt );
282 + $vals = explode( '|', $opt );
236 283 $opts[ $opt_key ] = array(
237 284 'label' => trim( $vals[0] ),
238 285 'value' => trim( $vals[1] ),
239 286 );
@@ -267,8 +314,9 @@
267 314 /**
268 315 * @since 4.0
269 316 *
270 317 * @param array $atts - Includes field array, field_obj, display array, values array.
318 + * @return void
271 319 */
272 320 public static function load_single_field_settings( $atts ) {
273 321 $field = $atts['field'];
274 322 $field_obj = $atts['field_obj'];
@@ -283,13 +331,13 @@
283 331 if ( ! isset( $field['read_only'] ) ) {
284 332 $field['read_only'] = false;
285 333 }
286 334
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();
335 + $field_selection_data = self::maybe_define_field_selection_data();
336 + $all_field_types = $field_selection_data->all_field_types;
337 + $disabled_fields = $field_selection_data->disabled_fields;
338 + $frm_settings = FrmAppHelper::get_settings();
339 + $field_types = FrmFieldTypeOptionData::get_field_types( $field['type'] );
292 340
293 341 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
294 342 // Add fallback for an add-on field type that has been deactivated.
295 343 $all_field_types[ $field['type'] ] = array(
@@ -312,20 +360,36 @@
312 360
313 361 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
314 362 $field['placeholder'] = implode( ', ', $field['placeholder'] );
315 363 }
316 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
364 +
365 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
317 366 }
318 367
319 368 /**
369 + * @since 6.9.1
370 + *
371 + * @return FrmFieldSelectionData
372 + */
373 + private static function maybe_define_field_selection_data() {
374 + if ( ! isset( self::$field_selection_data ) ) {
375 + self::$field_selection_data = new FrmFieldSelectionData();
376 + }
377 + return self::$field_selection_data;
378 + }
379 +
380 + /**
320 381 * Get the list of default value types that can be toggled in the builder.
321 382 *
322 383 * @since 4.0
384 + *
385 + * @param array $field
386 + * @param array $atts
323 387 * @return array
324 388 */
325 389 private static function default_value_types( $field, $atts ) {
326 390 $types = array(
327 - 'default_value' => array(
391 + 'default_value' => array(
328 392 'class' => '',
329 393 'icon' => 'frm_icon_font frm_text2_icon',
330 394 'title' => __( 'Default Value (Text)', 'formidable' ),
331 395 'data' => array(
@@ -331,9 +395,9 @@
331 395 'data' => array(
332 396 'frmshow' => '#default-value-for-',
333 397 ),
334 398 ),
335 - 'calc' => array(
399 + 'calc' => array(
336 400 'class' => 'frm_show_upgrade frm_noallow',
337 401 'title' => __( 'Default Value (Calculation)', 'formidable' ),
338 402 'icon' => 'frm_icon_font frm_calculator_icon',
339 403 'data' => array(
@@ -353,13 +417,8 @@
353 417 );
354 418
355 419 $types = apply_filters( 'frm_default_value_types', $types, $atts );
356 420
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 421 // Set active class.
363 422 $settings = array_keys( $types );
364 423 $active = 'default_value';
365 424
@@ -374,8 +433,12 @@
374 433
375 434 return $types;
376 435 }
377 436
437 + /**
438 + * @param string $type
439 + * @return string
440 + */
378 441 public static function change_type( $type ) {
379 442 $type_switch = array(
380 443 'scale' => 'radio',
381 444 'star' => 'radio',
@@ -388,10 +451,13 @@
388 451 $type = $type_switch[ $type ];
389 452 }
390 453
391 454 $pro_fields = FrmField::pro_field_selection();
392 - $types = array_keys( $pro_fields );
393 - if ( in_array( $type, $types ) ) {
455 + // We want to keep credit_card types as credit card types for Stripe Lite.
456 + // The credit_card key is set for backward compatibility.
457 + unset( $pro_fields['credit_card'] );
458 +
459 + if ( array_key_exists( $type, $pro_fields ) ) {
394 460 $type = 'text';
395 461 }
396 462
397 463 return $type;
@@ -397,16 +463,18 @@
397 463 return $type;
398 464 }
399 465
400 466 /**
401 - * @param array $settings
402 - * @param object $field_info
467 + * @param array $settings
468 + * @param FrmFieldType|null $field_info
403 469 *
404 470 * @return array
405 471 */
406 472 public static function display_field_options( $settings, $field_info = null ) {
407 473 if ( $field_info ) {
408 - $settings = $field_info->display_field_settings();
474 + $settings = $field_info->display_field_settings();
475 +
476 + // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
409 477 $settings['field_data'] = $field_info->field;
410 478 }
411 479
412 480 return apply_filters( 'frm_display_field_options', $settings );
@@ -416,12 +484,23 @@
416 484 * Display the format option
417 485 *
418 486 * @since 3.0
419 487 *
420 - * @param array $field
488 + * @param array $field Field data.
489 + * @param bool $is_hidden Whether the format option should be hidden.
490 + * @return void
421 491 */
422 - public static function show_format_option( $field ) {
423 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
492 + public static function show_format_option( $field, $is_hidden = false ) {
493 + $attributes = array(
494 + 'class' => 'frm-has-modal',
495 + 'id' => 'frm-field-format-custom-' . $field['id'],
496 + );
497 +
498 + if ( $is_hidden ) {
499 + $attributes['class'] .= ' frm_hidden';
500 + }
501 +
502 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
424 503 }
425 504
426 505 public static function input_html( $field, $echo = true ) {
427 506 $class = array();
@@ -449,14 +528,19 @@
449 528
450 529 return $add_html;
451 530 }
452 531
532 + /**
533 + * @param array $field
534 + * @param array $class
535 + * @return void
536 + */
453 537 private static function add_input_classes( $field, array &$class ) {
454 - if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
538 + if ( ! empty( $field['input_class'] ) ) {
455 539 $class[] = $field['input_class'];
456 540 }
457 541
458 - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
542 + if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
459 543 return;
460 544 }
461 545
462 546 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -463,8 +547,13 @@
463 547 $class[] = 'auto_width';
464 548 }
465 549 }
466 550
551 + /**
552 + * @param array $field
553 + * @param array $add_html
554 + * @return void
555 + */
467 556 private static function add_html_size( $field, array &$add_html ) {
468 557 $size_fields = array(
469 558 'select',
470 559 'data',
@@ -473,9 +562,9 @@
473 562 'file',
474 563 'lookup',
475 564 );
476 565
477 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
566 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
478 567 return;
479 568 }
480 569
481 570 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -492,10 +581,15 @@
492 581
493 582 self::add_html_cols( $field, $add_html );
494 583 }
495 584
585 + /**
586 + * @param array $field
587 + * @param array $add_html
588 + * @return void
589 + */
496 590 private static function add_html_cols( $field, array &$add_html ) {
497 - if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
591 + if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
498 592 return;
499 593 }
500 594
501 595 // Convert to cols for textareas.
@@ -517,8 +611,13 @@
517 611
518 612 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
519 613 }
520 614
615 + /**
616 + * @param array $field
617 + * @param array $add_html
618 + * @return void
619 + */
521 620 private static function add_html_length( $field, array &$add_html ) {
522 621 // Check for max setting and if this field accepts maxlength.
523 622 $fields = array(
524 623 'textarea',
@@ -526,9 +625,9 @@
526 625 'hidden',
527 626 'file',
528 627 );
529 628
530 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
629 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
531 630 return;
532 631 }
533 632
534 633 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -538,8 +637,14 @@
538 637
539 638 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
540 639 }
541 640
641 + /**
642 + * @param array $field
643 + * @param array $add_html
644 + * @param array $class
645 + * @return void
646 + */
542 647 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
543 648 if ( $field['default_value'] != '' ) {
544 649 if ( is_array( $field['default_value'] ) ) {
545 650 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -553,21 +658,9 @@
553 658 // don't include a json placeholder
554 659 return;
555 660 }
556 661
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 - }
662 + self::add_placeholder_to_input( $field, $add_html );
570 663 }
571 664
572 665 /**
573 666 * Prepares field placeholder.
@@ -610,14 +703,26 @@
610 703 if ( empty( $placeholder ) ) {
611 704 $placeholder = self::get_default_value_from_name( $field );
612 705 }
613 706
707 + $use_placeholder = $placeholder;
708 + $autocomplete = FrmField::get_option( $field, 'autocom' );
709 +
710 + if ( $autocomplete ) {
711 + $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
712 + if ( $use_chosen ) {
713 + $use_placeholder = '';
714 + }
715 + }
716 +
614 717 if ( $placeholder !== '' ) {
615 - ?>
616 - <option value="">
617 - <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
618 - </option>
619 - <?php
718 + $placeholder_attributes = array(
719 + 'class' => 'frm-select-placeholder',
720 + 'value' => '',
721 + 'data-placeholder' => 'true',
722 + );
723 +
724 + FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
620 725 return true;
621 726 }
622 727
623 728 return false;
@@ -623,12 +728,13 @@
623 728 return false;
624 729 }
625 730
626 731 /**
627 - * Use HMTL5 placeholder with js fallback
732 + * Use HTML5 placeholder with js fallback.
628 733 *
629 734 * @param array $field
630 735 * @param array $add_html
736 + * @return void
631 737 */
632 738 private static function add_placeholder_to_input( $field, &$add_html ) {
633 739 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
634 740 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -634,8 +740,13 @@
634 740 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
635 741 }
636 742 }
637 743
744 + /**
745 + * @param array $field
746 + * @param array $add_html
747 + * @return void
748 + */
638 749 private static function add_frmval_to_input( $field, &$add_html ) {
639 750 if ( $field['placeholder'] != '' ) {
640 751 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
641 752
@@ -649,15 +760,17 @@
649 760 }
650 761 }
651 762
652 763 private static function add_validation_messages( $field, array &$add_html ) {
653 - if ( FrmField::is_required( $field ) ) {
764 + $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
765 +
766 + if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
654 767 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
655 768 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
656 769 self::maybe_add_html_required( $field, $add_html );
657 770 }
658 771
659 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
772 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
660 773 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
661 774 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
662 775 }
663 776
@@ -666,12 +779,45 @@
666 779 }
667 780 }
668 781
669 782 /**
783 + * Returns an array that contains field validation messages status.
784 + *
785 + * @since 6.9
786 + *
787 + * @param array|object $field
788 + * @return array
789 + */
790 + private static function get_validation_data_attribute_visibility_info( $field ) {
791 + if ( FrmField::get_field_type( $field ) === 'hidden' ) {
792 + $field_validation_data_attributes = array(
793 + 'data-invmsg' => false,
794 + 'data-reqmsg' => false,
795 + );
796 + } else {
797 + $field_validation_data_attributes = array(
798 + 'data-invmsg' => true,
799 + 'data-reqmsg' => true,
800 + );
801 + }
802 +
803 + /**
804 + * Allows controlling which field validation messages would be included in the field html.
805 + *
806 + * @since 6.9
807 + *
808 + * @param array $field_validation_messages_status
809 + * @param array|object $field
810 + */
811 + return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
812 + }
813 +
814 + /**
670 815 * @since 5.0.03
671 816 *
672 817 * @param array $field
673 818 * @param array $add_html
819 + * @return void
674 820 */
675 821 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
676 822 $form = self::get_form_for_js_validation( $field );
677 823 if ( false === $form ) {
@@ -688,9 +834,9 @@
688 834 /**
689 835 * @since 5.0.03
690 836 *
691 837 * @param array $field
692 - * @return stdClass|false false if there is no form object found with JS validation active.
838 + * @return false|stdClass false if there is no form object found with JS validation active.
693 839 */
694 840 private static function get_form_for_js_validation( $field ) {
695 841 global $frm_vars;
696 842 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
@@ -707,9 +853,9 @@
707 853 /**
708 854 * @param stdClass $form
709 855 * @param array $field
710 856 * @param array $errors
711 - * @return string|false
857 + * @return false|string
712 858 */
713 859 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
714 860 if ( empty( $field['custom_html'] ) ) {
715 861 return false;
@@ -750,20 +896,30 @@
750 896 *
751 897 * @since 3.06.01
752 898 * @param array $field
753 899 * @param array $add_html
900 + * @return void
754 901 */
755 902 private static function maybe_add_html_required( $field, array &$add_html ) {
756 - if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) {
903 + $excluded_field_types =
904 + FrmField::is_radio( $field ) ||
905 + FrmField::is_checkbox( $field ) ||
906 + FrmField::is_field_type( $field, 'file' ) ||
907 + FrmField::is_field_type( $field, 'nps' ) ||
908 + FrmField::is_field_type( $field, 'scale' );
909 +
910 + if ( $excluded_field_types ) {
757 911 return;
758 912 }
759 913
760 - $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
761 - if ( $include_html ) {
762 - $add_html['aria-required'] = 'aria-required="true"';
763 - }
914 + $add_html['aria-required'] = 'aria-required="true"';
764 915 }
765 916
917 + /**
918 + * @param array $field
919 + * @param array $add_html
920 + * @return void
921 + */
766 922 private static function add_shortcodes_to_html( $field, array &$add_html ) {
767 923 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
768 924 return;
769 925 }
@@ -772,9 +928,19 @@
772 928 unset( $field['shortcodes']['autocomplete'] );
773 929 }
774 930
775 931 foreach ( $field['shortcodes'] as $k => $v ) {
776 - if ( 'opt' === $k ) {
932 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
933 + $subfield_name = $field['subfield_name'];
934 + if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
935 + continue;
936 + }
937 + // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
938 + $k = 'aria-invalid';
939 + $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
940 + unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
941 + }
942 + if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
777 943 continue;
778 944 }
779 945
780 946 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -785,32 +951,45 @@
785 951 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
786 952 }
787 953
788 954 unset( $k, $v );
955 + }//end foreach
956 + }
957 +
958 + /**
959 + * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
960 + *
961 + * @since 6.11.2
962 + *
963 + * @param string $key The option key.
964 + * @return bool
965 + */
966 + private static function should_allow_input_attribute( $key ) {
967 + if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
968 + return true;
789 969 }
970 + return FrmAppHelper::input_key_is_safe( $key );
790 971 }
791 972
792 973 /**
793 - * Add pattern attribute
974 + * Add pattern attribute.
794 975 *
795 976 * @since 3.0
796 977 *
797 978 * @param array $field
798 979 * @param array $add_html
980 + * @return void
799 981 */
800 982 private static function add_pattern_attribute( $field, array &$add_html ) {
801 - $has_format = FrmField::is_option_true_in_array( $field, 'format' );
983 + $format_value = FrmField::get_option( $field, 'format' );
984 + $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
802 985 $format_field = FrmField::is_field_type( $field, 'text' );
803 986
804 - if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
805 - $frm_settings = FrmAppHelper::get_settings();
987 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
988 + $format = FrmEntryValidate::phone_format( $field );
989 + $format = substr( $format, 2, - 1 );
806 990
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 - }
991 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
813 992 }
814 993 }
815 994
816 995 public static function check_value( $opt, $opt_key, $field ) {
@@ -826,88 +1005,10 @@
826 1005 }
827 1006
828 1007 public static function check_label( $opt ) {
829 1008 if ( is_array( $opt ) ) {
830 - $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1009 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
831 1010 }
832 1011
833 1012 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 1013 }
913 1014 }