PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.17
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.17
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 +88 -174 6.286.17 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 86 * @return array|false
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';
@@ -210,9 +193,8 @@
210 193 *
211 194 * @param array $field
212 195 * @param array $display
213 196 * @param FrmFieldType $field_info
214 - *
215 197 * @return string
216 198 */
217 199 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
218 200 $li_classes = $field_info->form_builder_classes( $display['type'] );
@@ -224,9 +206,9 @@
224 206
225 207 $li_classes .= 'frmend';
226 208
227 209 if ( $field ) {
228 - return apply_filters( 'frm_build_field_class', $li_classes, $field );
210 + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
229 211 }
230 212
231 213 return $li_classes;
232 214 }
@@ -260,9 +242,8 @@
260 242 *
261 243 * @since 6.8.4
262 244 *
263 245 * @param array $bulk_edit_types
264 - *
265 246 * @return array
266 247 */
267 248 $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
268 249
@@ -270,19 +251,18 @@
270 251 return;
271 252 }
272 253
273 254 $field = FrmFieldsHelper::setup_edit_vars( $field );
255 + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
256 + $opts = explode( "\n", rtrim( $opts, "\n" ) );
257 + $opts = array_map( 'trim', $opts );
274 258
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 259 $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
280 260 $field['separate_value'] = $separate === 'true';
281 261
282 262 if ( $field['separate_value'] ) {
283 263 foreach ( $opts as $opt_key => $opt ) {
284 - if ( str_contains( $opt, '|' ) ) {
264 + if ( strpos( $opt, '|' ) !== false ) {
285 265 $vals = explode( '|', $opt );
286 266 $opts[ $opt_key ] = array(
287 267 'label' => trim( $vals[0] ),
288 268 'value' => trim( $vals[1] ),
@@ -293,12 +273,10 @@
293 273 }
294 274 }
295 275
296 276 // Keep other options after bulk update.
297 - // phpcs:ignore Universal.Operators.StrictComparisons
298 - if ( ! empty( $field['field_options']['other'] ) ) {
277 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
299 278 $other_array = array();
300 -
301 279 foreach ( $field['options'] as $opt_key => $opt ) {
302 280 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
303 281 $other_array[ $opt_key ] = $opt;
304 282 }
@@ -303,10 +281,9 @@
303 281 $other_array[ $opt_key ] = $opt;
304 282 }
305 283 unset( $opt_key, $opt );
306 284 }
307 -
308 - if ( $other_array ) {
285 + if ( ! empty( $other_array ) ) {
309 286 $opts = array_merge( $opts, $other_array );
310 287 }
311 288 }
312 289
@@ -320,9 +297,8 @@
320 297 /**
321 298 * @since 4.0
322 299 *
323 300 * @param array $atts - Includes field array, field_obj, display array, values array.
324 - *
325 301 * @return void
326 302 */
327 303 public static function load_single_field_settings( $atts ) {
328 304 $field = $atts['field'];
@@ -348,9 +324,9 @@
348 324 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
349 325 // Add fallback for an add-on field type that has been deactivated.
350 326 $all_field_types[ $field['type'] ] = array(
351 327 'name' => ucfirst( $field['type'] ),
352 - 'icon' => 'frmfont frm_pencil_icon',
328 + 'icon' => 'frm_icon_font frm_pencil_icon',
353 329 );
354 330 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
355 331 // Fallback for fields added in a more basic way.
356 332 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -356,9 +332,8 @@
356 332 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
357 333 }
358 334
359 335 $type_name = $all_field_types[ $field['type'] ]['name'];
360 -
361 336 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
362 337 $type_name = $all_field_types['divider|repeat']['name'];
363 338 }
364 339
@@ -391,9 +366,8 @@
391 366 * @since 4.0
392 367 *
393 368 * @param array $field
394 369 * @param array $atts
395 - *
396 370 * @return array
397 371 */
398 372 private static function default_value_types( $field, $atts ) {
399 373 $types = array(
@@ -398,33 +372,31 @@
398 372 private static function default_value_types( $field, $atts ) {
399 373 $types = array(
400 374 'default_value' => array(
401 375 'class' => '',
402 - 'icon' => 'frmfont frm_text2_icon',
403 - 'title' => __( 'Default Value', 'formidable' ),
376 + 'icon' => 'frm_icon_font frm_text2_icon',
377 + 'title' => __( 'Default Value (Text)', 'formidable' ),
404 378 'data' => array(
405 379 'frmshow' => '#default-value-for-',
406 380 ),
407 381 ),
408 382 'calc' => array(
409 - 'class' => 'frm_show_upgrade frm_noallow',
410 - 'title' => __( 'Calculate Value', 'formidable' ),
411 - 'icon' => 'frmfont frm_calculator_icon',
412 - 'data' => array(
383 + 'class' => 'frm_show_upgrade frm_noallow',
384 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
385 + 'icon' => 'frm_icon_font frm_calculator_icon',
386 + 'data' => array(
413 387 'medium' => 'calculations',
414 388 'upgrade' => __( 'Calculator forms', 'formidable' ),
415 389 ),
416 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
417 390 ),
418 391 'get_values_field' => array(
419 - 'class' => 'frm_show_upgrade frm_noallow',
420 - 'title' => __( 'Lookup', 'formidable' ),
421 - 'icon' => 'frmfont frm_search_icon',
422 - 'data' => array(
392 + 'class' => 'frm_show_upgrade frm_noallow',
393 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
394 + 'icon' => 'frm_icon_font frm_search_icon',
395 + 'data' => array(
423 396 'medium' => 'lookup',
424 397 'upgrade' => __( 'Lookup fields', 'formidable' ),
425 398 ),
426 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
427 399 ),
428 400 );
429 401
430 402 $types = apply_filters( 'frm_default_value_types', $types, $atts );
@@ -432,13 +404,11 @@
432 404 // Set active class.
433 405 $settings = array_keys( $types );
434 406 $active = 'default_value';
435 407
436 - if ( FrmAppHelper::pro_is_connected() ) {
437 - foreach ( $settings as $type ) {
438 - if ( ! empty( $field[ $type ] ) ) {
439 - $active = $type;
440 - }
408 + foreach ( $settings as $type ) {
409 + if ( ! empty( $field[ $type ] ) ) {
410 + $active = $type;
441 411 }
442 412 }
443 413
444 414 $types[ $active ]['class'] .= ' current';
@@ -448,9 +418,8 @@
448 418 }
449 419
450 420 /**
451 421 * @param string $type
452 - *
453 422 * @return string
454 423 */
455 424 public static function change_type( $type ) {
456 425 $type_switch = array(
@@ -460,9 +429,8 @@
460 429 'rte' => 'textarea',
461 430 'website' => 'url',
462 431 'image' => 'url',
463 432 );
464 -
465 433 if ( isset( $type_switch[ $type ] ) ) {
466 434 $type = $type_switch[ $type ];
467 435 }
468 436
@@ -470,9 +438,13 @@
470 438 // We want to keep credit_card types as credit card types for Stripe Lite.
471 439 // The credit_card key is set for backward compatibility.
472 440 unset( $pro_fields['credit_card'] );
473 441
474 - return array_key_exists( $type, $pro_fields ) ? 'text' : $type;
442 + if ( array_key_exists( $type, $pro_fields ) ) {
443 + $type = 'text';
444 + }
445 +
446 + return $type;
475 447 }
476 448
477 449 /**
478 450 * @param array $settings
@@ -495,20 +467,17 @@
495 467 * Display the format option
496 468 *
497 469 * @since 3.0
498 470 *
499 - * @param array $field Field data.
500 - * @param bool $is_hidden Whether the format option should be hidden.
501 - *
471 + * @param array $field
502 472 * @return void
503 473 */
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 - );
474 + public static function show_format_option( $field ) {
475 + $attributes = array();
476 + $attributes['class'] = 'frm-has-modal';
509 477
510 - if ( $is_hidden ) {
478 + if ( 'phone' === $field['type'] ) {
479 + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id'];
511 480 $attributes['class'] .= ' frm_hidden';
512 481 }
513 482
514 483 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
@@ -513,14 +482,8 @@
513 482
514 483 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
515 484 }
516 485
517 - /**
518 - * @param array $field
519 - * @param bool $echo
520 - *
521 - * @return string
522 - */
523 486 public static function input_html( $field, $echo = true ) {
524 487 $class = array();
525 488 self::add_input_classes( $field, $class );
526 489
@@ -549,9 +512,8 @@
549 512
550 513 /**
551 514 * @param array $field
552 515 * @param array $class
553 - *
554 516 * @return void
555 517 */
556 518 private static function add_input_classes( $field, array &$class ) {
557 519 if ( ! empty( $field['input_class'] ) ) {
@@ -569,9 +531,8 @@
569 531
570 532 /**
571 533 * @param array $field
572 534 * @param array $add_html
573 - *
574 535 * @return void
575 536 */
576 537 private static function add_html_size( $field, array &$add_html ) {
577 538 $size_fields = array(
@@ -604,9 +565,8 @@
604 565
605 566 /**
606 567 * @param array $field
607 568 * @param array $add_html
608 - *
609 569 * @return void
610 570 */
611 571 private static function add_html_cols( $field, array &$add_html ) {
612 572 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -620,9 +580,9 @@
620 580 'rem' => 0.444,
621 581 'em' => 0.544,
622 582 );
623 583
624 - // Include "col" for valid html
584 + // include "col" for valid html
625 585 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
626 586
627 587 if ( ! isset( $calc[ $unit ] ) ) {
628 588 return;
@@ -627,9 +587,10 @@
627 587 if ( ! isset( $calc[ $unit ] ) ) {
628 588 return;
629 589 }
630 590
631 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
591 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
592 +
632 593 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
633 594 }
634 595
635 596 /**
@@ -634,9 +595,8 @@
634 595
635 596 /**
636 597 * @param array $field
637 598 * @param array $add_html
638 - *
639 599 * @return void
640 600 */
641 601 private static function add_html_length( $field, array &$add_html ) {
642 602 // Check for max setting and if this field accepts maxlength.
@@ -662,13 +622,11 @@
662 622 /**
663 623 * @param array $field
664 624 * @param array $add_html
665 625 * @param array $class
666 - *
667 626 * @return void
668 627 */
669 628 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
670 - // phpcs:ignore Universal.Operators.StrictComparisons
671 629 if ( $field['default_value'] != '' ) {
672 630 if ( is_array( $field['default_value'] ) ) {
673 631 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
674 632 } else {
@@ -676,12 +634,10 @@
676 634 }
677 635 }
678 636
679 637 $field['placeholder'] = self::prepare_placeholder( $field );
680 -
681 - // phpcs:ignore Universal.Operators.StrictComparisons
682 638 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
683 - // Don't include a json placeholder
639 + // don't include a json placeholder
684 640 return;
685 641 }
686 642
687 643 self::add_placeholder_to_input( $field, $add_html );
@@ -692,13 +648,14 @@
692 648 *
693 649 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
694 650 *
695 651 * @param array $field Field array.
696 - *
697 652 * @return string
698 653 */
699 654 private static function prepare_placeholder( $field ) {
700 - return $field['placeholder'] ?? '';
655 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
656 +
657 + return $placeholder;
701 658 }
702 659
703 660 /**
704 661 * If the label position is "inside",
@@ -719,17 +676,13 @@
719 676 * Maybe add a blank placeholder option before any options
720 677 * in a dropdown.
721 678 *
722 679 * @since 4.04
723 - *
724 - * @param array|object $field
725 - *
726 680 * @return bool True if placeholder was added.
727 681 */
728 682 public static function add_placeholder_to_select( $field ) {
729 683 $placeholder = FrmField::get_option( $field, 'placeholder' );
730 -
731 - if ( ! $placeholder ) {
684 + if ( empty( $placeholder ) ) {
732 685 $placeholder = self::get_default_value_from_name( $field );
733 686 }
734 687
735 688 $use_placeholder = $placeholder;
@@ -736,9 +689,8 @@
736 689 $autocomplete = FrmField::get_option( $field, 'autocom' );
737 690
738 691 if ( $autocomplete ) {
739 692 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
740 -
741 693 if ( $use_chosen ) {
742 694 $use_placeholder = '';
743 695 }
744 696 }
@@ -761,9 +713,8 @@
761 713 * Use HTML5 placeholder with js fallback.
762 714 *
763 715 * @param array $field
764 716 * @param array $add_html
765 - *
766 717 * @return void
767 718 */
768 719 private static function add_placeholder_to_input( $field, &$add_html ) {
769 720 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -773,13 +724,11 @@
773 724
774 725 /**
775 726 * @param array $field
776 727 * @param array $add_html
777 - *
778 728 * @return void
779 729 */
780 730 private static function add_frmval_to_input( $field, &$add_html ) {
781 - // phpcs:ignore Universal.Operators.StrictComparisons
782 731 if ( $field['placeholder'] != '' ) {
783 732 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
784 733
785 734 if ( 'select' === $field['type'] ) {
@@ -786,20 +735,13 @@
786 735 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
787 736 }
788 737 }
789 738
790 - // phpcs:ignore Universal.Operators.StrictComparisons
791 739 if ( $field['default_value'] != '' ) {
792 740 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
793 741 }
794 742 }
795 743
796 - /**
797 - * @param array $field
798 - * @param array $add_html
799 - *
800 - * @return void
801 - */
802 744 private static function add_validation_messages( $field, array &$add_html ) {
803 745 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
804 746
805 747 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -823,9 +765,8 @@
823 765 *
824 766 * @since 6.9
825 767 *
826 768 * @param array|object $field
827 - *
828 769 * @return array
829 770 */
830 771 private static function get_validation_data_attribute_visibility_info( $field ) {
831 772 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -855,26 +796,21 @@
855 796 * @since 5.0.03
856 797 *
857 798 * @param array $field
858 799 * @param array $add_html
859 - *
860 800 * @return void
861 801 */
862 802 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
863 803 $form = self::get_form_for_js_validation( $field );
864 -
865 804 if ( false === $form ) {
866 805 return;
867 806 }
868 807
869 808 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
870 -
871 - if ( false === $error_body ) {
872 - return;
809 + if ( false !== $error_body ) {
810 + $error_body = urlencode( $error_body );
811 + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
873 812 }
874 -
875 - $error_body = urlencode( $error_body );
876 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
877 813 }
878 814
879 815 /**
880 816 * @since 5.0.03
@@ -879,24 +815,20 @@
879 815 /**
880 816 * @since 5.0.03
881 817 *
882 818 * @param array $field
883 - *
884 819 * @return false|stdClass false if there is no form object found with JS validation active.
885 820 */
886 821 private static function get_form_for_js_validation( $field ) {
887 822 global $frm_vars;
888 -
889 823 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
890 824 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
891 825 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
892 826 }
893 -
894 827 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
895 828 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
896 829 }
897 830 }
898 -
899 831 return false;
900 832 }
901 833
902 834 /**
@@ -902,9 +834,8 @@
902 834 /**
903 835 * @param stdClass $form
904 836 * @param array $field
905 837 * @param array $errors
906 - *
907 838 * @return false|string
908 839 */
909 840 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
910 841 if ( empty( $field['custom_html'] ) ) {
@@ -912,16 +843,15 @@
912 843 }
913 844
914 845 $custom_html = $field['custom_html'];
915 846 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
916 - $start = strpos( $custom_html, '[if error]' );
917 847
848 + $start = strpos( $custom_html, '[if error]' );
918 849 if ( false === $start ) {
919 850 return false;
920 851 }
921 852
922 853 $end = strpos( $custom_html, '[/if error]' );
923 -
924 854 if ( false === $end || $end < $start ) {
925 855 return false;
926 856 }
927 857
@@ -932,9 +862,13 @@
932 862 '<div class="frm_error">[error]</div>',
933 863 '<div class="frm_error" role="alert">[error]</div>',
934 864 );
935 865
936 - return in_array( $error_body, $default_html, true ) ? false : $error_body;
866 + if ( in_array( $error_body, $default_html, true ) ) {
867 + return false;
868 + }
869 +
870 + return $error_body;
937 871 }
938 872
939 873 /**
940 874 * If 'required' is added to a conditionally hidden field, the form won't
@@ -941,16 +875,13 @@
941 875 * submit in many browsers. Check to make sure the javascript to conditionally
942 876 * remove it is present if needed.
943 877 *
944 878 * @since 3.06.01
945 - *
946 879 * @param array $field
947 880 * @param array $add_html
948 - *
949 881 * @return void
950 882 */
951 883 private static function maybe_add_html_required( $field, array &$add_html ) {
952 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
953 884 $excluded_field_types =
954 885 FrmField::is_radio( $field ) ||
955 886 FrmField::is_checkbox( $field ) ||
956 887 FrmField::is_field_type( $field, 'file' ) ||
@@ -955,9 +886,8 @@
955 886 FrmField::is_checkbox( $field ) ||
956 887 FrmField::is_field_type( $field, 'file' ) ||
957 888 FrmField::is_field_type( $field, 'nps' ) ||
958 889 FrmField::is_field_type( $field, 'scale' );
959 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
960 890
961 891 if ( $excluded_field_types ) {
962 892 return;
963 893 }
@@ -967,9 +897,8 @@
967 897
968 898 /**
969 899 * @param array $field
970 900 * @param array $add_html
971 - *
972 901 * @return void
973 902 */
974 903 private static function add_shortcodes_to_html( $field, array &$add_html ) {
975 904 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -980,11 +909,10 @@
980 909 unset( $field['shortcodes']['autocomplete'] );
981 910 }
982 911
983 912 foreach ( $field['shortcodes'] as $k => $v ) {
984 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
913 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
985 914 $subfield_name = $field['subfield_name'];
986 -
987 915 if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
988 916 continue;
989 917 }
990 918 // 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,14 +919,13 @@
991 919 $k = 'aria-invalid';
992 920 $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
993 921 unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
994 922 }
995 -
996 923 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
997 924 continue;
998 925 }
999 926
1000 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
927 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1001 928 $add_html[] = $v;
1002 929 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1003 930 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1004 931 } else {
@@ -1014,9 +941,8 @@
1014 941 *
1015 942 * @since 6.11.2
1016 943 *
1017 944 * @param string $key The option key.
1018 - *
1019 945 * @return bool
1020 946 */
1021 947 private static function should_allow_input_attribute( $key ) {
1022 948 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1031,39 +957,28 @@
1031 957 * @since 3.0
1032 958 *
1033 959 * @param array $field
1034 960 * @param array $add_html
1035 - *
1036 961 * @return void
1037 962 */
1038 963 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 );
964 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1041 965 $format_field = FrmField::is_field_type( $field, 'text' );
1042 966
1043 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1044 - return;
967 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
968 + $format = FrmEntryValidate::phone_format( $field );
969 + $format = substr( $format, 2, - 1 );
970 +
971 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1045 972 }
1046 -
1047 - $format = FrmEntryValidate::phone_format( $field );
1048 - $format = substr( $format, 2, - 1 );
1049 -
1050 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1051 973 }
1052 974
1053 - /**
1054 - * @param mixed $opt
1055 - * @param mixed $opt_key
1056 - * @param array|object $field
1057 - *
1058 - * @return mixed
1059 - */
1060 975 public static function check_value( $opt, $opt_key, $field ) {
1061 976 if ( is_array( $opt ) ) {
1062 977 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1063 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
978 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1064 979 } else {
1065 - $opt = $opt['label'] ?? reset( $opt );
980 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1066 981 }
1067 982 }
1068 983
1069 984 return $opt;
@@ -1068,13 +983,12 @@
1068 983
1069 984 return $opt;
1070 985 }
1071 986
1072 - /**
1073 - * @param mixed $opt
1074 - *
1075 - * @return mixed
1076 - */
1077 987 public static function check_label( $opt ) {
1078 - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt;
988 + if ( is_array( $opt ) ) {
989 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
990 + }
991 +
992 + return $opt;
1079 993 }
1080 994 }