PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.24
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.24
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 +271 -180 6.5.26.24 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,15 +81,23 @@
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 );
83 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 +
84 100 /**
85 101 * @param array $field_values
86 102 */
87 103 $field_values = apply_filters( 'frm_before_field_created', $field_values );
@@ -139,11 +155,11 @@
139 155
140 156 /**
141 157 * @since 3.0
142 158 *
143 - * @param int|array|object $field_object
144 - * @param array $values
145 - * @param int $form_id
159 + * @param array|int|object $field_object
160 + * @param array $values
161 + * @param int $form_id
146 162 */
147 163 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
148 164 global $frm_vars;
149 165 $frm_vars['is_admin'] = true;
@@ -157,30 +173,46 @@
157 173
158 174 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
159 175 $display = self::display_field_options( array(), $field_obj );
160 176
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' ) );
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 );
163 179
164 180 if ( $ajax_loading && $ajax_this_field ) {
165 181 $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;
182 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php';
183 + return;
184 + }
170 185
171 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
172 - }
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 + }
173 190
174 - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
175 - $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 );
176 201
177 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
178 - }
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';
179 206 }
180 207
181 208 /**
182 209 * @since 3.0
210 + *
211 + * @param array $field
212 + * @param array $display
213 + * @param FrmFieldType $field_info
214 + * @return string
183 215 */
184 216 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
185 217 $li_classes = $field_info->form_builder_classes( $display['type'] );
186 218 $li_classes .= ' frm_form_field frmstart ';
@@ -206,10 +238,11 @@
206 238 FrmField::destroy( $field_id );
207 239 wp_die();
208 240 }
209 241
210 - /* Field Options */
211 -
242 + /**
243 + * Field Options.
244 + */
212 245 public static function import_options() {
213 246 FrmAppHelper::permission_check( 'frm_edit_forms' );
214 247 check_ajax_referer( 'frm_ajax', 'nonce' );
215 248
@@ -216,12 +249,23 @@
216 249 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
217 250 return;
218 251 }
219 252
220 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
221 - $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' );
222 256
223 - 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 ) ) {
224 268 return;
225 269 }
226 270
227 271 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -228,15 +272,15 @@
228 272 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
229 273 $opts = explode( "\n", rtrim( $opts, "\n" ) );
230 274 $opts = array_map( 'trim', $opts );
231 275
232 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
233 - $field['separate_value'] = ( $separate === 'true' );
276 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
277 + $field['separate_value'] = $separate === 'true';
234 278
235 279 if ( $field['separate_value'] ) {
236 280 foreach ( $opts as $opt_key => $opt ) {
237 281 if ( strpos( $opt, '|' ) !== false ) {
238 - $vals = explode( '|', $opt );
282 + $vals = explode( '|', $opt );
239 283 $opts[ $opt_key ] = array(
240 284 'label' => trim( $vals[0] ),
241 285 'value' => trim( $vals[1] ),
242 286 );
@@ -270,8 +314,9 @@
270 314 /**
271 315 * @since 4.0
272 316 *
273 317 * @param array $atts - Includes field array, field_obj, display array, values array.
318 + * @return void
274 319 */
275 320 public static function load_single_field_settings( $atts ) {
276 321 $field = $atts['field'];
277 322 $field_obj = $atts['field_obj'];
@@ -286,13 +331,13 @@
286 331 if ( ! isset( $field['read_only'] ) ) {
287 332 $field['read_only'] = false;
288 333 }
289 334
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();
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'] );
295 340
296 341 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
297 342 // Add fallback for an add-on field type that has been deactivated.
298 343 $all_field_types[ $field['type'] ] = array(
@@ -320,57 +365,71 @@
320 365 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
321 366 }
322 367
323 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 + /**
324 381 * Get the list of default value types that can be toggled in the builder.
325 382 *
326 383 * @since 4.0
384 + *
385 + * @param array $field
386 + * @param array $atts
327 387 * @return array
328 388 */
329 389 private static function default_value_types( $field, $atts ) {
330 390 $types = array(
331 - 'default_value' => array(
391 + 'default_value' => array(
332 392 'class' => '',
333 393 'icon' => 'frm_icon_font frm_text2_icon',
334 - 'title' => __( 'Default Value (Text)', 'formidable' ),
394 + 'title' => __( 'Default Value', 'formidable' ),
335 395 'data' => array(
336 396 'frmshow' => '#default-value-for-',
337 397 ),
338 398 ),
339 - 'calc' => array(
340 - 'class' => 'frm_show_upgrade frm_noallow',
341 - 'title' => __( 'Default Value (Calculation)', 'formidable' ),
342 - 'icon' => 'frm_icon_font frm_calculator_icon',
343 - 'data' => array(
399 + 'calc' => array(
400 + 'class' => 'frm_show_upgrade frm_noallow',
401 + 'title' => __( 'Calculate Value', 'formidable' ),
402 + 'icon' => 'frm_icon_font frm_calculator_icon',
403 + 'data' => array(
344 404 'medium' => 'calculations',
345 405 'upgrade' => __( 'Calculator forms', 'formidable' ),
346 406 ),
407 + 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
347 408 ),
348 409 'get_values_field' => array(
349 - 'class' => 'frm_show_upgrade frm_noallow',
350 - 'title' => __( 'Default Value (Lookup)', 'formidable' ),
351 - 'icon' => 'frm_icon_font frm_search_icon',
352 - 'data' => array(
410 + 'class' => 'frm_show_upgrade frm_noallow',
411 + 'title' => __( 'Lookup', 'formidable' ),
412 + 'icon' => 'frm_icon_font frm_search_icon',
413 + 'data' => array(
353 414 'medium' => 'lookup',
354 415 'upgrade' => __( 'Lookup fields', 'formidable' ),
355 416 ),
417 + 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
356 418 ),
357 419 );
358 420
359 421 $types = apply_filters( 'frm_default_value_types', $types, $atts );
360 422
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 423 // Set active class.
367 424 $settings = array_keys( $types );
368 425 $active = 'default_value';
369 426
370 - foreach ( $settings as $type ) {
371 - if ( ! empty( $field[ $type ] ) ) {
372 - $active = $type;
427 + if ( FrmAppHelper::pro_is_connected() ) {
428 + foreach ( $settings as $type ) {
429 + if ( ! empty( $field[ $type ] ) ) {
430 + $active = $type;
431 + }
373 432 }
374 433 }
375 434
376 435 $types[ $active ]['class'] .= ' current';
@@ -378,8 +437,12 @@
378 437
379 438 return $types;
380 439 }
381 440
441 + /**
442 + * @param string $type
443 + * @return string
444 + */
382 445 public static function change_type( $type ) {
383 446 $type_switch = array(
384 447 'scale' => 'radio',
385 448 'star' => 'radio',
@@ -404,16 +467,18 @@
404 467 return $type;
405 468 }
406 469
407 470 /**
408 - * @param array $settings
409 - * @param object $field_info
471 + * @param array $settings
472 + * @param FrmFieldType|null $field_info
410 473 *
411 474 * @return array
412 475 */
413 476 public static function display_field_options( $settings, $field_info = null ) {
414 477 if ( $field_info ) {
415 - $settings = $field_info->display_field_settings();
478 + $settings = $field_info->display_field_settings();
479 +
480 + // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
416 481 $settings['field_data'] = $field_info->field;
417 482 }
418 483
419 484 return apply_filters( 'frm_display_field_options', $settings );
@@ -423,12 +488,23 @@
423 488 * Display the format option
424 489 *
425 490 * @since 3.0
426 491 *
427 - * @param array $field
492 + * @param array $field Field data.
493 + * @param bool $is_hidden Whether the format option should be hidden.
494 + * @return void
428 495 */
429 - public static function show_format_option( $field ) {
430 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
496 + public static function show_format_option( $field, $is_hidden = false ) {
497 + $attributes = array(
498 + 'class' => 'frm-has-modal',
499 + 'id' => 'frm-field-format-custom-' . $field['id'],
500 + );
501 +
502 + if ( $is_hidden ) {
503 + $attributes['class'] .= ' frm_hidden';
504 + }
505 +
506 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
431 507 }
432 508
433 509 public static function input_html( $field, $echo = true ) {
434 510 $class = array();
@@ -456,14 +532,19 @@
456 532
457 533 return $add_html;
458 534 }
459 535
536 + /**
537 + * @param array $field
538 + * @param array $class
539 + * @return void
540 + */
460 541 private static function add_input_classes( $field, array &$class ) {
461 - if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
542 + if ( ! empty( $field['input_class'] ) ) {
462 543 $class[] = $field['input_class'];
463 544 }
464 545
465 - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
546 + if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
466 547 return;
467 548 }
468 549
469 550 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -470,8 +551,13 @@
470 551 $class[] = 'auto_width';
471 552 }
472 553 }
473 554
555 + /**
556 + * @param array $field
557 + * @param array $add_html
558 + * @return void
559 + */
474 560 private static function add_html_size( $field, array &$add_html ) {
475 561 $size_fields = array(
476 562 'select',
477 563 'data',
@@ -480,9 +566,9 @@
480 566 'file',
481 567 'lookup',
482 568 );
483 569
484 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
570 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
485 571 return;
486 572 }
487 573
488 574 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -499,8 +585,13 @@
499 585
500 586 self::add_html_cols( $field, $add_html );
501 587 }
502 588
589 + /**
590 + * @param array $field
591 + * @param array $add_html
592 + * @return void
593 + */
503 594 private static function add_html_cols( $field, array &$add_html ) {
504 595 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
505 596 return;
506 597 }
@@ -524,8 +615,13 @@
524 615
525 616 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
526 617 }
527 618
619 + /**
620 + * @param array $field
621 + * @param array $add_html
622 + * @return void
623 + */
528 624 private static function add_html_length( $field, array &$add_html ) {
529 625 // Check for max setting and if this field accepts maxlength.
530 626 $fields = array(
531 627 'textarea',
@@ -533,9 +629,9 @@
533 629 'hidden',
534 630 'file',
535 631 );
536 632
537 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
633 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
538 634 return;
539 635 }
540 636
541 637 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -545,8 +641,14 @@
545 641
546 642 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
547 643 }
548 644
645 + /**
646 + * @param array $field
647 + * @param array $add_html
648 + * @param array $class
649 + * @return void
650 + */
549 651 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
550 652 if ( $field['default_value'] != '' ) {
551 653 if ( is_array( $field['default_value'] ) ) {
552 654 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -560,21 +662,9 @@
560 662 // don't include a json placeholder
561 663 return;
562 664 }
563 665
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 - }
666 + self::add_placeholder_to_input( $field, $add_html );
577 667 }
578 668
579 669 /**
580 670 * Prepares field placeholder.
@@ -617,14 +707,26 @@
617 707 if ( empty( $placeholder ) ) {
618 708 $placeholder = self::get_default_value_from_name( $field );
619 709 }
620 710
711 + $use_placeholder = $placeholder;
712 + $autocomplete = FrmField::get_option( $field, 'autocom' );
713 +
714 + if ( $autocomplete ) {
715 + $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
716 + if ( $use_chosen ) {
717 + $use_placeholder = '';
718 + }
719 + }
720 +
621 721 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
722 + $placeholder_attributes = array(
723 + 'class' => 'frm-select-placeholder',
724 + 'value' => '',
725 + 'data-placeholder' => 'true',
726 + );
727 +
728 + FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
627 729 return true;
628 730 }
629 731
630 732 return false;
@@ -630,12 +732,13 @@
630 732 return false;
631 733 }
632 734
633 735 /**
634 - * Use HMTL5 placeholder with js fallback
736 + * Use HTML5 placeholder with js fallback.
635 737 *
636 738 * @param array $field
637 739 * @param array $add_html
740 + * @return void
638 741 */
639 742 private static function add_placeholder_to_input( $field, &$add_html ) {
640 743 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
641 744 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -641,8 +744,13 @@
641 744 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
642 745 }
643 746 }
644 747
748 + /**
749 + * @param array $field
750 + * @param array $add_html
751 + * @return void
752 + */
645 753 private static function add_frmval_to_input( $field, &$add_html ) {
646 754 if ( $field['placeholder'] != '' ) {
647 755 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
648 756
@@ -656,15 +764,17 @@
656 764 }
657 765 }
658 766
659 767 private static function add_validation_messages( $field, array &$add_html ) {
660 - if ( FrmField::is_required( $field ) ) {
768 + $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
769 +
770 + if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
661 771 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
662 772 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
663 773 self::maybe_add_html_required( $field, $add_html );
664 774 }
665 775
666 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
776 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
667 777 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
668 778 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
669 779 }
670 780
@@ -673,12 +783,45 @@
673 783 }
674 784 }
675 785
676 786 /**
787 + * Returns an array that contains field validation messages status.
788 + *
789 + * @since 6.9
790 + *
791 + * @param array|object $field
792 + * @return array
793 + */
794 + private static function get_validation_data_attribute_visibility_info( $field ) {
795 + if ( FrmField::get_field_type( $field ) === 'hidden' ) {
796 + $field_validation_data_attributes = array(
797 + 'data-invmsg' => false,
798 + 'data-reqmsg' => false,
799 + );
800 + } else {
801 + $field_validation_data_attributes = array(
802 + 'data-invmsg' => true,
803 + 'data-reqmsg' => true,
804 + );
805 + }
806 +
807 + /**
808 + * Allows controlling which field validation messages would be included in the field html.
809 + *
810 + * @since 6.9
811 + *
812 + * @param array $field_validation_messages_status
813 + * @param array|object $field
814 + */
815 + return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
816 + }
817 +
818 + /**
677 819 * @since 5.0.03
678 820 *
679 821 * @param array $field
680 822 * @param array $add_html
823 + * @return void
681 824 */
682 825 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
683 826 $form = self::get_form_for_js_validation( $field );
684 827 if ( false === $form ) {
@@ -695,9 +838,9 @@
695 838 /**
696 839 * @since 5.0.03
697 840 *
698 841 * @param array $field
699 - * @return stdClass|false false if there is no form object found with JS validation active.
842 + * @return false|stdClass false if there is no form object found with JS validation active.
700 843 */
701 844 private static function get_form_for_js_validation( $field ) {
702 845 global $frm_vars;
703 846 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
@@ -714,9 +857,9 @@
714 857 /**
715 858 * @param stdClass $form
716 859 * @param array $field
717 860 * @param array $errors
718 - * @return string|false
861 + * @return false|string
719 862 */
720 863 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
721 864 if ( empty( $field['custom_html'] ) ) {
722 865 return false;
@@ -757,8 +900,9 @@
757 900 *
758 901 * @since 3.06.01
759 902 * @param array $field
760 903 * @param array $add_html
904 + * @return void
761 905 */
762 906 private static function maybe_add_html_required( $field, array &$add_html ) {
763 907 $excluded_field_types =
764 908 FrmField::is_radio( $field ) ||
@@ -770,14 +914,16 @@
770 914 if ( $excluded_field_types ) {
771 915 return;
772 916 }
773 917
774 - $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
775 - if ( $include_html ) {
776 - $add_html['aria-required'] = 'aria-required="true"';
777 - }
918 + $add_html['aria-required'] = 'aria-required="true"';
778 919 }
779 920
921 + /**
922 + * @param array $field
923 + * @param array $add_html
924 + * @return void
925 + */
780 926 private static function add_shortcodes_to_html( $field, array &$add_html ) {
781 927 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
782 928 return;
783 929 }
@@ -786,9 +932,19 @@
786 932 unset( $field['shortcodes']['autocomplete'] );
787 933 }
788 934
789 935 foreach ( $field['shortcodes'] as $k => $v ) {
790 - if ( 'opt' === $k ) {
936 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
937 + $subfield_name = $field['subfield_name'];
938 + if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
939 + continue;
940 + }
941 + // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
942 + $k = 'aria-invalid';
943 + $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
944 + unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
945 + }
946 + if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
791 947 continue;
792 948 }
793 949
794 950 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -799,32 +955,45 @@
799 955 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
800 956 }
801 957
802 958 unset( $k, $v );
959 + }//end foreach
960 + }
961 +
962 + /**
963 + * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
964 + *
965 + * @since 6.11.2
966 + *
967 + * @param string $key The option key.
968 + * @return bool
969 + */
970 + private static function should_allow_input_attribute( $key ) {
971 + if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
972 + return true;
803 973 }
974 + return FrmAppHelper::input_key_is_safe( $key );
804 975 }
805 976
806 977 /**
807 - * Add pattern attribute
978 + * Add pattern attribute.
808 979 *
809 980 * @since 3.0
810 981 *
811 982 * @param array $field
812 983 * @param array $add_html
984 + * @return void
813 985 */
814 986 private static function add_pattern_attribute( $field, array &$add_html ) {
815 - $has_format = FrmField::is_option_true_in_array( $field, 'format' );
987 + $format_value = FrmField::get_option( $field, 'format' );
988 + $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
816 989 $format_field = FrmField::is_field_type( $field, 'text' );
817 990
818 - if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
819 - $frm_settings = FrmAppHelper::get_settings();
991 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
992 + $format = FrmEntryValidate::phone_format( $field );
993 + $format = substr( $format, 2, - 1 );
820 994
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 - }
995 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
827 996 }
828 997 }
829 998
830 999 public static function check_value( $opt, $opt_key, $field ) {
@@ -840,88 +1009,10 @@
840 1009 }
841 1010
842 1011 public static function check_label( $opt ) {
843 1012 if ( is_array( $opt ) ) {
844 - $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1013 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
845 1014 }
846 1015
847 1016 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 1017 }
927 1018 }