PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7.2
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 +180 -270 6.256.7.2 View file →
@@ -4,15 +4,8 @@
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 -
15 8 public static function load_field() {
16 9 FrmAppHelper::permission_check( 'frm_edit_forms' );
17 10 check_ajax_referer( 'frm_ajax', 'nonce' );
18 11
@@ -63,15 +56,14 @@
63 56 public static function create() {
64 57 FrmAppHelper::permission_check( 'frm_edit_forms' );
65 58 check_ajax_referer( 'frm_ajax', 'nonce' );
66 59
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' );
60 + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
61 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
70 62
71 63 do_action( 'frm_before_create_field', $field_type, $form_id );
72 64
73 - $field = self::include_new_field( $field_type, $form_id, $field_options );
65 + $field = self::include_new_field( $field_type, $form_id );
74 66
75 67 // this hook will allow for multiple fields to be added at once
76 68 do_action( 'frm_after_field_created', $field, $form_id );
77 69
@@ -80,24 +72,16 @@
80 72
81 73 /**
82 74 * Set up and create a new field
83 75 *
84 - * @param string $field_type
85 - * @param int $form_id
86 - * @param array $field_options
76 + * @param string $field_type
77 + * @param integer $form_id
87 78 *
88 - * @return array|false
79 + * @return array|bool
89 80 */
90 - public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
81 + public static function include_new_field( $field_type, $form_id ) {
91 82 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
92 83
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 84 /**
101 85 * @param array $field_values
102 86 */
103 87 $field_values = apply_filters( 'frm_before_field_created', $field_values );
@@ -155,9 +139,9 @@
155 139
156 140 /**
157 141 * @since 3.0
158 142 *
159 - * @param array|int|object $field_object
143 + * @param int|array|object $field_object
160 144 * @param array $values
161 145 * @param int $form_id
162 146 */
163 147 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
@@ -173,46 +157,30 @@
173 157
174 158 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
175 159 $display = self::display_field_options( array(), $field_obj );
176 160
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 );
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' ) );
179 163
180 164 if ( $ajax_loading && $ajax_this_field ) {
181 165 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
182 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php';
183 - return;
184 - }
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;
185 170
186 - if ( ! isset( $field ) && is_object( $field_object ) ) {
187 - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id;
188 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
189 - }
171 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
172 + }
190 173
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 );
174 + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
175 + $li_classes .= ' ui-state-default widgets-holder-wrap';
201 176
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';
177 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
178 + }
206 179 }
207 180
208 181 /**
209 182 * @since 3.0
210 - *
211 - * @param array $field
212 - * @param array $display
213 - * @param FrmFieldType $field_info
214 - * @return string
215 183 */
216 184 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
217 185 $li_classes = $field_info->form_builder_classes( $display['type'] );
218 186 $li_classes .= ' frm_form_field frmstart ';
@@ -249,23 +217,12 @@
249 217 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
250 218 return;
251 219 }
252 220
253 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
254 - $field = FrmField::getOne( $field_id );
255 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
221 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
222 + $field = FrmField::getOne( $field_id );
256 223
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 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
268 225 return;
269 226 }
270 227
271 228 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -272,15 +229,15 @@
272 229 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
273 230 $opts = explode( "\n", rtrim( $opts, "\n" ) );
274 231 $opts = array_map( 'trim', $opts );
275 232
276 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
277 - $field['separate_value'] = $separate === 'true';
233 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
234 + $field['separate_value'] = ( $separate === 'true' );
278 235
279 236 if ( $field['separate_value'] ) {
280 237 foreach ( $opts as $opt_key => $opt ) {
281 238 if ( strpos( $opt, '|' ) !== false ) {
282 - $vals = explode( '|', $opt );
239 + $vals = explode( '|', $opt );
283 240 $opts[ $opt_key ] = array(
284 241 'label' => trim( $vals[0] ),
285 242 'value' => trim( $vals[1] ),
286 243 );
@@ -314,9 +271,8 @@
314 271 /**
315 272 * @since 4.0
316 273 *
317 274 * @param array $atts - Includes field array, field_obj, display array, values array.
318 - * @return void
319 275 */
320 276 public static function load_single_field_settings( $atts ) {
321 277 $field = $atts['field'];
322 278 $field_obj = $atts['field_obj'];
@@ -331,13 +287,13 @@
331 287 if ( ! isset( $field['read_only'] ) ) {
332 288 $field['read_only'] = false;
333 289 }
334 290
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'] );
291 + $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
292 + $pro_field_selection = FrmField::pro_field_selection();
293 + $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
294 + $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
295 + $frm_settings = FrmAppHelper::get_settings();
340 296
341 297 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
342 298 // Add fallback for an add-on field type that has been deactivated.
343 299 $all_field_types[ $field['type'] ] = array(
@@ -365,71 +321,57 @@
365 321 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
366 322 }
367 323
368 324 /**
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 - /**
381 325 * Get the list of default value types that can be toggled in the builder.
382 326 *
383 327 * @since 4.0
384 - *
385 - * @param array $field
386 - * @param array $atts
387 328 * @return array
388 329 */
389 330 private static function default_value_types( $field, $atts ) {
390 331 $types = array(
391 - 'default_value' => array(
332 + 'default_value' => array(
392 333 'class' => '',
393 334 'icon' => 'frm_icon_font frm_text2_icon',
394 - 'title' => __( 'Default Value', 'formidable' ),
335 + 'title' => __( 'Default Value (Text)', 'formidable' ),
395 336 'data' => array(
396 337 'frmshow' => '#default-value-for-',
397 338 ),
398 339 ),
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(
340 + 'calc' => array(
341 + 'class' => 'frm_show_upgrade frm_noallow',
342 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
343 + 'icon' => 'frm_icon_font frm_calculator_icon',
344 + 'data' => array(
404 345 'medium' => 'calculations',
405 346 'upgrade' => __( 'Calculator forms', 'formidable' ),
406 347 ),
407 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
408 348 ),
409 349 'get_values_field' => array(
410 - 'class' => 'frm_show_upgrade frm_noallow',
411 - 'title' => __( 'Lookup', 'formidable' ),
412 - 'icon' => 'frm_icon_font frm_search_icon',
413 - 'data' => array(
350 + 'class' => 'frm_show_upgrade frm_noallow',
351 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
352 + 'icon' => 'frm_icon_font frm_search_icon',
353 + 'data' => array(
414 354 'medium' => 'lookup',
415 355 'upgrade' => __( 'Lookup fields', 'formidable' ),
416 356 ),
417 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
418 357 ),
419 358 );
420 359
421 360 $types = apply_filters( 'frm_default_value_types', $types, $atts );
422 361
362 + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
363 + // Prevent settings from showing in 2 spots.
364 + unset( $types['calc'], $types['get_values_field'] );
365 + }
366 +
423 367 // Set active class.
424 368 $settings = array_keys( $types );
425 369 $active = 'default_value';
426 370
427 - if ( FrmAppHelper::pro_is_connected() ) {
428 - foreach ( $settings as $type ) {
429 - if ( ! empty( $field[ $type ] ) ) {
430 - $active = $type;
431 - }
371 + foreach ( $settings as $type ) {
372 + if ( ! empty( $field[ $type ] ) ) {
373 + $active = $type;
432 374 }
433 375 }
434 376
435 377 $types[ $active ]['class'] .= ' current';
@@ -437,12 +379,8 @@
437 379
438 380 return $types;
439 381 }
440 382
441 - /**
442 - * @param string $type
443 - * @return string
444 - */
445 383 public static function change_type( $type ) {
446 384 $type_switch = array(
447 385 'scale' => 'radio',
448 386 'star' => 'radio',
@@ -467,18 +405,16 @@
467 405 return $type;
468 406 }
469 407
470 408 /**
471 - * @param array $settings
472 - * @param FrmFieldType|null $field_info
409 + * @param array $settings
410 + * @param object $field_info
473 411 *
474 412 * @return array
475 413 */
476 414 public static function display_field_options( $settings, $field_info = null ) {
477 415 if ( $field_info ) {
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 + $settings = $field_info->display_field_settings();
481 417 $settings['field_data'] = $field_info->field;
482 418 }
483 419
484 420 return apply_filters( 'frm_display_field_options', $settings );
@@ -488,23 +424,12 @@
488 424 * Display the format option
489 425 *
490 426 * @since 3.0
491 427 *
492 - * @param array $field Field data.
493 - * @param bool $is_hidden Whether the format option should be hidden.
494 - * @return void
428 + * @param array $field
495 429 */
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';
430 + public static function show_format_option( $field ) {
431 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
507 432 }
508 433
509 434 public static function input_html( $field, $echo = true ) {
510 435 $class = array();
@@ -532,19 +457,14 @@
532 457
533 458 return $add_html;
534 459 }
535 460
536 - /**
537 - * @param array $field
538 - * @param array $class
539 - * @return void
540 - */
541 461 private static function add_input_classes( $field, array &$class ) {
542 - if ( ! empty( $field['input_class'] ) ) {
462 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
543 463 $class[] = $field['input_class'];
544 464 }
545 465
546 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
466 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
547 467 return;
548 468 }
549 469
550 470 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -551,13 +471,8 @@
551 471 $class[] = 'auto_width';
552 472 }
553 473 }
554 474
555 - /**
556 - * @param array $field
557 - * @param array $add_html
558 - * @return void
559 - */
560 475 private static function add_html_size( $field, array &$add_html ) {
561 476 $size_fields = array(
562 477 'select',
563 478 'data',
@@ -566,9 +481,9 @@
566 481 'file',
567 482 'lookup',
568 483 );
569 484
570 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
485 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
571 486 return;
572 487 }
573 488
574 489 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -585,13 +500,8 @@
585 500
586 501 self::add_html_cols( $field, $add_html );
587 502 }
588 503
589 - /**
590 - * @param array $field
591 - * @param array $add_html
592 - * @return void
593 - */
594 504 private static function add_html_cols( $field, array &$add_html ) {
595 505 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
596 506 return;
597 507 }
@@ -615,13 +525,8 @@
615 525
616 526 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
617 527 }
618 528
619 - /**
620 - * @param array $field
621 - * @param array $add_html
622 - * @return void
623 - */
624 529 private static function add_html_length( $field, array &$add_html ) {
625 530 // Check for max setting and if this field accepts maxlength.
626 531 $fields = array(
627 532 'textarea',
@@ -629,9 +534,9 @@
629 534 'hidden',
630 535 'file',
631 536 );
632 537
633 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
538 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
634 539 return;
635 540 }
636 541
637 542 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -641,14 +546,8 @@
641 546
642 547 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
643 548 }
644 549
645 - /**
646 - * @param array $field
647 - * @param array $add_html
648 - * @param array $class
649 - * @return void
650 - */
651 550 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
652 551 if ( $field['default_value'] != '' ) {
653 552 if ( is_array( $field['default_value'] ) ) {
654 553 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -662,9 +561,21 @@
662 561 // don't include a json placeholder
663 562 return;
664 563 }
665 564
666 - self::add_placeholder_to_input( $field, $add_html );
565 + $frm_settings = FrmAppHelper::get_settings();
566 +
567 + if ( $frm_settings->use_html ) {
568 + self::add_placeholder_to_input( $field, $add_html );
569 + } else {
570 + self::add_frmval_to_input( $field, $add_html );
571 +
572 + $class[] = 'frm_toggle_default';
573 +
574 + if ( $field['value'] == $field['placeholder'] ) {
575 + $class[] = 'frm_default';
576 + }
577 + }
667 578 }
668 579
669 580 /**
670 581 * Prepares field placeholder.
@@ -674,9 +585,9 @@
674 585 * @param array $field Field array.
675 586 * @return string
676 587 */
677 588 private static function prepare_placeholder( $field ) {
678 - $placeholder = $field['placeholder'] ?? '';
589 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
679 590
680 591 return $placeholder;
681 592 }
682 593
@@ -707,26 +618,14 @@
707 618 if ( empty( $placeholder ) ) {
708 619 $placeholder = self::get_default_value_from_name( $field );
709 620 }
710 621
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 -
721 622 if ( $placeholder !== '' ) {
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 );
623 + ?>
624 + <option class="frm-select-placeholder" value="">
625 + <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
626 + </option>
627 + <?php
729 628 return true;
730 629 }
731 630
732 631 return false;
@@ -732,13 +631,12 @@
732 631 return false;
733 632 }
734 633
735 634 /**
736 - * Use HTML5 placeholder with js fallback.
635 + * Use HMTL5 placeholder with js fallback
737 636 *
738 637 * @param array $field
739 638 * @param array $add_html
740 - * @return void
741 639 */
742 640 private static function add_placeholder_to_input( $field, &$add_html ) {
743 641 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
744 642 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -744,13 +642,8 @@
744 642 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
745 643 }
746 644 }
747 645
748 - /**
749 - * @param array $field
750 - * @param array $add_html
751 - * @return void
752 - */
753 646 private static function add_frmval_to_input( $field, &$add_html ) {
754 647 if ( $field['placeholder'] != '' ) {
755 648 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
756 649
@@ -764,17 +657,15 @@
764 657 }
765 658 }
766 659
767 660 private static function add_validation_messages( $field, array &$add_html ) {
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 + if ( FrmField::is_required( $field ) ) {
771 662 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
772 663 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
773 664 self::maybe_add_html_required( $field, $add_html );
774 665 }
775 666
776 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
667 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
777 668 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
778 669 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
779 670 }
780 671
@@ -783,45 +674,12 @@
783 674 }
784 675 }
785 676
786 677 /**
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 - /**
819 678 * @since 5.0.03
820 679 *
821 680 * @param array $field
822 681 * @param array $add_html
823 - * @return void
824 682 */
825 683 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
826 684 $form = self::get_form_for_js_validation( $field );
827 685 if ( false === $form ) {
@@ -838,9 +696,9 @@
838 696 /**
839 697 * @since 5.0.03
840 698 *
841 699 * @param array $field
842 - * @return false|stdClass false if there is no form object found with JS validation active.
700 + * @return stdClass|false false if there is no form object found with JS validation active.
843 701 */
844 702 private static function get_form_for_js_validation( $field ) {
845 703 global $frm_vars;
846 704 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
@@ -857,9 +715,9 @@
857 715 /**
858 716 * @param stdClass $form
859 717 * @param array $field
860 718 * @param array $errors
861 - * @return false|string
719 + * @return string|false
862 720 */
863 721 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
864 722 if ( empty( $field['custom_html'] ) ) {
865 723 return false;
@@ -900,9 +758,8 @@
900 758 *
901 759 * @since 3.06.01
902 760 * @param array $field
903 761 * @param array $add_html
904 - * @return void
905 762 */
906 763 private static function maybe_add_html_required( $field, array &$add_html ) {
907 764 $excluded_field_types =
908 765 FrmField::is_radio( $field ) ||
@@ -914,16 +771,14 @@
914 771 if ( $excluded_field_types ) {
915 772 return;
916 773 }
917 774
918 - $add_html['aria-required'] = 'aria-required="true"';
775 + $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
776 + if ( $include_html ) {
777 + $add_html['aria-required'] = 'aria-required="true"';
778 + }
919 779 }
920 780
921 - /**
922 - * @param array $field
923 - * @param array $add_html
924 - * @return void
925 - */
926 781 private static function add_shortcodes_to_html( $field, array &$add_html ) {
927 782 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
928 783 return;
929 784 }
@@ -932,19 +787,9 @@
932 787 unset( $field['shortcodes']['autocomplete'] );
933 788 }
934 789
935 790 foreach ( $field['shortcodes'] as $k => $v ) {
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 + if ( 'opt' === $k ) {
947 792 continue;
948 793 }
949 794
950 795 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -955,45 +800,32 @@
955 800 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
956 801 }
957 802
958 803 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;
973 804 }
974 - return FrmAppHelper::input_key_is_safe( $key );
975 805 }
976 806
977 807 /**
978 - * Add pattern attribute.
808 + * Add pattern attribute
979 809 *
980 810 * @since 3.0
981 811 *
982 812 * @param array $field
983 813 * @param array $add_html
984 - * @return void
985 814 */
986 815 private static function add_pattern_attribute( $field, array &$add_html ) {
987 - $format_value = FrmField::get_option( $field, 'format' );
988 - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
816 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
989 817 $format_field = FrmField::is_field_type( $field, 'text' );
990 818
991 - if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
992 - $format = FrmEntryValidate::phone_format( $field );
993 - $format = substr( $format, 2, - 1 );
819 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
820 + $frm_settings = FrmAppHelper::get_settings();
994 821
995 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
822 + if ( $frm_settings->use_html ) {
823 + $format = FrmEntryValidate::phone_format( $field );
824 + $format = substr( $format, 2, - 1 );
825 +
826 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
827 + }
996 828 }
997 829 }
998 830
999 831 public static function check_value( $opt, $opt_key, $field ) {
@@ -998,11 +830,11 @@
998 830
999 831 public static function check_value( $opt, $opt_key, $field ) {
1000 832 if ( is_array( $opt ) ) {
1001 833 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1002 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
834 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1003 835 } else {
1004 - $opt = $opt['label'] ?? reset( $opt );
836 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1005 837 }
1006 838 }
1007 839
1008 840 return $opt;
@@ -1009,10 +841,88 @@
1009 841 }
1010 842
1011 843 public static function check_label( $opt ) {
1012 844 if ( is_array( $opt ) ) {
1013 - $opt = $opt['label'] ?? reset( $opt );
845 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1014 846 }
1015 847
1016 848 return $opt;
849 + }
850 +
851 + /**
852 + * @deprecated 4.0
853 + */
854 + public static function update_ajax_option() {
855 + _deprecated_function( __METHOD__, '4.0' );
856 + FrmAppHelper::permission_check( 'frm_edit_forms' );
857 + check_ajax_referer( 'frm_ajax', 'nonce' );
858 +
859 + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
860 + if ( ! $field_id ) {
861 + wp_die();
862 + }
863 +
864 + $field = FrmField::getOne( $field_id );
865 +
866 + if ( isset( $_POST['separate_value'] ) ) {
867 + $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
868 +
869 + $field->field_options['separate_value'] = $new_val;
870 + unset( $new_val );
871 + }
872 +
873 + FrmField::update(
874 + $field_id,
875 + array(
876 + 'field_options' => $field->field_options,
877 + 'form_id' => $field->form_id,
878 + )
879 + );
880 + wp_die();
881 + }
882 +
883 + /**
884 + * @deprecated 4.0
885 + */
886 + public static function import_choices() {
887 + _deprecated_function( __METHOD__, '4.0' );
888 + wp_die();
889 + }
890 +
891 + /**
892 + * Add Single Option or Other Option.
893 + *
894 + * @deprecated 4.0 Moved to Pro for Other option only.
895 + */
896 + public static function add_option() {
897 + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
898 + }
899 +
900 + /**
901 + * @deprecated 4.0
902 + */
903 + public static function update_order() {
904 + FrmDeprecated::update_order();
905 + }
906 +
907 + /**
908 + * @deprecated 3.0
909 + * @codeCoverageIgnore
910 + */
911 + public static function edit_name( $field = 'name', $id = '' ) {
912 + FrmDeprecated::edit_name( $field, $id );
913 + }
914 +
915 + /**
916 + * @deprecated 3.0
917 + * @codeCoverageIgnore
918 + *
919 + * @param int $field_id
920 + * @param array $values
921 + * @param int $form_id
922 + *
923 + * @return array
924 + */
925 + public static function include_single_field( $field_id, $values, $form_id = 0 ) {
926 + return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
1017 927 }
1018 928 }