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 -290 6.336.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'] );
@@ -217,14 +216,8 @@
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'] );
219 218 $li_classes .= ' frm_form_field frmstart ';
220 219
221 - $style_align_class = self::get_builder_field_style_align_class( $field, $field_info );
222 -
223 - if ( $style_align_class ) {
224 - $li_classes .= $style_align_class . ' ';
225 - }
226 -
227 220 if ( isset( $field['classes'] ) ) {
228 221 $li_classes .= trim( $field['classes'] ) . ' ';
229 222 }
230 223
@@ -230,45 +223,14 @@
230 223
231 224 $li_classes .= 'frmend';
232 225
233 226 if ( $field ) {
234 - return apply_filters( 'frm_build_field_class', $li_classes, $field );
227 + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
235 228 }
236 229
237 230 return $li_classes;
238 231 }
239 232
240 - /**
241 - * Apply the active style alignment to a radio or checkbox builder preview on load.
242 - *
243 - * The per-field alignment setting only exists in Pro, so on load the style setting is
244 - * used. When the field has an explicit alignment (Pro), the frm_build_field_class filter
245 - * applies it instead. When Pro is not installed, any saved alignment is treated as empty.
246 - *
247 - * @since 6.32
248 - *
249 - * @param array $field
250 - * @param FrmFieldType $field_info
251 - *
252 - * @return string
253 - */
254 - private static function get_builder_field_style_align_class( $field, $field_info ) {
255 - if ( ! $field || ! is_array( $field ) || ( ! FrmField::is_radio( $field ) && ! FrmField::is_checkbox( $field ) ) ) {
256 - return '';
257 - }
258 -
259 - $align = FrmAppHelper::pro_is_installed() ? FrmField::get_option( $field, 'align' ) : '';
260 -
261 - if ( $align ) {
262 - return '';
263 - }
264 -
265 - $align = FrmStylesHelper::get_align_from_active_style( $field );
266 - $field_info->prepare_align_class( $align );
267 -
268 - return $align;
269 - }
270 -
271 233 public static function destroy() {
272 234 FrmAppHelper::permission_check( 'frm_edit_forms' );
273 235 check_ajax_referer( 'frm_ajax', 'nonce' );
274 236
@@ -297,9 +259,8 @@
297 259 *
298 260 * @since 6.8.4
299 261 *
300 262 * @param array $bulk_edit_types
301 - *
302 263 * @return array
303 264 */
304 265 $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
305 266
@@ -307,19 +268,18 @@
307 268 return;
308 269 }
309 270
310 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 );
311 275
312 - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
313 - $opts = explode( "\n", rtrim( $opts, "\n" ) );
314 - $opts = array_map( 'trim', $opts );
315 -
316 276 $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
317 277 $field['separate_value'] = $separate === 'true';
318 278
319 279 if ( $field['separate_value'] ) {
320 280 foreach ( $opts as $opt_key => $opt ) {
321 - if ( str_contains( $opt, '|' ) ) {
281 + if ( strpos( $opt, '|' ) !== false ) {
322 282 $vals = explode( '|', $opt );
323 283 $opts[ $opt_key ] = array(
324 284 'label' => trim( $vals[0] ),
325 285 'value' => trim( $vals[1] ),
@@ -330,11 +290,10 @@
330 290 }
331 291 }
332 292
333 293 // Keep other options after bulk update.
334 - if ( ! empty( $field['field_options']['other'] ) ) {
294 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
335 295 $other_array = array();
336 -
337 296 foreach ( $field['options'] as $opt_key => $opt ) {
338 297 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
339 298 $other_array[ $opt_key ] = $opt;
340 299 }
@@ -339,10 +298,9 @@
339 298 $other_array[ $opt_key ] = $opt;
340 299 }
341 300 unset( $opt_key, $opt );
342 301 }
343 -
344 - if ( $other_array ) {
302 + if ( ! empty( $other_array ) ) {
345 303 $opts = array_merge( $opts, $other_array );
346 304 }
347 305 }
348 306
@@ -356,9 +314,8 @@
356 314 /**
357 315 * @since 4.0
358 316 *
359 317 * @param array $atts - Includes field array, field_obj, display array, values array.
360 - *
361 318 * @return void
362 319 */
363 320 public static function load_single_field_settings( $atts ) {
364 321 $field = $atts['field'];
@@ -384,9 +341,9 @@
384 341 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
385 342 // Add fallback for an add-on field type that has been deactivated.
386 343 $all_field_types[ $field['type'] ] = array(
387 344 'name' => ucfirst( $field['type'] ),
388 - 'icon' => 'frmfont frm_pencil_icon',
345 + 'icon' => 'frm_icon_font frm_pencil_icon',
389 346 );
390 347 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
391 348 // Fallback for fields added in a more basic way.
392 349 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -392,9 +349,8 @@
392 349 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
393 350 }
394 351
395 352 $type_name = $all_field_types[ $field['type'] ]['name'];
396 -
397 353 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
398 354 $type_name = $all_field_types['divider|repeat']['name'];
399 355 }
400 356
@@ -405,79 +361,8 @@
405 361 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
406 362 $field['placeholder'] = implode( ', ', $field['placeholder'] );
407 363 }
408 364
409 - $pro_is_installed = FrmAppHelper::pro_is_installed();
410 -
411 - $unique_values_label_atts = array(
412 - 'for' => 'frm_uniq_field_' . $field['id'],
413 - 'class' => 'frm_help frm-mb-0',
414 - 'title' => __(
415 - '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.',
416 - 'formidable'
417 - ),
418 - 'data-trigger' => 'hover',
419 - );
420 -
421 - $read_only_label_atts = array(
422 - 'for' => 'frm_read_only_field_' . $field['id'],
423 - 'class' => 'frm_help frm-mb-0',
424 - 'title' => __( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ),
425 - 'data-trigger' => 'hover',
426 - );
427 -
428 - if ( ! $pro_is_installed ) {
429 - $visibility_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
430 - array(
431 - 'id' => 'field_options_admin_only_' . $field['id'],
432 - 'readonly' => '1',
433 - ),
434 - 'field_visibility',
435 - __( 'Visibility options', 'formidable' ),
436 - '/field-options/#kb-visibility'
437 - );
438 -
439 - $autocomplete_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
440 - array( 'id' => 'field_options_autocomplete_' . $field['id'] ),
441 - 'autocomplete',
442 - __( 'Autocomplete options', 'formidable' ),
443 - '/email-address/#kb-autocomplete-attribute'
444 - );
445 -
446 - $before_after_content_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
447 - array(
448 - 'type' => 'text',
449 - 'readonly' => '1',
450 - ),
451 - 'before_after_contents',
452 - __( 'Before and after field contents', 'formidable' ),
453 - '/field-options/#kb-before-after-input'
454 - );
455 -
456 - $show_upsell_for_unique_value = in_array(
457 - $field['type'],
458 - array( 'address', 'checkbox', 'email', 'name', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ),
459 - true
460 - );
461 - $show_upsell_for_read_only = in_array( $field['type'], array( 'email', 'hidden', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), true );
462 - $show_upsell_for_before_after_contents = in_array( $field['type'], array( 'email', 'number', 'phone', 'quantity', 'select', 'tag', 'text', 'total', 'url' ), true );
463 - $show_upsell_for_autocomplete = in_array( $field['type'], array( 'text', 'email', 'number' ), true );
464 - $show_upsell_for_visibility = $field['type'] !== 'hidden';
465 -
466 - $unique_values_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
467 - $unique_values_label_atts,
468 - 'unique_values',
469 - __( 'Unique Values', 'formidable' ),
470 - '/field-options/#kb-unique'
471 - );
472 - $read_only_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
473 - $read_only_label_atts,
474 - 'read_only',
475 - __( 'Read Only Values', 'formidable' ),
476 - '/field-options/#kb-read-only'
477 - );
478 - }//end if
479 -
480 365 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
481 366 }
482 367
483 368 /**
@@ -498,9 +383,8 @@
498 383 * @since 4.0
499 384 *
500 385 * @param array $field
501 386 * @param array $atts
502 - *
503 387 * @return array
504 388 */
505 389 private static function default_value_types( $field, $atts ) {
506 390 $types = array(
@@ -505,9 +389,9 @@
505 389 private static function default_value_types( $field, $atts ) {
506 390 $types = array(
507 391 'default_value' => array(
508 392 'class' => '',
509 - 'icon' => 'frmfont frm_text2_icon',
393 + 'icon' => 'frm_icon_font frm_text2_icon',
510 394 'title' => __( 'Default Value', 'formidable' ),
511 395 'data' => array(
512 396 'frmshow' => '#default-value-for-',
513 397 ),
@@ -514,9 +398,9 @@
514 398 ),
515 399 'calc' => array(
516 400 'class' => 'frm_show_upgrade frm_noallow',
517 401 'title' => __( 'Calculate Value', 'formidable' ),
518 - 'icon' => 'frmfont frm_calculator_icon',
402 + 'icon' => 'frm_icon_font frm_calculator_icon',
519 403 'data' => array(
520 404 'medium' => 'calculations',
521 405 'upgrade' => __( 'Calculator forms', 'formidable' ),
522 406 ),
@@ -524,9 +408,9 @@
524 408 ),
525 409 'get_values_field' => array(
526 410 'class' => 'frm_show_upgrade frm_noallow',
527 411 'title' => __( 'Lookup', 'formidable' ),
528 - 'icon' => 'frmfont frm_search_icon',
412 + 'icon' => 'frm_icon_font frm_search_icon',
529 413 'data' => array(
530 414 'medium' => 'lookup',
531 415 'upgrade' => __( 'Lookup fields', 'formidable' ),
532 416 ),
@@ -555,9 +439,8 @@
555 439 }
556 440
557 441 /**
558 442 * @param string $type
559 - *
560 443 * @return string
561 444 */
562 445 public static function change_type( $type ) {
563 446 $type_switch = array(
@@ -567,9 +450,8 @@
567 450 'rte' => 'textarea',
568 451 'website' => 'url',
569 452 'image' => 'url',
570 453 );
571 -
572 454 if ( isset( $type_switch[ $type ] ) ) {
573 455 $type = $type_switch[ $type ];
574 456 }
575 457
@@ -575,11 +457,15 @@
575 457
576 458 $pro_fields = FrmField::pro_field_selection();
577 459 // We want to keep credit_card types as credit card types for Stripe Lite.
578 460 // The credit_card key is set for backward compatibility.
579 - FrmField::remove_moved_field_types_from_pro( $pro_fields );
461 + unset( $pro_fields['credit_card'] );
580 462
581 - 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;
582 468 }
583 469
584 470 /**
585 471 * @param array $settings
@@ -604,9 +490,8 @@
604 490 * @since 3.0
605 491 *
606 492 * @param array $field Field data.
607 493 * @param bool $is_hidden Whether the format option should be hidden.
608 - *
609 494 * @return void
610 495 */
611 496 public static function show_format_option( $field, $is_hidden = false ) {
612 497 $attributes = array(
@@ -620,14 +505,8 @@
620 505
621 506 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
622 507 }
623 508
624 - /**
625 - * @param array $field
626 - * @param bool $echo
627 - *
628 - * @return string
629 - */
630 509 public static function input_html( $field, $echo = true ) {
631 510 $class = array();
632 511 self::add_input_classes( $field, $class );
633 512
@@ -642,9 +521,8 @@
642 521 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
643 522
644 523 self::add_shortcodes_to_html( $field, $add_html );
645 524 self::add_pattern_attribute( $field, $add_html );
646 - self::add_currency_field_attributes( $field, $add_html );
647 525
648 526 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
649 527 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
650 528
@@ -657,9 +535,8 @@
657 535
658 536 /**
659 537 * @param array $field
660 538 * @param array $class
661 - *
662 539 * @return void
663 540 */
664 541 private static function add_input_classes( $field, array &$class ) {
665 542 if ( ! empty( $field['input_class'] ) ) {
@@ -677,9 +554,8 @@
677 554
678 555 /**
679 556 * @param array $field
680 557 * @param array $add_html
681 - *
682 558 * @return void
683 559 */
684 560 private static function add_html_size( $field, array &$add_html ) {
685 561 $size_fields = array(
@@ -712,9 +588,8 @@
712 588
713 589 /**
714 590 * @param array $field
715 591 * @param array $add_html
716 - *
717 592 * @return void
718 593 */
719 594 private static function add_html_cols( $field, array &$add_html ) {
720 595 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -728,9 +603,9 @@
728 603 'rem' => 0.444,
729 604 'em' => 0.544,
730 605 );
731 606
732 - // Include "col" for valid html
607 + // include "col" for valid html
733 608 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
734 609
735 610 if ( ! isset( $calc[ $unit ] ) ) {
736 611 return;
@@ -735,9 +610,10 @@
735 610 if ( ! isset( $calc[ $unit ] ) ) {
736 611 return;
737 612 }
738 613
739 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
614 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
615 +
740 616 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
741 617 }
742 618
743 619 /**
@@ -742,9 +618,8 @@
742 618
743 619 /**
744 620 * @param array $field
745 621 * @param array $add_html
746 - *
747 622 * @return void
748 623 */
749 624 private static function add_html_length( $field, array &$add_html ) {
750 625 // Check for max setting and if this field accepts maxlength.
@@ -770,13 +645,11 @@
770 645 /**
771 646 * @param array $field
772 647 * @param array $add_html
773 648 * @param array $class
774 - *
775 649 * @return void
776 650 */
777 651 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
778 - // phpcs:ignore Universal.Operators.StrictComparisons
779 652 if ( $field['default_value'] != '' ) {
780 653 if ( is_array( $field['default_value'] ) ) {
781 654 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
782 655 } else {
@@ -784,12 +657,10 @@
784 657 }
785 658 }
786 659
787 660 $field['placeholder'] = self::prepare_placeholder( $field );
788 -
789 - // phpcs:ignore Universal.Operators.StrictComparisons
790 661 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
791 - // Don't include a json placeholder
662 + // don't include a json placeholder
792 663 return;
793 664 }
794 665
795 666 self::add_placeholder_to_input( $field, $add_html );
@@ -800,13 +671,14 @@
800 671 *
801 672 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
802 673 *
803 674 * @param array $field Field array.
804 - *
805 675 * @return string
806 676 */
807 677 private static function prepare_placeholder( $field ) {
808 - return $field['placeholder'] ?? '';
678 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
679 +
680 + return $placeholder;
809 681 }
810 682
811 683 /**
812 684 * If the label position is "inside",
@@ -827,17 +699,13 @@
827 699 * Maybe add a blank placeholder option before any options
828 700 * in a dropdown.
829 701 *
830 702 * @since 4.04
831 - *
832 - * @param array|object $field
833 - *
834 703 * @return bool True if placeholder was added.
835 704 */
836 705 public static function add_placeholder_to_select( $field ) {
837 706 $placeholder = FrmField::get_option( $field, 'placeholder' );
838 -
839 - if ( ! $placeholder ) {
707 + if ( empty( $placeholder ) ) {
840 708 $placeholder = self::get_default_value_from_name( $field );
841 709 }
842 710
843 711 $use_placeholder = $placeholder;
@@ -844,9 +712,8 @@
844 712 $autocomplete = FrmField::get_option( $field, 'autocom' );
845 713
846 714 if ( $autocomplete ) {
847 715 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
848 -
849 716 if ( $use_chosen ) {
850 717 $use_placeholder = '';
851 718 }
852 719 }
@@ -869,9 +736,8 @@
869 736 * Use HTML5 placeholder with js fallback.
870 737 *
871 738 * @param array $field
872 739 * @param array $add_html
873 - *
874 740 * @return void
875 741 */
876 742 private static function add_placeholder_to_input( $field, &$add_html ) {
877 743 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -881,13 +747,11 @@
881 747
882 748 /**
883 749 * @param array $field
884 750 * @param array $add_html
885 - *
886 751 * @return void
887 752 */
888 753 private static function add_frmval_to_input( $field, &$add_html ) {
889 - // phpcs:ignore Universal.Operators.StrictComparisons
890 754 if ( $field['placeholder'] != '' ) {
891 755 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
892 756
893 757 if ( 'select' === $field['type'] ) {
@@ -894,20 +758,13 @@
894 758 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
895 759 }
896 760 }
897 761
898 - // phpcs:ignore Universal.Operators.StrictComparisons
899 762 if ( $field['default_value'] != '' ) {
900 763 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
901 764 }
902 765 }
903 766
904 - /**
905 - * @param array $field
906 - * @param array $add_html
907 - *
908 - * @return void
909 - */
910 767 private static function add_validation_messages( $field, array &$add_html ) {
911 768 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
912 769
913 770 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -931,9 +788,8 @@
931 788 *
932 789 * @since 6.9
933 790 *
934 791 * @param array|object $field
935 - *
936 792 * @return array
937 793 */
938 794 private static function get_validation_data_attribute_visibility_info( $field ) {
939 795 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -963,26 +819,21 @@
963 819 * @since 5.0.03
964 820 *
965 821 * @param array $field
966 822 * @param array $add_html
967 - *
968 823 * @return void
969 824 */
970 825 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
971 826 $form = self::get_form_for_js_validation( $field );
972 -
973 827 if ( false === $form ) {
974 828 return;
975 829 }
976 830
977 831 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
978 -
979 - if ( false === $error_body ) {
980 - 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 ) . '"';
981 835 }
982 -
983 - $error_body = urlencode( $error_body );
984 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
985 836 }
986 837
987 838 /**
988 839 * @since 5.0.03
@@ -987,24 +838,20 @@
987 838 /**
988 839 * @since 5.0.03
989 840 *
990 841 * @param array $field
991 - *
992 842 * @return false|stdClass false if there is no form object found with JS validation active.
993 843 */
994 844 private static function get_form_for_js_validation( $field ) {
995 845 global $frm_vars;
996 -
997 846 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
998 847 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
999 848 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
1000 849 }
1001 -
1002 850 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
1003 851 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
1004 852 }
1005 853 }
1006 -
1007 854 return false;
1008 855 }
1009 856
1010 857 /**
@@ -1010,9 +857,8 @@
1010 857 /**
1011 858 * @param stdClass $form
1012 859 * @param array $field
1013 860 * @param array $errors
1014 - *
1015 861 * @return false|string
1016 862 */
1017 863 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
1018 864 if ( empty( $field['custom_html'] ) ) {
@@ -1020,16 +866,15 @@
1020 866 }
1021 867
1022 868 $custom_html = $field['custom_html'];
1023 869 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
1024 - $start = strpos( $custom_html, '[if error]' );
1025 870
871 + $start = strpos( $custom_html, '[if error]' );
1026 872 if ( false === $start ) {
1027 873 return false;
1028 874 }
1029 875
1030 876 $end = strpos( $custom_html, '[/if error]' );
1031 -
1032 877 if ( false === $end || $end < $start ) {
1033 878 return false;
1034 879 }
1035 880
@@ -1040,9 +885,13 @@
1040 885 '<div class="frm_error">[error]</div>',
1041 886 '<div class="frm_error" role="alert">[error]</div>',
1042 887 );
1043 888
1044 - 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;
1045 894 }
1046 895
1047 896 /**
1048 897 * If 'required' is added to a conditionally hidden field, the form won't
@@ -1049,16 +898,13 @@
1049 898 * submit in many browsers. Check to make sure the javascript to conditionally
1050 899 * remove it is present if needed.
1051 900 *
1052 901 * @since 3.06.01
1053 - *
1054 902 * @param array $field
1055 903 * @param array $add_html
1056 - *
1057 904 * @return void
1058 905 */
1059 906 private static function maybe_add_html_required( $field, array &$add_html ) {
1060 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1061 907 $excluded_field_types =
1062 908 FrmField::is_radio( $field ) ||
1063 909 FrmField::is_checkbox( $field ) ||
1064 910 FrmField::is_field_type( $field, 'file' ) ||
@@ -1063,9 +909,8 @@
1063 909 FrmField::is_checkbox( $field ) ||
1064 910 FrmField::is_field_type( $field, 'file' ) ||
1065 911 FrmField::is_field_type( $field, 'nps' ) ||
1066 912 FrmField::is_field_type( $field, 'scale' );
1067 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1068 913
1069 914 if ( $excluded_field_types ) {
1070 915 return;
1071 916 }
@@ -1075,9 +920,8 @@
1075 920
1076 921 /**
1077 922 * @param array $field
1078 923 * @param array $add_html
1079 - *
1080 924 * @return void
1081 925 */
1082 926 private static function add_shortcodes_to_html( $field, array &$add_html ) {
1083 927 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -1088,11 +932,10 @@
1088 932 unset( $field['shortcodes']['autocomplete'] );
1089 933 }
1090 934
1091 935 foreach ( $field['shortcodes'] as $k => $v ) {
1092 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
936 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
1093 937 $subfield_name = $field['subfield_name'];
1094 -
1095 938 if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
1096 939 continue;
1097 940 }
1098 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.
@@ -1099,14 +942,13 @@
1099 942 $k = 'aria-invalid';
1100 943 $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1101 944 unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1102 945 }
1103 -
1104 946 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
1105 947 continue;
1106 948 }
1107 949
1108 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
950 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1109 951 $add_html[] = $v;
1110 952 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1111 953 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1112 954 } else {
@@ -1122,9 +964,8 @@
1122 964 *
1123 965 * @since 6.11.2
1124 966 *
1125 967 * @param string $key The option key.
1126 - *
1127 968 * @return bool
1128 969 */
1129 970 private static function should_allow_input_attribute( $key ) {
1130 971 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1139,9 +980,8 @@
1139 980 * @since 3.0
1140 981 *
1141 982 * @param array $field
1142 983 * @param array $add_html
1143 - *
1144 984 * @return void
1145 985 */
1146 986 private static function add_pattern_attribute( $field, array &$add_html ) {
1147 987 $format_value = FrmField::get_option( $field, 'format' );
@@ -1147,83 +987,22 @@
1147 987 $format_value = FrmField::get_option( $field, 'format' );
1148 988 $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
1149 989 $format_field = FrmField::is_field_type( $field, 'text' );
1150 990
1151 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1152 - return;
1153 - }
991 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
992 + $format = FrmEntryValidate::phone_format( $field );
993 + $format = substr( $format, 2, - 1 );
1154 994
1155 - $format = FrmEntryValidate::phone_format( $field );
1156 - $format = substr( $format, 2, - 1 );
1157 -
1158 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1159 - }
1160 -
1161 - /**
1162 - * Add product attributes to fields in multi-paged forms.
1163 - *
1164 - * @param array $field
1165 - * @param array $add_html
1166 - *
1167 - * @return void
1168 - */
1169 - private static function add_currency_field_attributes( $field, &$add_html ) {
1170 - $type = $field['original_type'] ?? $field['type'];
1171 - $is_product_field = in_array( $type, array( 'total', 'quantity', 'product' ), true );
1172 -
1173 - if ( ! $is_product_field ) {
1174 - return;
995 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1175 996 }
1176 -
1177 - if ( $type === 'total' ) {
1178 - $add_html['data-frmtotal'] = 'data-frmtotal';
1179 - } elseif ( $type === 'quantity' ) {
1180 - $product_field = FrmField::get_option( $field, 'product_field' );
1181 - $add_html['data-frmproduct'] = 'data-frmproduct="' . esc_attr( json_encode( $product_field ) ) . '"';
1182 - } elseif ( $type === 'product' && 'hidden' === $field['type'] ) {
1183 - // We want to do this only for fields that are hidden because it's
1184 - // not their page, hence the check : 'hidden' === $field['type'].
1185 - $price = empty( $field['value'] ) ? 0 : self::get_product_price( $field );
1186 -
1187 - $add_html['data-frmprice'] = 'data-frmprice="' . esc_attr( $price ) . '"';
1188 - }
1189 997 }
1190 998
1191 - /**
1192 - * @param array $field
1193 - */
1194 - private static function get_product_price( $field ) {
1195 - if ( is_array( $field['value'] ) ) {
1196 - // '' is unlikely though, let's just do it to prevent warnings
1197 - $value = isset( $field['opt_key'] ) && isset( $field['value'][ $field['opt_key'] ] )
1198 - ? $field['value'][ $field['opt_key'] ]
1199 - : '';
1200 - } else {
1201 - $value = $field['value'];
1202 - }
1203 -
1204 - $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
1205 -
1206 - if ( method_exists( $field_obj, 'get_posted_price' ) ) {
1207 - return $field_obj->get_posted_price( $value );
1208 - }
1209 -
1210 - return $value;
1211 - }
1212 -
1213 - /**
1214 - * @param mixed $opt
1215 - * @param mixed $opt_key
1216 - * @param array|object $field
1217 - *
1218 - * @return mixed
1219 - */
1220 999 public static function check_value( $opt, $opt_key, $field ) {
1221 1000 if ( is_array( $opt ) ) {
1222 1001 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1223 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
1002 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1224 1003 } else {
1225 - $opt = $opt['label'] ?? reset( $opt );
1004 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1226 1005 }
1227 1006 }
1228 1007
1229 1008 return $opt;
@@ -1228,13 +1007,12 @@
1228 1007
1229 1008 return $opt;
1230 1009 }
1231 1010
1232 - /**
1233 - * @param mixed $opt
1234 - *
1235 - * @return mixed
1236 - */
1237 1011 public static function check_label( $opt ) {
1238 - 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;
1239 1017 }
1240 1018 }