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