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 +181 -322 6.266.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
@@ -18,9 +11,8 @@
18 11
19 12 // Javascript may be included in some field settings.
20 13 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
21 14 $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array();
22 -
23 15 if ( empty( $fields ) ) {
24 16 wp_die();
25 17 }
26 18
@@ -34,9 +26,8 @@
34 26
35 27 foreach ( $fields as $field ) {
36 28 $field = htmlspecialchars_decode( nl2br( $field ) );
37 29 $field = json_decode( $field );
38 -
39 30 if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
40 31 // this field may have already been loaded
41 32 continue;
42 33 }
@@ -51,9 +42,9 @@
51 42 ob_start();
52 43 self::load_single_field( $field, $values );
53 44 $field_html[ absint( $field->id ) ] = ob_get_contents();
54 45 ob_end_clean();
55 - }//end foreach
46 + }
56 47
57 48 echo json_encode( $field_html );
58 49
59 50 wp_die();
@@ -65,15 +56,14 @@
65 56 public static function create() {
66 57 FrmAppHelper::permission_check( 'frm_edit_forms' );
67 58 check_ajax_referer( 'frm_ajax', 'nonce' );
68 59
69 - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
70 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
71 - $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' );
72 62
73 63 do_action( 'frm_before_create_field', $field_type, $form_id );
74 64
75 - $field = self::include_new_field( $field_type, $form_id, $field_options );
65 + $field = self::include_new_field( $field_type, $form_id );
76 66
77 67 // this hook will allow for multiple fields to be added at once
78 68 do_action( 'frm_after_field_created', $field, $form_id );
79 69
@@ -82,21 +72,16 @@
82 72
83 73 /**
84 74 * Set up and create a new field
85 75 *
86 - * @param string $field_type
87 - * @param int $form_id
88 - * @param array $field_options
76 + * @param string $field_type
77 + * @param integer $form_id
89 78 *
90 - * @return array|false
79 + * @return array|bool
91 80 */
92 - public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
81 + public static function include_new_field( $field_type, $form_id ) {
93 82 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
94 83
95 - if ( ! empty( $field_options ) ) {
96 - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
97 - }
98 -
99 84 // When a new field is added to the form, flag it as draft and hide it from the front-end.
100 85 $field_values['field_options']['draft'] = 1;
101 86
102 87 /**
@@ -111,14 +96,12 @@
111 96
112 97 $field = self::get_field_array_from_id( $field_id );
113 98
114 99 $values = array();
115 -
116 100 if ( FrmAppHelper::pro_is_installed() ) {
117 101 $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
118 102
119 103 $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
120 -
121 104 if ( $parent_form_id ) {
122 105 $field['parent_form_id'] = $parent_form_id;
123 106 }
124 107 }
@@ -159,13 +142,11 @@
159 142
160 143 /**
161 144 * @since 3.0
162 145 *
163 - * @param array|int|object $field_object
146 + * @param int|array|object $field_object
164 147 * @param array $values
165 148 * @param int $form_id
166 - *
167 - * @return void
168 149 */
169 150 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
170 151 global $frm_vars;
171 152 $frm_vars['is_admin'] = true;
@@ -179,47 +160,30 @@
179 160
180 161 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
181 162 $display = self::display_field_options( array(), $field_obj );
182 163
183 - $ajax_loading = ! empty( $values['ajax_load'] );
184 - $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' ) );
185 166
186 167 if ( $ajax_loading && $ajax_this_field ) {
187 168 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
188 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php';
189 - return;
190 - }
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;
191 173
192 - if ( ! isset( $field ) && is_object( $field_object ) ) {
193 - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id;
194 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
195 - }
174 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
175 + }
196 176
197 - /**
198 - * Filter for adding extra attributes to the field container.
199 - *
200 - * @since 6.23
201 - *
202 - * @param array $extra_field_attributes
203 - * @param array $field
204 - * @param array $display
205 - */
206 - $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';
207 179
208 - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
209 - $li_classes .= ' ui-state-default widgets-holder-wrap';
210 -
211 - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
180 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
181 + }
212 182 }
213 183
214 184 /**
215 185 * @since 3.0
216 - *
217 - * @param array $field
218 - * @param array $display
219 - * @param FrmFieldType $field_info
220 - *
221 - * @return string
222 186 */
223 187 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
224 188 $li_classes = $field_info->form_builder_classes( $display['type'] );
225 189 $li_classes .= ' frm_form_field frmstart ';
@@ -256,24 +220,12 @@
256 220 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
257 221 return;
258 222 }
259 223
260 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
261 - $field = FrmField::getOne( $field_id );
262 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
224 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
225 + $field = FrmField::getOne( $field_id );
263 226
264 - /**
265 - * Filter to add new fields that will support import_options/Bulk Edit Options.
266 - *
267 - * @since 6.8.4
268 - *
269 - * @param array $bulk_edit_types
270 - *
271 - * @return array
272 - */
273 - $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
274 -
275 - if ( ! in_array( $field->type, $bulk_edit_types, true ) ) {
227 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
276 228 return;
277 229 }
278 230
279 231 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -280,15 +232,15 @@
280 232 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
281 233 $opts = explode( "\n", rtrim( $opts, "\n" ) );
282 234 $opts = array_map( 'trim', $opts );
283 235
284 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
285 - $field['separate_value'] = $separate === 'true';
236 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
237 + $field['separate_value'] = ( $separate === 'true' );
286 238
287 239 if ( $field['separate_value'] ) {
288 240 foreach ( $opts as $opt_key => $opt ) {
289 241 if ( strpos( $opt, '|' ) !== false ) {
290 - $vals = explode( '|', $opt );
242 + $vals = explode( '|', $opt );
291 243 $opts[ $opt_key ] = array(
292 244 'label' => trim( $vals[0] ),
293 245 'value' => trim( $vals[1] ),
294 246 );
@@ -300,9 +252,8 @@
300 252
301 253 // Keep other options after bulk update.
302 254 if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
303 255 $other_array = array();
304 -
305 256 foreach ( $field['options'] as $opt_key => $opt ) {
306 257 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
307 258 $other_array[ $opt_key ] = $opt;
308 259 }
@@ -307,9 +258,8 @@
307 258 $other_array[ $opt_key ] = $opt;
308 259 }
309 260 unset( $opt_key, $opt );
310 261 }
311 -
312 262 if ( ! empty( $other_array ) ) {
313 263 $opts = array_merge( $opts, $other_array );
314 264 }
315 265 }
@@ -324,10 +274,8 @@
324 274 /**
325 275 * @since 4.0
326 276 *
327 277 * @param array $atts - Includes field array, field_obj, display array, values array.
328 - *
329 - * @return void
330 278 */
331 279 public static function load_single_field_settings( $atts ) {
332 280 $field = $atts['field'];
333 281 $field_obj = $atts['field_obj'];
@@ -342,13 +290,13 @@
342 290 if ( ! isset( $field['read_only'] ) ) {
343 291 $field['read_only'] = false;
344 292 }
345 293
346 - $field_selection_data = self::maybe_define_field_selection_data();
347 - $all_field_types = $field_selection_data->all_field_types;
348 - $disabled_fields = $field_selection_data->disabled_fields;
349 - $frm_settings = FrmAppHelper::get_settings();
350 - $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();
351 299
352 300 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
353 301 // Add fallback for an add-on field type that has been deactivated.
354 302 $all_field_types[ $field['type'] ] = array(
@@ -360,9 +308,8 @@
360 308 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
361 309 }
362 310
363 311 $type_name = $all_field_types[ $field['type'] ]['name'];
364 -
365 312 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
366 313 $type_name = $all_field_types['divider|repeat']['name'];
367 314 }
368 315
@@ -377,72 +324,57 @@
377 324 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
378 325 }
379 326
380 327 /**
381 - * @since 6.9.1
382 - *
383 - * @return FrmFieldSelectionData
384 - */
385 - private static function maybe_define_field_selection_data() {
386 - if ( ! isset( self::$field_selection_data ) ) {
387 - self::$field_selection_data = new FrmFieldSelectionData();
388 - }
389 - return self::$field_selection_data;
390 - }
391 -
392 - /**
393 328 * Get the list of default value types that can be toggled in the builder.
394 329 *
395 330 * @since 4.0
396 - *
397 - * @param array $field
398 - * @param array $atts
399 - *
400 331 * @return array
401 332 */
402 333 private static function default_value_types( $field, $atts ) {
403 334 $types = array(
404 - 'default_value' => array(
335 + 'default_value' => array(
405 336 'class' => '',
406 337 'icon' => 'frm_icon_font frm_text2_icon',
407 - 'title' => __( 'Default Value', 'formidable' ),
338 + 'title' => __( 'Default Value (Text)', 'formidable' ),
408 339 'data' => array(
409 340 'frmshow' => '#default-value-for-',
410 341 ),
411 342 ),
412 - 'calc' => array(
413 - 'class' => 'frm_show_upgrade frm_noallow',
414 - 'title' => __( 'Calculate Value', 'formidable' ),
415 - 'icon' => 'frm_icon_font frm_calculator_icon',
416 - '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(
417 348 'medium' => 'calculations',
418 349 'upgrade' => __( 'Calculator forms', 'formidable' ),
419 350 ),
420 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
421 351 ),
422 352 'get_values_field' => array(
423 - 'class' => 'frm_show_upgrade frm_noallow',
424 - 'title' => __( 'Lookup', 'formidable' ),
425 - 'icon' => 'frm_icon_font frm_search_icon',
426 - '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(
427 357 'medium' => 'lookup',
428 358 'upgrade' => __( 'Lookup fields', 'formidable' ),
429 359 ),
430 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
431 360 ),
432 361 );
433 362
434 363 $types = apply_filters( 'frm_default_value_types', $types, $atts );
435 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 +
436 370 // Set active class.
437 371 $settings = array_keys( $types );
438 372 $active = 'default_value';
439 373
440 - if ( FrmAppHelper::pro_is_connected() ) {
441 - foreach ( $settings as $type ) {
442 - if ( ! empty( $field[ $type ] ) ) {
443 - $active = $type;
444 - }
374 + foreach ( $settings as $type ) {
375 + if ( ! empty( $field[ $type ] ) ) {
376 + $active = $type;
445 377 }
446 378 }
447 379
448 380 $types[ $active ]['class'] .= ' current';
@@ -450,13 +382,8 @@
450 382
451 383 return $types;
452 384 }
453 385
454 - /**
455 - * @param string $type
456 - *
457 - * @return string
458 - */
459 386 public static function change_type( $type ) {
460 387 $type_switch = array(
461 388 'scale' => 'radio',
462 389 'star' => 'radio',
@@ -464,9 +391,8 @@
464 391 'rte' => 'textarea',
465 392 'website' => 'url',
466 393 'image' => 'url',
467 394 );
468 -
469 395 if ( isset( $type_switch[ $type ] ) ) {
470 396 $type = $type_switch[ $type ];
471 397 }
472 398
@@ -482,18 +408,16 @@
482 408 return $type;
483 409 }
484 410
485 411 /**
486 - * @param array $settings
487 - * @param FrmFieldType|null $field_info
412 + * @param array $settings
413 + * @param object $field_info
488 414 *
489 415 * @return array
490 416 */
491 417 public static function display_field_options( $settings, $field_info = null ) {
492 418 if ( $field_info ) {
493 - $settings = $field_info->display_field_settings();
494 -
495 - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
419 + $settings = $field_info->display_field_settings();
496 420 $settings['field_data'] = $field_info->field;
497 421 }
498 422
499 423 return apply_filters( 'frm_display_field_options', $settings );
@@ -503,32 +427,14 @@
503 427 * Display the format option
504 428 *
505 429 * @since 3.0
506 430 *
507 - * @param array $field Field data.
508 - * @param bool $is_hidden Whether the format option should be hidden.
509 - *
510 - * @return void
431 + * @param array $field
511 432 */
512 - public static function show_format_option( $field, $is_hidden = false ) {
513 - $attributes = array(
514 - 'class' => 'frm-has-modal',
515 - 'id' => 'frm-field-format-custom-' . $field['id'],
516 - );
517 -
518 - if ( $is_hidden ) {
519 - $attributes['class'] .= ' frm_hidden';
520 - }
521 -
522 - 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' );
523 435 }
524 436
525 - /**
526 - * @param array $field
527 - * @param bool $echo
528 - *
529 - * @return string
530 - */
531 437 public static function input_html( $field, $echo = true ) {
532 438 $class = array();
533 439 self::add_input_classes( $field, $class );
534 440
@@ -554,20 +460,14 @@
554 460
555 461 return $add_html;
556 462 }
557 463
558 - /**
559 - * @param array $field
560 - * @param array $class
561 - *
562 - * @return void
563 - */
564 464 private static function add_input_classes( $field, array &$class ) {
565 - if ( ! empty( $field['input_class'] ) ) {
465 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
566 466 $class[] = $field['input_class'];
567 467 }
568 468
569 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
469 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
570 470 return;
571 471 }
572 472
573 473 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -574,14 +474,8 @@
574 474 $class[] = 'auto_width';
575 475 }
576 476 }
577 477
578 - /**
579 - * @param array $field
580 - * @param array $add_html
581 - *
582 - * @return void
583 - */
584 478 private static function add_html_size( $field, array &$add_html ) {
585 479 $size_fields = array(
586 480 'select',
587 481 'data',
@@ -590,9 +484,9 @@
590 484 'file',
591 485 'lookup',
592 486 );
593 487
594 - 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 ) ) {
595 489 return;
596 490 }
597 491
598 492 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -609,14 +503,8 @@
609 503
610 504 self::add_html_cols( $field, $add_html );
611 505 }
612 506
613 - /**
614 - * @param array $field
615 - * @param array $add_html
616 - *
617 - * @return void
618 - */
619 507 private static function add_html_cols( $field, array &$add_html ) {
620 508 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
621 509 return;
622 510 }
@@ -640,14 +528,8 @@
640 528
641 529 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
642 530 }
643 531
644 - /**
645 - * @param array $field
646 - * @param array $add_html
647 - *
648 - * @return void
649 - */
650 532 private static function add_html_length( $field, array &$add_html ) {
651 533 // Check for max setting and if this field accepts maxlength.
652 534 $fields = array(
653 535 'textarea',
@@ -655,9 +537,9 @@
655 537 'hidden',
656 538 'file',
657 539 );
658 540
659 - 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 ) ) {
660 542 return;
661 543 }
662 544
663 545 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -667,15 +549,8 @@
667 549
668 550 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
669 551 }
670 552
671 - /**
672 - * @param array $field
673 - * @param array $add_html
674 - * @param array $class
675 - *
676 - * @return void
677 - */
678 553 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
679 554 if ( $field['default_value'] != '' ) {
680 555 if ( is_array( $field['default_value'] ) ) {
681 556 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -684,15 +559,26 @@
684 559 }
685 560 }
686 561
687 562 $field['placeholder'] = self::prepare_placeholder( $field );
688 -
689 563 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
690 564 // don't include a json placeholder
691 565 return;
692 566 }
693 567
694 - 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 + }
695 581 }
696 582
697 583 /**
698 584 * Prepares field placeholder.
@@ -699,13 +585,12 @@
699 585 *
700 586 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
701 587 *
702 588 * @param array $field Field array.
703 - *
704 589 * @return string
705 590 */
706 591 private static function prepare_placeholder( $field ) {
707 - $placeholder = $field['placeholder'] ?? '';
592 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
708 593
709 594 return $placeholder;
710 595 }
711 596
@@ -728,16 +613,12 @@
728 613 * Maybe add a blank placeholder option before any options
729 614 * in a dropdown.
730 615 *
731 616 * @since 4.04
732 - *
733 - * @param array|object $field
734 - *
735 617 * @return bool True if placeholder was added.
736 618 */
737 619 public static function add_placeholder_to_select( $field ) {
738 620 $placeholder = FrmField::get_option( $field, 'placeholder' );
739 -
740 621 if ( empty( $placeholder ) ) {
741 622 $placeholder = self::get_default_value_from_name( $field );
742 623 }
743 624
@@ -745,9 +626,8 @@
745 626 $autocomplete = FrmField::get_option( $field, 'autocom' );
746 627
747 628 if ( $autocomplete ) {
748 629 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
749 -
750 630 if ( $use_chosen ) {
751 631 $use_placeholder = '';
752 632 }
753 633 }
@@ -758,8 +638,13 @@
758 638 'value' => '',
759 639 'data-placeholder' => 'true',
760 640 );
761 641
642 + if ( $autocomplete && empty( $use_chosen ) ) {
643 + // This is required for Slim Select.
644 + $placeholder_attributes['data-placeholder'] = 'true';
645 + }
646 +
762 647 FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
763 648 return true;
764 649 }
765 650
@@ -766,14 +651,12 @@
766 651 return false;
767 652 }
768 653
769 654 /**
770 - * Use HTML5 placeholder with js fallback.
655 + * Use HMTL5 placeholder with js fallback
771 656 *
772 657 * @param array $field
773 658 * @param array $add_html
774 - *
775 - * @return void
776 659 */
777 660 private static function add_placeholder_to_input( $field, &$add_html ) {
778 661 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
779 662 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -779,14 +662,8 @@
779 662 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
780 663 }
781 664 }
782 665
783 - /**
784 - * @param array $field
785 - * @param array $add_html
786 - *
787 - * @return void
788 - */
789 666 private static function add_frmval_to_input( $field, &$add_html ) {
790 667 if ( $field['placeholder'] != '' ) {
791 668 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
792 669
@@ -799,24 +676,16 @@
799 676 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
800 677 }
801 678 }
802 679
803 - /**
804 - * @param array $field
805 - * @param array $add_html
806 - *
807 - * @return void
808 - */
809 680 private static function add_validation_messages( $field, array &$add_html ) {
810 - $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
811 -
812 - if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
681 + if ( FrmField::is_required( $field ) ) {
813 682 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
814 683 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
815 684 self::maybe_add_html_required( $field, $add_html );
816 685 }
817 686
818 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
687 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
819 688 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
820 689 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
821 690 }
822 691
@@ -825,57 +694,20 @@
825 694 }
826 695 }
827 696
828 697 /**
829 - * Returns an array that contains field validation messages status.
830 - *
831 - * @since 6.9
832 - *
833 - * @param array|object $field
834 - *
835 - * @return array
836 - */
837 - private static function get_validation_data_attribute_visibility_info( $field ) {
838 - if ( FrmField::get_field_type( $field ) === 'hidden' ) {
839 - $field_validation_data_attributes = array(
840 - 'data-invmsg' => false,
841 - 'data-reqmsg' => false,
842 - );
843 - } else {
844 - $field_validation_data_attributes = array(
845 - 'data-invmsg' => true,
846 - 'data-reqmsg' => true,
847 - );
848 - }
849 -
850 - /**
851 - * Allows controlling which field validation messages would be included in the field html.
852 - *
853 - * @since 6.9
854 - *
855 - * @param array $field_validation_messages_status
856 - * @param array|object $field
857 - */
858 - return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
859 - }
860 -
861 - /**
862 698 * @since 5.0.03
863 699 *
864 700 * @param array $field
865 701 * @param array $add_html
866 - *
867 - * @return void
868 702 */
869 703 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
870 704 $form = self::get_form_for_js_validation( $field );
871 -
872 705 if ( false === $form ) {
873 706 return;
874 707 }
875 708
876 709 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
877 -
878 710 if ( false !== $error_body ) {
879 711 $error_body = urlencode( $error_body );
880 712 $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
881 713 }
@@ -884,19 +716,16 @@
884 716 /**
885 717 * @since 5.0.03
886 718 *
887 719 * @param array $field
888 - *
889 - * @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.
890 721 */
891 722 private static function get_form_for_js_validation( $field ) {
892 723 global $frm_vars;
893 -
894 724 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
895 725 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
896 726 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
897 727 }
898 -
899 728 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
900 729 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
901 730 }
902 731 }
@@ -906,10 +735,9 @@
906 735 /**
907 736 * @param stdClass $form
908 737 * @param array $field
909 738 * @param array $errors
910 - *
911 - * @return false|string
739 + * @return string|false
912 740 */
913 741 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
914 742 if ( empty( $field['custom_html'] ) ) {
915 743 return false;
@@ -918,15 +746,13 @@
918 746 $custom_html = $field['custom_html'];
919 747 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
920 748
921 749 $start = strpos( $custom_html, '[if error]' );
922 -
923 750 if ( false === $start ) {
924 751 return false;
925 752 }
926 753
927 754 $end = strpos( $custom_html, '[/if error]' );
928 -
929 755 if ( false === $end || $end < $start ) {
930 756 return false;
931 757 }
932 758
@@ -950,13 +776,10 @@
950 776 * submit in many browsers. Check to make sure the javascript to conditionally
951 777 * remove it is present if needed.
952 778 *
953 779 * @since 3.06.01
954 - *
955 780 * @param array $field
956 781 * @param array $add_html
957 - *
958 - * @return void
959 782 */
960 783 private static function maybe_add_html_required( $field, array &$add_html ) {
961 784 $excluded_field_types =
962 785 FrmField::is_radio( $field ) ||
@@ -968,17 +791,14 @@
968 791 if ( $excluded_field_types ) {
969 792 return;
970 793 }
971 794
972 - $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 + }
973 799 }
974 800
975 - /**
976 - * @param array $field
977 - * @param array $add_html
978 - *
979 - * @return void
980 - */
981 801 private static function add_shortcodes_to_html( $field, array &$add_html ) {
982 802 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
983 803 return;
984 804 }
@@ -987,21 +807,9 @@
987 807 unset( $field['shortcodes']['autocomplete'] );
988 808 }
989 809
990 810 foreach ( $field['shortcodes'] as $k => $v ) {
991 - if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
992 - $subfield_name = $field['subfield_name'];
993 -
994 - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
995 - continue;
996 - }
997 - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
998 - $k = 'aria-invalid';
999 - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1000 - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1001 - }
1002 -
1003 - if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
811 + if ( 'opt' === $k ) {
1004 812 continue;
1005 813 }
1006 814
1007 815 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -1012,63 +820,41 @@
1012 820 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1013 821 }
1014 822
1015 823 unset( $k, $v );
1016 - }//end foreach
1017 - }
1018 -
1019 - /**
1020 - * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
1021 - *
1022 - * @since 6.11.2
1023 - *
1024 - * @param string $key The option key.
1025 - *
1026 - * @return bool
1027 - */
1028 - private static function should_allow_input_attribute( $key ) {
1029 - if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
1030 - return true;
1031 824 }
1032 - return FrmAppHelper::input_key_is_safe( $key );
1033 825 }
1034 826
1035 827 /**
1036 - * Add pattern attribute.
828 + * Add pattern attribute
1037 829 *
1038 830 * @since 3.0
1039 831 *
1040 832 * @param array $field
1041 833 * @param array $add_html
1042 - *
1043 - * @return void
1044 834 */
1045 835 private static function add_pattern_attribute( $field, array &$add_html ) {
1046 - $format_value = FrmField::get_option( $field, 'format' );
1047 - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
836 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1048 837 $format_field = FrmField::is_field_type( $field, 'text' );
1049 838
1050 - if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
1051 - $format = FrmEntryValidate::phone_format( $field );
1052 - $format = substr( $format, 2, - 1 );
839 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
840 + $frm_settings = FrmAppHelper::get_settings();
1053 841
1054 - $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 + }
1055 848 }
1056 849 }
1057 850
1058 - /**
1059 - * @param mixed $opt
1060 - * @param mixed $opt_key
1061 - * @param array|object $field
1062 - *
1063 - * @return mixed
1064 - */
1065 851 public static function check_value( $opt, $opt_key, $field ) {
1066 852 if ( is_array( $opt ) ) {
1067 853 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1068 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
854 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1069 855 } else {
1070 - $opt = $opt['label'] ?? reset( $opt );
856 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1071 857 }
1072 858 }
1073 859
1074 860 return $opt;
@@ -1073,17 +859,90 @@
1073 859
1074 860 return $opt;
1075 861 }
1076 862
1077 - /**
1078 - * @param mixed $opt
1079 - *
1080 - * @return mixed
1081 - */
1082 863 public static function check_label( $opt ) {
1083 864 if ( is_array( $opt ) ) {
1084 - $opt = $opt['label'] ?? reset( $opt );
865 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1085 866 }
1086 867
1087 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 );
1088 947 }
1089 948 }