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