PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.07
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.07
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 +242 -312 6.255.0.07 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,53 +154,47 @@
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 - $li_classes = $field_info->form_builder_classes( $display['type'] );
182 + $li_classes = $field_info->form_builder_classes( $display['type'] );
183 + $classes = isset( $field['classes'] ) ? $field['classes'] : '';
184 +
185 + // Exclude alignright for now since we aren't using widths.
186 + $classes = str_replace( ' frm_alignright ', ' ', $classes );
187 + $classes = trim( $classes );
188 +
189 + if ( 'frm_alignright' === $classes ) {
190 + $classes = '';
191 + }
192 +
218 193 $li_classes .= ' frm_form_field frmstart ';
219 194
220 - if ( isset( $field['classes'] ) ) {
221 - $li_classes .= trim( $field['classes'] ) . ' ';
195 + if ( $classes ) {
196 + $li_classes .= $classes . ' ';
222 197 }
223 198
224 199 $li_classes .= 'frmend';
225 200
@@ -238,11 +213,10 @@
238 213 FrmField::destroy( $field_id );
239 214 wp_die();
240 215 }
241 216
242 - /**
243 - * Field Options.
244 - */
217 + /* Field Options */
218 +
245 219 public static function import_options() {
246 220 FrmAppHelper::permission_check( 'frm_edit_forms' );
247 221 check_ajax_referer( 'frm_ajax', 'nonce' );
248 222
@@ -249,23 +223,12 @@
249 223 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
250 224 return;
251 225 }
252 226
253 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
254 - $field = FrmField::getOne( $field_id );
255 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
227 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
228 + $field = FrmField::getOne( $field_id );
256 229
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 ) ) {
230 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
268 231 return;
269 232 }
270 233
271 234 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -272,15 +235,15 @@
272 235 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
273 236 $opts = explode( "\n", rtrim( $opts, "\n" ) );
274 237 $opts = array_map( 'trim', $opts );
275 238
276 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
277 - $field['separate_value'] = $separate === 'true';
239 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
240 + $field['separate_value'] = ( $separate === 'true' );
278 241
279 242 if ( $field['separate_value'] ) {
280 243 foreach ( $opts as $opt_key => $opt ) {
281 244 if ( strpos( $opt, '|' ) !== false ) {
282 - $vals = explode( '|', $opt );
245 + $vals = explode( '|', $opt );
283 246 $opts[ $opt_key ] = array(
284 247 'label' => trim( $vals[0] ),
285 248 'value' => trim( $vals[1] ),
286 249 );
@@ -314,9 +277,8 @@
314 277 /**
315 278 * @since 4.0
316 279 *
317 280 * @param array $atts - Includes field array, field_obj, display array, values array.
318 - * @return void
319 281 */
320 282 public static function load_single_field_settings( $atts ) {
321 283 $field = $atts['field'];
322 284 $field_obj = $atts['field_obj'];
@@ -331,13 +293,13 @@
331 293 if ( ! isset( $field['read_only'] ) ) {
332 294 $field['read_only'] = false;
333 295 }
334 296
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'] );
297 + $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
298 + $pro_field_selection = FrmField::pro_field_selection();
299 + $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
300 + $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
301 + $frm_settings = FrmAppHelper::get_settings();
340 302
341 303 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
342 304 // Add fallback for an add-on field type that has been deactivated.
343 305 $all_field_types[ $field['type'] ] = array(
@@ -360,76 +322,61 @@
360 322
361 323 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
362 324 $field['placeholder'] = implode( ', ', $field['placeholder'] );
363 325 }
364 -
365 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
326 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
366 327 }
367 328
368 329 /**
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 330 * Get the list of default value types that can be toggled in the builder.
382 331 *
383 332 * @since 4.0
384 - *
385 - * @param array $field
386 - * @param array $atts
387 333 * @return array
388 334 */
389 335 private static function default_value_types( $field, $atts ) {
390 336 $types = array(
391 - 'default_value' => array(
337 + 'default_value' => array(
392 338 'class' => '',
393 339 'icon' => 'frm_icon_font frm_text2_icon',
394 - 'title' => __( 'Default Value', 'formidable' ),
340 + 'title' => __( 'Default Value (Text)', 'formidable' ),
395 341 'data' => array(
396 342 'frmshow' => '#default-value-for-',
397 343 ),
398 344 ),
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(
345 + 'calc' => array(
346 + 'class' => 'frm_show_upgrade frm_noallow',
347 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
348 + 'icon' => 'frm_icon_font frm_calculator_icon',
349 + 'data' => array(
404 350 'medium' => 'calculations',
405 351 'upgrade' => __( 'Calculator forms', 'formidable' ),
406 352 ),
407 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
408 353 ),
409 354 '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(
355 + 'class' => 'frm_show_upgrade frm_noallow',
356 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
357 + 'icon' => 'frm_icon_font frm_search_icon',
358 + 'data' => array(
414 359 'medium' => 'lookup',
415 360 'upgrade' => __( 'Lookup fields', 'formidable' ),
416 361 ),
417 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
418 362 ),
419 363 );
420 364
421 365 $types = apply_filters( 'frm_default_value_types', $types, $atts );
422 366
367 + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
368 + // Prevent settings from showing in 2 spots.
369 + unset( $types['calc'], $types['get_values_field'] );
370 + }
371 +
423 372 // Set active class.
424 373 $settings = array_keys( $types );
425 374 $active = 'default_value';
426 375
427 - if ( FrmAppHelper::pro_is_connected() ) {
428 - foreach ( $settings as $type ) {
429 - if ( ! empty( $field[ $type ] ) ) {
430 - $active = $type;
431 - }
376 + foreach ( $settings as $type ) {
377 + if ( ! empty( $field[ $type ] ) ) {
378 + $active = $type;
432 379 }
433 380 }
434 381
435 382 $types[ $active ]['class'] .= ' current';
@@ -437,12 +384,8 @@
437 384
438 385 return $types;
439 386 }
440 387
441 - /**
442 - * @param string $type
443 - * @return string
444 - */
445 388 public static function change_type( $type ) {
446 389 $type_switch = array(
447 390 'scale' => 'radio',
448 391 'star' => 'radio',
@@ -455,13 +398,10 @@
455 398 $type = $type_switch[ $type ];
456 399 }
457 400
458 401 $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 ) ) {
402 + $types = array_keys( $pro_fields );
403 + if ( in_array( $type, $types ) ) {
464 404 $type = 'text';
465 405 }
466 406
467 407 return $type;
@@ -467,18 +407,16 @@
467 407 return $type;
468 408 }
469 409
470 410 /**
471 - * @param array $settings
472 - * @param FrmFieldType|null $field_info
411 + * @param array $settings
412 + * @param object $field_info
473 413 *
474 414 * @return array
475 415 */
476 416 public static function display_field_options( $settings, $field_info = null ) {
477 417 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.
418 + $settings = $field_info->display_field_settings();
481 419 $settings['field_data'] = $field_info->field;
482 420 }
483 421
484 422 return apply_filters( 'frm_display_field_options', $settings );
@@ -488,23 +426,12 @@
488 426 * Display the format option
489 427 *
490 428 * @since 3.0
491 429 *
492 - * @param array $field Field data.
493 - * @param bool $is_hidden Whether the format option should be hidden.
494 - * @return void
430 + * @param array $field
495 431 */
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';
432 + public static function show_format_option( $field ) {
433 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
507 434 }
508 435
509 436 public static function input_html( $field, $echo = true ) {
510 437 $class = array();
@@ -526,25 +453,20 @@
526 453 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
527 454 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
528 455
529 456 if ( $echo ) {
530 - echo $add_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
457 + echo $add_html; // WPCS: XSS ok.
531 458 }
532 459
533 460 return $add_html;
534 461 }
535 462
536 - /**
537 - * @param array $field
538 - * @param array $class
539 - * @return void
540 - */
541 463 private static function add_input_classes( $field, array &$class ) {
542 - if ( ! empty( $field['input_class'] ) ) {
464 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
543 465 $class[] = $field['input_class'];
544 466 }
545 467
546 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
468 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
547 469 return;
548 470 }
549 471
550 472 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -551,13 +473,8 @@
551 473 $class[] = 'auto_width';
552 474 }
553 475 }
554 476
555 - /**
556 - * @param array $field
557 - * @param array $add_html
558 - * @return void
559 - */
560 477 private static function add_html_size( $field, array &$add_html ) {
561 478 $size_fields = array(
562 479 'select',
563 480 'data',
@@ -566,9 +483,9 @@
566 483 'file',
567 484 'lookup',
568 485 );
569 486
570 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
487 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
571 488 return;
572 489 }
573 490
574 491 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -585,15 +502,10 @@
585 502
586 503 self::add_html_cols( $field, $add_html );
587 504 }
588 505
589 - /**
590 - * @param array $field
591 - * @param array $add_html
592 - * @return void
593 - */
594 506 private static function add_html_cols( $field, array &$add_html ) {
595 - if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
507 + if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
596 508 return;
597 509 }
598 510
599 511 // Convert to cols for textareas.
@@ -615,13 +527,8 @@
615 527
616 528 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
617 529 }
618 530
619 - /**
620 - * @param array $field
621 - * @param array $add_html
622 - * @return void
623 - */
624 531 private static function add_html_length( $field, array &$add_html ) {
625 532 // Check for max setting and if this field accepts maxlength.
626 533 $fields = array(
627 534 'textarea',
@@ -629,9 +536,9 @@
629 536 'hidden',
630 537 'file',
631 538 );
632 539
633 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
540 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
634 541 return;
635 542 }
636 543
637 544 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -641,14 +548,8 @@
641 548
642 549 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
643 550 }
644 551
645 - /**
646 - * @param array $field
647 - * @param array $add_html
648 - * @param array $class
649 - * @return void
650 - */
651 552 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
652 553 if ( $field['default_value'] != '' ) {
653 554 if ( is_array( $field['default_value'] ) ) {
654 555 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -662,22 +563,37 @@
662 563 // don't include a json placeholder
663 564 return;
664 565 }
665 566
666 - self::add_placeholder_to_input( $field, $add_html );
567 + $frm_settings = FrmAppHelper::get_settings();
568 +
569 + if ( $frm_settings->use_html ) {
570 + self::add_placeholder_to_input( $field, $add_html );
571 + } else {
572 + self::add_frmval_to_input( $field, $add_html );
573 +
574 + $class[] = 'frm_toggle_default';
575 +
576 + if ( $field['value'] == $field['placeholder'] ) {
577 + $class[] = 'frm_default';
578 + }
579 + }
667 580 }
668 581
669 582 /**
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.
583 + * @param array $field
675 584 * @return string
676 585 */
677 586 private static function prepare_placeholder( $field ) {
678 - $placeholder = $field['placeholder'] ?? '';
587 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
588 + $placeholder_is_blank = empty( $placeholder ) && '0' !== $placeholder;
589 + $is_placeholder_field = FrmFieldsHelper::is_placeholder_field_type( $field['type'] );
590 + $is_combo_field = in_array( $field['type'], array( 'address', 'credit_card' ), true );
679 591
592 + if ( $placeholder_is_blank && $is_placeholder_field && ! $is_combo_field ) {
593 + $placeholder = self::get_default_value_from_name( $field );
594 + }
595 +
680 596 return $placeholder;
681 597 }
682 598
683 599 /**
@@ -684,9 +600,8 @@
684 600 * If the label position is "inside",
685 601 * get the label to use as the placeholder
686 602 *
687 603 * @since 2.05
688 - * @since 5.4 Remove the logic code for "inside" label position.
689 604 *
690 605 * @param array $field
691 606 *
692 607 * @return string
@@ -691,9 +606,19 @@
691 606 *
692 607 * @return string
693 608 */
694 609 public static function get_default_value_from_name( $field ) {
695 - return '';
610 + $position = FrmField::get_option( $field, 'label' );
611 + if ( $position == 'inside' ) {
612 + $default_value = $field['name'];
613 + if ( FrmField::is_required( $field ) ) {
614 + $default_value .= ' ' . $field['required_indicator'];
615 + }
616 + } else {
617 + $default_value = '';
618 + }
619 +
620 + return $default_value;
696 621 }
697 622
698 623 /**
699 624 * Maybe add a blank placeholder option before any options
@@ -707,26 +632,14 @@
707 632 if ( empty( $placeholder ) ) {
708 633 $placeholder = self::get_default_value_from_name( $field );
709 634 }
710 635
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 636 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 );
637 + ?>
638 + <option value="">
639 + <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
640 + </option>
641 + <?php
729 642 return true;
730 643 }
731 644
732 645 return false;
@@ -732,13 +645,12 @@
732 645 return false;
733 646 }
734 647
735 648 /**
736 - * Use HTML5 placeholder with js fallback.
649 + * Use HMTL5 placeholder with js fallback
737 650 *
738 651 * @param array $field
739 652 * @param array $add_html
740 - * @return void
741 653 */
742 654 private static function add_placeholder_to_input( $field, &$add_html ) {
743 655 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
744 656 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -744,13 +656,8 @@
744 656 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
745 657 }
746 658 }
747 659
748 - /**
749 - * @param array $field
750 - * @param array $add_html
751 - * @return void
752 - */
753 660 private static function add_frmval_to_input( $field, &$add_html ) {
754 661 if ( $field['placeholder'] != '' ) {
755 662 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
756 663
@@ -764,17 +671,15 @@
764 671 }
765 672 }
766 673
767 674 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'] ) ) {
675 + if ( FrmField::is_required( $field ) ) {
771 676 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
772 677 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
773 678 self::maybe_add_html_required( $field, $add_html );
774 679 }
775 680
776 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
681 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
777 682 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
778 683 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
779 684 }
780 685
@@ -783,45 +688,12 @@
783 688 }
784 689 }
785 690
786 691 /**
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 692 * @since 5.0.03
820 693 *
821 694 * @param array $field
822 695 * @param array $add_html
823 - * @return void
824 696 */
825 697 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
826 698 $form = self::get_form_for_js_validation( $field );
827 699 if ( false === $form ) {
@@ -838,9 +710,9 @@
838 710 /**
839 711 * @since 5.0.03
840 712 *
841 713 * @param array $field
842 - * @return false|stdClass false if there is no form object found with JS validation active.
714 + * @return stdClass|false false if there is no form object found with JS validation active.
843 715 */
844 716 private static function get_form_for_js_validation( $field ) {
845 717 global $frm_vars;
846 718 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
@@ -857,9 +729,9 @@
857 729 /**
858 730 * @param stdClass $form
859 731 * @param array $field
860 732 * @param array $errors
861 - * @return false|string
733 + * @return string|false
862 734 */
863 735 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
864 736 if ( empty( $field['custom_html'] ) ) {
865 737 return false;
@@ -880,11 +752,9 @@
880 752
881 753 $error_body = substr( $custom_html, $start + 10, $end - $start - 10 );
882 754 $default_html = array(
883 755 '<div class="frm_error" id="frm_error_field_[key]">[error]</div>',
884 - '<div class="frm_error" role="alert" id="frm_error_field_[key]">[error]</div>',
885 756 '<div class="frm_error">[error]</div>',
886 - '<div class="frm_error" role="alert">[error]</div>',
887 757 );
888 758
889 759 if ( in_array( $error_body, $default_html, true ) ) {
890 760 return false;
@@ -900,51 +770,27 @@
900 770 *
901 771 * @since 3.06.01
902 772 * @param array $field
903 773 * @param array $add_html
904 - * @return void
905 774 */
906 775 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 ) {
776 + if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) {
915 777 return;
916 778 }
917 779
918 - $add_html['aria-required'] = 'aria-required="true"';
780 + $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
781 + if ( $include_html ) {
782 + $add_html['aria-required'] = 'aria-required="true"';
783 + }
919 784 }
920 785
921 - /**
922 - * @param array $field
923 - * @param array $add_html
924 - * @return void
925 - */
926 786 private static function add_shortcodes_to_html( $field, array &$add_html ) {
927 787 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
928 788 return;
929 789 }
930 790
931 - if ( ! empty( $field['autocomplete'] ) ) {
932 - unset( $field['shortcodes']['autocomplete'] );
933 - }
934 -
935 791 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 ) ) {
792 + if ( 'opt' === $k ) {
947 793 continue;
948 794 }
949 795
950 796 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -955,45 +801,32 @@
955 801 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
956 802 }
957 803
958 804 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 805 }
974 - return FrmAppHelper::input_key_is_safe( $key );
975 806 }
976 807
977 808 /**
978 - * Add pattern attribute.
809 + * Add pattern attribute
979 810 *
980 811 * @since 3.0
981 812 *
982 813 * @param array $field
983 814 * @param array $add_html
984 - * @return void
985 815 */
986 816 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 );
817 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
989 818 $format_field = FrmField::is_field_type( $field, 'text' );
990 819
991 - if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
992 - $format = FrmEntryValidate::phone_format( $field );
993 - $format = substr( $format, 2, - 1 );
820 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
821 + $frm_settings = FrmAppHelper::get_settings();
994 822
995 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
823 + if ( $frm_settings->use_html ) {
824 + $format = FrmEntryValidate::phone_format( $field );
825 + $format = substr( $format, 2, - 1 );
826 +
827 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
828 + }
996 829 }
997 830 }
998 831
999 832 public static function check_value( $opt, $opt_key, $field ) {
@@ -998,11 +831,11 @@
998 831
999 832 public static function check_value( $opt, $opt_key, $field ) {
1000 833 if ( is_array( $opt ) ) {
1001 834 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1002 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
835 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1003 836 } else {
1004 - $opt = $opt['label'] ?? reset( $opt );
837 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1005 838 }
1006 839 }
1007 840
1008 841 return $opt;
@@ -1009,10 +842,107 @@
1009 842 }
1010 843
1011 844 public static function check_label( $opt ) {
1012 845 if ( is_array( $opt ) ) {
1013 - $opt = $opt['label'] ?? reset( $opt );
846 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1014 847 }
1015 848
1016 849 return $opt;
850 + }
851 +
852 + /**
853 + * @deprecated 4.0
854 + */
855 + public static function update_ajax_option() {
856 + _deprecated_function( __METHOD__, '4.0' );
857 + FrmAppHelper::permission_check( 'frm_edit_forms' );
858 + check_ajax_referer( 'frm_ajax', 'nonce' );
859 +
860 + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
861 + if ( ! $field_id ) {
862 + wp_die();
863 + }
864 +
865 + $field = FrmField::getOne( $field_id );
866 +
867 + if ( isset( $_POST['separate_value'] ) ) {
868 + $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
869 +
870 + $field->field_options['separate_value'] = $new_val;
871 + unset( $new_val );
872 + }
873 +
874 + FrmField::update(
875 + $field_id,
876 + array(
877 + 'field_options' => $field->field_options,
878 + 'form_id' => $field->form_id,
879 + )
880 + );
881 + wp_die();
882 + }
883 +
884 + /**
885 + * @deprecated 4.0
886 + */
887 + public static function import_choices() {
888 + _deprecated_function( __METHOD__, '4.0' );
889 + wp_die();
890 + }
891 +
892 + /**
893 + * Add Single Option or Other Option.
894 + *
895 + * @deprecated 4.0 Moved to Pro for Other option only.
896 + */
897 + public static function add_option() {
898 + _deprecated_function( __METHOD__, '4.0', 'FrmProFormsController::add_other_option' );
899 + if ( is_callable( 'FrmProFormsController::add_other_option' ) ) {
900 + FrmProFormsController::add_other_option();
901 + }
902 + }
903 +
904 + /**
905 + * @deprecated 4.0
906 + */
907 + public static function update_order() {
908 + FrmDeprecated::update_order();
909 + }
910 +
911 + /**
912 + * @deprecated 3.0
913 + * @codeCoverageIgnore
914 + */
915 + public static function edit_name( $field = 'name', $id = '' ) {
916 + FrmDeprecated::edit_name( $field, $id );
917 + }
918 +
919 + /**
920 + * @deprecated 3.0
921 + * @codeCoverageIgnore
922 + *
923 + * @param int $field_id
924 + * @param array $values
925 + * @param int $form_id
926 + *
927 + * @return array
928 + */
929 + public static function include_single_field( $field_id, $values, $form_id = 0 ) {
930 + return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
931 + }
932 +
933 + /**
934 + * @deprecated 2.3
935 + * @codeCoverageIgnore
936 + */
937 + public static function edit_option() {
938 + FrmDeprecated::deprecated( __METHOD__, '2.3' );
939 + }
940 +
941 + /**
942 + * @deprecated 2.3
943 + * @codeCoverageIgnore
944 + */
945 + public static function delete_option() {
946 + FrmDeprecated::deprecated( __METHOD__, '2.3' );
1017 947 }
1018 948 }