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