PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.24
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.24
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 +68 -253 6.316.24 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();
@@ -72,9 +71,9 @@
72 71 do_action( 'frm_before_create_field', $field_type, $form_id );
73 72
74 73 $field = self::include_new_field( $field_type, $form_id, $field_options );
75 74
76 - // This hook will allow for multiple fields to be added at once
75 + // this hook will allow for multiple fields to be added at once
77 76 do_action( 'frm_after_field_created', $field, $form_id );
78 77
79 78 wp_die();
80 79 }
@@ -90,9 +89,9 @@
90 89 */
91 90 public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
92 91 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
93 92
94 - if ( $field_options ) {
93 + if ( ! empty( $field_options ) ) {
95 94 $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
96 95 }
97 96
98 97 // When a new field is added to the form, flag it as draft and hide it from the front-end.
@@ -107,15 +106,15 @@
107 106 if ( ! $field_id ) {
108 107 return false;
109 108 }
110 109
111 - $field = self::get_field_array_from_id( $field_id );
110 + $field = self::get_field_array_from_id( $field_id );
111 +
112 112 $values = array();
113 -
114 113 if ( FrmAppHelper::pro_is_installed() ) {
115 114 $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 115
116 + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
118 117 if ( $parent_form_id ) {
119 118 $field['parent_form_id'] = $parent_form_id;
120 119 }
121 120 }
@@ -128,10 +127,11 @@
128 127 public static function duplicate() {
129 128 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 129 check_ajax_referer( 'frm_ajax', 'nonce' );
131 130
132 - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
133 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
131 + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
132 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
133 +
134 134 $new_field = FrmField::duplicate_single_field( $field_id, $form_id );
135 135
136 136 if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) {
137 137 self::load_single_field( $new_field['field_id'], $new_field['values'] );
@@ -148,8 +148,9 @@
148 148 * @return array
149 149 */
150 150 public static function get_field_array_from_id( $field_id ) {
151 151 $field = FrmField::getOne( $field_id );
152 +
152 153 return FrmFieldsHelper::setup_edit_vars( $field );
153 154 }
154 155
155 156 /**
@@ -154,13 +155,11 @@
154 155
155 156 /**
156 157 * @since 3.0
157 158 *
158 - * @param array|int|object|string $field_object
159 - * @param array $values
160 - * @param int $form_id
161 - *
162 - * @return void
159 + * @param array|int|object $field_object
160 + * @param array $values
161 + * @param int $form_id
163 162 */
164 163 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
165 164 global $frm_vars;
166 165 $frm_vars['is_admin'] = true;
@@ -171,10 +170,11 @@
171 170 $field = $field_object;
172 171 $field_object = FrmField::getOne( $field['id'] );
173 172 }
174 173
175 - $field_obj = FrmFieldFactory::get_field_factory( $field_object );
176 - $display = self::display_field_options( array(), $field_obj );
174 + $field_obj = FrmFieldFactory::get_field_factory( $field_object );
175 + $display = self::display_field_options( array(), $field_obj );
176 +
177 177 $ajax_loading = ! empty( $values['ajax_load'] );
178 178 $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
179 179
180 180 if ( $ajax_loading && $ajax_this_field ) {
@@ -183,9 +183,9 @@
183 183 return;
184 184 }
185 185
186 186 if ( ! isset( $field ) && is_object( $field_object ) ) {
187 - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id;
187 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
188 188 $field = FrmFieldsHelper::setup_edit_vars( $field_object );
189 189 }
190 190
191 191 /**
@@ -210,9 +210,8 @@
210 210 *
211 211 * @param array $field
212 212 * @param array $display
213 213 * @param FrmFieldType $field_info
214 - *
215 214 * @return string
216 215 */
217 216 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
218 217 $li_classes = $field_info->form_builder_classes( $display['type'] );
@@ -224,9 +223,9 @@
224 223
225 224 $li_classes .= 'frmend';
226 225
227 226 if ( $field ) {
228 - return apply_filters( 'frm_build_field_class', $li_classes, $field );
227 + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
229 228 }
230 229
231 230 return $li_classes;
232 231 }
@@ -260,9 +259,8 @@
260 259 *
261 260 * @since 6.8.4
262 261 *
263 262 * @param array $bulk_edit_types
264 - *
265 263 * @return array
266 264 */
267 265 $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
268 266
@@ -270,19 +268,18 @@
270 268 return;
271 269 }
272 270
273 271 $field = FrmFieldsHelper::setup_edit_vars( $field );
272 + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
273 + $opts = explode( "\n", rtrim( $opts, "\n" ) );
274 + $opts = array_map( 'trim', $opts );
274 275
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 276 $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
280 277 $field['separate_value'] = $separate === 'true';
281 278
282 279 if ( $field['separate_value'] ) {
283 280 foreach ( $opts as $opt_key => $opt ) {
284 - if ( str_contains( $opt, '|' ) ) {
281 + if ( strpos( $opt, '|' ) !== false ) {
285 282 $vals = explode( '|', $opt );
286 283 $opts[ $opt_key ] = array(
287 284 'label' => trim( $vals[0] ),
288 285 'value' => trim( $vals[1] ),
@@ -293,11 +290,10 @@
293 290 }
294 291 }
295 292
296 293 // Keep other options after bulk update.
297 - if ( ! empty( $field['field_options']['other'] ) ) {
294 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
298 295 $other_array = array();
299 -
300 296 foreach ( $field['options'] as $opt_key => $opt ) {
301 297 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
302 298 $other_array[ $opt_key ] = $opt;
303 299 }
@@ -302,10 +298,9 @@
302 298 $other_array[ $opt_key ] = $opt;
303 299 }
304 300 unset( $opt_key, $opt );
305 301 }
306 -
307 - if ( $other_array ) {
302 + if ( ! empty( $other_array ) ) {
308 303 $opts = array_merge( $opts, $other_array );
309 304 }
310 305 }
311 306
@@ -319,9 +314,8 @@
319 314 /**
320 315 * @since 4.0
321 316 *
322 317 * @param array $atts - Includes field array, field_obj, display array, values array.
323 - *
324 318 * @return void
325 319 */
326 320 public static function load_single_field_settings( $atts ) {
327 321 $field = $atts['field'];
@@ -347,9 +341,9 @@
347 341 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
348 342 // Add fallback for an add-on field type that has been deactivated.
349 343 $all_field_types[ $field['type'] ] = array(
350 344 'name' => ucfirst( $field['type'] ),
351 - 'icon' => 'frmfont frm_pencil_icon',
345 + 'icon' => 'frm_icon_font frm_pencil_icon',
352 346 );
353 347 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
354 348 // Fallback for fields added in a more basic way.
355 349 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -355,9 +349,8 @@
355 349 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
356 350 }
357 351
358 352 $type_name = $all_field_types[ $field['type'] ]['name'];
359 -
360 353 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
361 354 $type_name = $all_field_types['divider|repeat']['name'];
362 355 }
363 356
@@ -368,79 +361,8 @@
368 361 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
369 362 $field['placeholder'] = implode( ', ', $field['placeholder'] );
370 363 }
371 364
372 - $pro_is_installed = FrmAppHelper::pro_is_installed();
373 -
374 - $unique_values_label_atts = array(
375 - 'for' => 'frm_uniq_field_' . $field['id'],
376 - 'class' => 'frm_help frm-mb-0',
377 - 'title' => __(
378 - 'Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\', then no one else will be allowed to enter the same name.',
379 - 'formidable'
380 - ),
381 - 'data-trigger' => 'hover',
382 - );
383 -
384 - $read_only_label_atts = array(
385 - 'for' => 'frm_read_only_field_' . $field['id'],
386 - 'class' => 'frm_help frm-mb-0',
387 - 'title' => __( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ),
388 - 'data-trigger' => 'hover',
389 - );
390 -
391 - if ( ! $pro_is_installed ) {
392 - $visibility_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
393 - array(
394 - 'id' => 'field_options_admin_only_' . $field['id'],
395 - 'readonly' => '1',
396 - ),
397 - 'field_visibility',
398 - __( 'Visibility options', 'formidable' ),
399 - '/field-options/#kb-visibility'
400 - );
401 -
402 - $autocomplete_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
403 - array( 'id' => 'field_options_autocomplete_' . $field['id'] ),
404 - 'autocomplete',
405 - __( 'Autocomplete options', 'formidable' ),
406 - '/email-address/#kb-autocomplete-attribute'
407 - );
408 -
409 - $before_after_content_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
410 - array(
411 - 'type' => 'text',
412 - 'readonly' => '1',
413 - ),
414 - 'before_after_contents',
415 - __( 'Before and after field contents', 'formidable' ),
416 - '/field-options/#kb-before-after-input'
417 - );
418 -
419 - $show_upsell_for_unique_value = in_array(
420 - $field['type'],
421 - array( 'address', 'checkbox', 'email', 'name', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ),
422 - true
423 - );
424 - $show_upsell_for_read_only = in_array( $field['type'], array( 'email', 'hidden', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), true );
425 - $show_upsell_for_before_after_contents = in_array( $field['type'], array( 'email', 'number', 'phone', 'quantity', 'select', 'tag', 'text', 'total', 'url' ), true );
426 - $show_upsell_for_autocomplete = in_array( $field['type'], array( 'text', 'email', 'number' ), true );
427 - $show_upsell_for_visibility = $field['type'] !== 'hidden';
428 -
429 - $unique_values_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
430 - $unique_values_label_atts,
431 - 'unique_values',
432 - __( 'Unique Values', 'formidable' ),
433 - '/field-options/#kb-unique'
434 - );
435 - $read_only_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
436 - $read_only_label_atts,
437 - 'read_only',
438 - __( 'Read Only Values', 'formidable' ),
439 - '/field-options/#kb-read-only'
440 - );
441 - }//end if
442 -
443 365 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
444 366 }
445 367
446 368 /**
@@ -461,9 +383,8 @@
461 383 * @since 4.0
462 384 *
463 385 * @param array $field
464 386 * @param array $atts
465 - *
466 387 * @return array
467 388 */
468 389 private static function default_value_types( $field, $atts ) {
469 390 $types = array(
@@ -468,9 +389,9 @@
468 389 private static function default_value_types( $field, $atts ) {
469 390 $types = array(
470 391 'default_value' => array(
471 392 'class' => '',
472 - 'icon' => 'frmfont frm_text2_icon',
393 + 'icon' => 'frm_icon_font frm_text2_icon',
473 394 'title' => __( 'Default Value', 'formidable' ),
474 395 'data' => array(
475 396 'frmshow' => '#default-value-for-',
476 397 ),
@@ -477,9 +398,9 @@
477 398 ),
478 399 'calc' => array(
479 400 'class' => 'frm_show_upgrade frm_noallow',
480 401 'title' => __( 'Calculate Value', 'formidable' ),
481 - 'icon' => 'frmfont frm_calculator_icon',
402 + 'icon' => 'frm_icon_font frm_calculator_icon',
482 403 'data' => array(
483 404 'medium' => 'calculations',
484 405 'upgrade' => __( 'Calculator forms', 'formidable' ),
485 406 ),
@@ -487,9 +408,9 @@
487 408 ),
488 409 'get_values_field' => array(
489 410 'class' => 'frm_show_upgrade frm_noallow',
490 411 'title' => __( 'Lookup', 'formidable' ),
491 - 'icon' => 'frmfont frm_search_icon',
412 + 'icon' => 'frm_icon_font frm_search_icon',
492 413 'data' => array(
493 414 'medium' => 'lookup',
494 415 'upgrade' => __( 'Lookup fields', 'formidable' ),
495 416 ),
@@ -518,9 +439,8 @@
518 439 }
519 440
520 441 /**
521 442 * @param string $type
522 - *
523 443 * @return string
524 444 */
525 445 public static function change_type( $type ) {
526 446 $type_switch = array(
@@ -530,9 +450,8 @@
530 450 'rte' => 'textarea',
531 451 'website' => 'url',
532 452 'image' => 'url',
533 453 );
534 -
535 454 if ( isset( $type_switch[ $type ] ) ) {
536 455 $type = $type_switch[ $type ];
537 456 }
538 457
@@ -538,11 +457,15 @@
538 457
539 458 $pro_fields = FrmField::pro_field_selection();
540 459 // We want to keep credit_card types as credit card types for Stripe Lite.
541 460 // The credit_card key is set for backward compatibility.
542 - FrmField::remove_moved_field_types_from_pro( $pro_fields );
461 + unset( $pro_fields['credit_card'] );
543 462
544 - return array_key_exists( $type, $pro_fields ) ? 'text' : $type;
463 + if ( array_key_exists( $type, $pro_fields ) ) {
464 + $type = 'text';
465 + }
466 +
467 + return $type;
545 468 }
546 469
547 470 /**
548 471 * @param array $settings
@@ -567,9 +490,8 @@
567 490 * @since 3.0
568 491 *
569 492 * @param array $field Field data.
570 493 * @param bool $is_hidden Whether the format option should be hidden.
571 - *
572 494 * @return void
573 495 */
574 496 public static function show_format_option( $field, $is_hidden = false ) {
575 497 $attributes = array(
@@ -583,14 +505,8 @@
583 505
584 506 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
585 507 }
586 508
587 - /**
588 - * @param array $field
589 - * @param bool $echo
590 - *
591 - * @return string
592 - */
593 509 public static function input_html( $field, $echo = true ) {
594 510 $class = array();
595 511 self::add_input_classes( $field, $class );
596 512
@@ -605,9 +521,8 @@
605 521 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
606 522
607 523 self::add_shortcodes_to_html( $field, $add_html );
608 524 self::add_pattern_attribute( $field, $add_html );
609 - self::add_currency_field_attributes( $field, $add_html );
610 525
611 526 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
612 527 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
613 528
@@ -620,9 +535,8 @@
620 535
621 536 /**
622 537 * @param array $field
623 538 * @param array $class
624 - *
625 539 * @return void
626 540 */
627 541 private static function add_input_classes( $field, array &$class ) {
628 542 if ( ! empty( $field['input_class'] ) ) {
@@ -640,9 +554,8 @@
640 554
641 555 /**
642 556 * @param array $field
643 557 * @param array $add_html
644 - *
645 558 * @return void
646 559 */
647 560 private static function add_html_size( $field, array &$add_html ) {
648 561 $size_fields = array(
@@ -675,9 +588,8 @@
675 588
676 589 /**
677 590 * @param array $field
678 591 * @param array $add_html
679 - *
680 592 * @return void
681 593 */
682 594 private static function add_html_cols( $field, array &$add_html ) {
683 595 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -691,9 +603,9 @@
691 603 'rem' => 0.444,
692 604 'em' => 0.544,
693 605 );
694 606
695 - // Include "col" for valid html
607 + // include "col" for valid html
696 608 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
697 609
698 610 if ( ! isset( $calc[ $unit ] ) ) {
699 611 return;
@@ -698,9 +610,10 @@
698 610 if ( ! isset( $calc[ $unit ] ) ) {
699 611 return;
700 612 }
701 613
702 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
614 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
615 +
703 616 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
704 617 }
705 618
706 619 /**
@@ -705,9 +618,8 @@
705 618
706 619 /**
707 620 * @param array $field
708 621 * @param array $add_html
709 - *
710 622 * @return void
711 623 */
712 624 private static function add_html_length( $field, array &$add_html ) {
713 625 // Check for max setting and if this field accepts maxlength.
@@ -733,13 +645,11 @@
733 645 /**
734 646 * @param array $field
735 647 * @param array $add_html
736 648 * @param array $class
737 - *
738 649 * @return void
739 650 */
740 651 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
741 - // phpcs:ignore Universal.Operators.StrictComparisons
742 652 if ( $field['default_value'] != '' ) {
743 653 if ( is_array( $field['default_value'] ) ) {
744 654 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
745 655 } else {
@@ -747,12 +657,10 @@
747 657 }
748 658 }
749 659
750 660 $field['placeholder'] = self::prepare_placeholder( $field );
751 -
752 - // phpcs:ignore Universal.Operators.StrictComparisons
753 661 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
754 - // Don't include a json placeholder
662 + // don't include a json placeholder
755 663 return;
756 664 }
757 665
758 666 self::add_placeholder_to_input( $field, $add_html );
@@ -763,13 +671,14 @@
763 671 *
764 672 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
765 673 *
766 674 * @param array $field Field array.
767 - *
768 675 * @return string
769 676 */
770 677 private static function prepare_placeholder( $field ) {
771 - return $field['placeholder'] ?? '';
678 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
679 +
680 + return $placeholder;
772 681 }
773 682
774 683 /**
775 684 * If the label position is "inside",
@@ -790,17 +699,13 @@
790 699 * Maybe add a blank placeholder option before any options
791 700 * in a dropdown.
792 701 *
793 702 * @since 4.04
794 - *
795 - * @param array|object $field
796 - *
797 703 * @return bool True if placeholder was added.
798 704 */
799 705 public static function add_placeholder_to_select( $field ) {
800 706 $placeholder = FrmField::get_option( $field, 'placeholder' );
801 -
802 - if ( ! $placeholder ) {
707 + if ( empty( $placeholder ) ) {
803 708 $placeholder = self::get_default_value_from_name( $field );
804 709 }
805 710
806 711 $use_placeholder = $placeholder;
@@ -807,9 +712,8 @@
807 712 $autocomplete = FrmField::get_option( $field, 'autocom' );
808 713
809 714 if ( $autocomplete ) {
810 715 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
811 -
812 716 if ( $use_chosen ) {
813 717 $use_placeholder = '';
814 718 }
815 719 }
@@ -832,9 +736,8 @@
832 736 * Use HTML5 placeholder with js fallback.
833 737 *
834 738 * @param array $field
835 739 * @param array $add_html
836 - *
837 740 * @return void
838 741 */
839 742 private static function add_placeholder_to_input( $field, &$add_html ) {
840 743 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -844,13 +747,11 @@
844 747
845 748 /**
846 749 * @param array $field
847 750 * @param array $add_html
848 - *
849 751 * @return void
850 752 */
851 753 private static function add_frmval_to_input( $field, &$add_html ) {
852 - // phpcs:ignore Universal.Operators.StrictComparisons
853 754 if ( $field['placeholder'] != '' ) {
854 755 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
855 756
856 757 if ( 'select' === $field['type'] ) {
@@ -857,20 +758,13 @@
857 758 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
858 759 }
859 760 }
860 761
861 - // phpcs:ignore Universal.Operators.StrictComparisons
862 762 if ( $field['default_value'] != '' ) {
863 763 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
864 764 }
865 765 }
866 766
867 - /**
868 - * @param array $field
869 - * @param array $add_html
870 - *
871 - * @return void
872 - */
873 767 private static function add_validation_messages( $field, array &$add_html ) {
874 768 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
875 769
876 770 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -894,9 +788,8 @@
894 788 *
895 789 * @since 6.9
896 790 *
897 791 * @param array|object $field
898 - *
899 792 * @return array
900 793 */
901 794 private static function get_validation_data_attribute_visibility_info( $field ) {
902 795 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -926,26 +819,21 @@
926 819 * @since 5.0.03
927 820 *
928 821 * @param array $field
929 822 * @param array $add_html
930 - *
931 823 * @return void
932 824 */
933 825 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
934 826 $form = self::get_form_for_js_validation( $field );
935 -
936 827 if ( false === $form ) {
937 828 return;
938 829 }
939 830
940 831 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
941 -
942 - if ( false === $error_body ) {
943 - return;
832 + if ( false !== $error_body ) {
833 + $error_body = urlencode( $error_body );
834 + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
944 835 }
945 -
946 - $error_body = urlencode( $error_body );
947 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
948 836 }
949 837
950 838 /**
951 839 * @since 5.0.03
@@ -950,24 +838,20 @@
950 838 /**
951 839 * @since 5.0.03
952 840 *
953 841 * @param array $field
954 - *
955 842 * @return false|stdClass false if there is no form object found with JS validation active.
956 843 */
957 844 private static function get_form_for_js_validation( $field ) {
958 845 global $frm_vars;
959 -
960 846 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
961 847 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
962 848 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
963 849 }
964 -
965 850 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
966 851 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
967 852 }
968 853 }
969 -
970 854 return false;
971 855 }
972 856
973 857 /**
@@ -973,9 +857,8 @@
973 857 /**
974 858 * @param stdClass $form
975 859 * @param array $field
976 860 * @param array $errors
977 - *
978 861 * @return false|string
979 862 */
980 863 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
981 864 if ( empty( $field['custom_html'] ) ) {
@@ -983,16 +866,15 @@
983 866 }
984 867
985 868 $custom_html = $field['custom_html'];
986 869 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
987 - $start = strpos( $custom_html, '[if error]' );
988 870
871 + $start = strpos( $custom_html, '[if error]' );
989 872 if ( false === $start ) {
990 873 return false;
991 874 }
992 875
993 876 $end = strpos( $custom_html, '[/if error]' );
994 -
995 877 if ( false === $end || $end < $start ) {
996 878 return false;
997 879 }
998 880
@@ -1003,9 +885,13 @@
1003 885 '<div class="frm_error">[error]</div>',
1004 886 '<div class="frm_error" role="alert">[error]</div>',
1005 887 );
1006 888
1007 - return in_array( $error_body, $default_html, true ) ? false : $error_body;
889 + if ( in_array( $error_body, $default_html, true ) ) {
890 + return false;
891 + }
892 +
893 + return $error_body;
1008 894 }
1009 895
1010 896 /**
1011 897 * If 'required' is added to a conditionally hidden field, the form won't
@@ -1012,16 +898,13 @@
1012 898 * submit in many browsers. Check to make sure the javascript to conditionally
1013 899 * remove it is present if needed.
1014 900 *
1015 901 * @since 3.06.01
1016 - *
1017 902 * @param array $field
1018 903 * @param array $add_html
1019 - *
1020 904 * @return void
1021 905 */
1022 906 private static function maybe_add_html_required( $field, array &$add_html ) {
1023 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1024 907 $excluded_field_types =
1025 908 FrmField::is_radio( $field ) ||
1026 909 FrmField::is_checkbox( $field ) ||
1027 910 FrmField::is_field_type( $field, 'file' ) ||
@@ -1026,9 +909,8 @@
1026 909 FrmField::is_checkbox( $field ) ||
1027 910 FrmField::is_field_type( $field, 'file' ) ||
1028 911 FrmField::is_field_type( $field, 'nps' ) ||
1029 912 FrmField::is_field_type( $field, 'scale' );
1030 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1031 913
1032 914 if ( $excluded_field_types ) {
1033 915 return;
1034 916 }
@@ -1038,9 +920,8 @@
1038 920
1039 921 /**
1040 922 * @param array $field
1041 923 * @param array $add_html
1042 - *
1043 924 * @return void
1044 925 */
1045 926 private static function add_shortcodes_to_html( $field, array &$add_html ) {
1046 927 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -1051,11 +932,10 @@
1051 932 unset( $field['shortcodes']['autocomplete'] );
1052 933 }
1053 934
1054 935 foreach ( $field['shortcodes'] as $k => $v ) {
1055 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
936 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
1056 937 $subfield_name = $field['subfield_name'];
1057 -
1058 938 if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
1059 939 continue;
1060 940 }
1061 941 // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
@@ -1062,14 +942,13 @@
1062 942 $k = 'aria-invalid';
1063 943 $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1064 944 unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1065 945 }
1066 -
1067 946 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
1068 947 continue;
1069 948 }
1070 949
1071 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
950 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1072 951 $add_html[] = $v;
1073 952 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1074 953 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1075 954 } else {
@@ -1085,9 +964,8 @@
1085 964 *
1086 965 * @since 6.11.2
1087 966 *
1088 967 * @param string $key The option key.
1089 - *
1090 968 * @return bool
1091 969 */
1092 970 private static function should_allow_input_attribute( $key ) {
1093 971 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1102,9 +980,8 @@
1102 980 * @since 3.0
1103 981 *
1104 982 * @param array $field
1105 983 * @param array $add_html
1106 - *
1107 984 * @return void
1108 985 */
1109 986 private static function add_pattern_attribute( $field, array &$add_html ) {
1110 987 $format_value = FrmField::get_option( $field, 'format' );
@@ -1110,83 +987,22 @@
1110 987 $format_value = FrmField::get_option( $field, 'format' );
1111 988 $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
1112 989 $format_field = FrmField::is_field_type( $field, 'text' );
1113 990
1114 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1115 - return;
1116 - }
991 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
992 + $format = FrmEntryValidate::phone_format( $field );
993 + $format = substr( $format, 2, - 1 );
1117 994
1118 - $format = FrmEntryValidate::phone_format( $field );
1119 - $format = substr( $format, 2, - 1 );
1120 -
1121 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1122 - }
1123 -
1124 - /**
1125 - * Add product attributes to fields in multi-paged forms.
1126 - *
1127 - * @param array $field
1128 - * @param array $add_html
1129 - *
1130 - * @return void
1131 - */
1132 - private static function add_currency_field_attributes( $field, &$add_html ) {
1133 - $type = $field['original_type'] ?? $field['type'];
1134 - $is_product_field = in_array( $type, array( 'total', 'quantity', 'product' ), true );
1135 -
1136 - if ( ! $is_product_field ) {
1137 - return;
995 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1138 996 }
1139 -
1140 - if ( $type === 'total' ) {
1141 - $add_html['data-frmtotal'] = 'data-frmtotal';
1142 - } elseif ( $type === 'quantity' ) {
1143 - $product_field = FrmField::get_option( $field, 'product_field' );
1144 - $add_html['data-frmproduct'] = 'data-frmproduct="' . esc_attr( json_encode( $product_field ) ) . '"';
1145 - } elseif ( $type === 'product' && 'hidden' === $field['type'] ) {
1146 - // We want to do this only for fields that are hidden because it's
1147 - // not their page, hence the check : 'hidden' === $field['type'].
1148 - $price = empty( $field['value'] ) ? 0 : self::get_product_price( $field );
1149 -
1150 - $add_html['data-frmprice'] = 'data-frmprice="' . esc_attr( $price ) . '"';
1151 - }
1152 997 }
1153 998
1154 - /**
1155 - * @param array $field
1156 - */
1157 - private static function get_product_price( $field ) {
1158 - if ( is_array( $field['value'] ) ) {
1159 - // '' is unlikely though, let's just do it to prevent warnings
1160 - $value = isset( $field['opt_key'] ) && isset( $field['value'][ $field['opt_key'] ] )
1161 - ? $field['value'][ $field['opt_key'] ]
1162 - : '';
1163 - } else {
1164 - $value = $field['value'];
1165 - }
1166 -
1167 - $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
1168 -
1169 - if ( method_exists( $field_obj, 'get_posted_price' ) ) {
1170 - return $field_obj->get_posted_price( $value );
1171 - }
1172 -
1173 - return $value;
1174 - }
1175 -
1176 - /**
1177 - * @param mixed $opt
1178 - * @param mixed $opt_key
1179 - * @param array|object $field
1180 - *
1181 - * @return mixed
1182 - */
1183 999 public static function check_value( $opt, $opt_key, $field ) {
1184 1000 if ( is_array( $opt ) ) {
1185 1001 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1186 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
1002 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1187 1003 } else {
1188 - $opt = $opt['label'] ?? reset( $opt );
1004 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1189 1005 }
1190 1006 }
1191 1007
1192 1008 return $opt;
@@ -1191,13 +1007,12 @@
1191 1007
1192 1008 return $opt;
1193 1009 }
1194 1010
1195 - /**
1196 - * @param mixed $opt
1197 - *
1198 - * @return mixed
1199 - */
1200 1011 public static function check_label( $opt ) {
1201 - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt;
1012 + if ( is_array( $opt ) ) {
1013 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1014 + }
1015 +
1016 + return $opt;
1202 1017 }
1203 1018 }