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