PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.23
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.23
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 +78 -304 6.336.23 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,33 +389,31 @@
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',
510 - 'title' => __( 'Default Value', 'formidable' ),
393 + 'icon' => 'frm_icon_font frm_text2_icon',
394 + 'title' => __( 'Default Value (Text)', 'formidable' ),
511 395 'data' => array(
512 396 'frmshow' => '#default-value-for-',
513 397 ),
514 398 ),
515 399 'calc' => array(
516 - 'class' => 'frm_show_upgrade frm_noallow',
517 - 'title' => __( 'Calculate Value', 'formidable' ),
518 - 'icon' => 'frmfont frm_calculator_icon',
519 - 'data' => array(
400 + 'class' => 'frm_show_upgrade frm_noallow',
401 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
402 + 'icon' => 'frm_icon_font frm_calculator_icon',
403 + 'data' => array(
520 404 'medium' => 'calculations',
521 405 'upgrade' => __( 'Calculator forms', 'formidable' ),
522 406 ),
523 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
524 407 ),
525 408 'get_values_field' => array(
526 - 'class' => 'frm_show_upgrade frm_noallow',
527 - 'title' => __( 'Lookup', 'formidable' ),
528 - 'icon' => 'frmfont frm_search_icon',
529 - 'data' => array(
409 + 'class' => 'frm_show_upgrade frm_noallow',
410 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
411 + 'icon' => 'frm_icon_font frm_search_icon',
412 + 'data' => array(
530 413 'medium' => 'lookup',
531 414 'upgrade' => __( 'Lookup fields', 'formidable' ),
532 415 ),
533 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
534 416 ),
535 417 );
536 418
537 419 $types = apply_filters( 'frm_default_value_types', $types, $atts );
@@ -539,13 +421,11 @@
539 421 // Set active class.
540 422 $settings = array_keys( $types );
541 423 $active = 'default_value';
542 424
543 - if ( FrmAppHelper::pro_is_connected() ) {
544 - foreach ( $settings as $type ) {
545 - if ( ! empty( $field[ $type ] ) ) {
546 - $active = $type;
547 - }
425 + foreach ( $settings as $type ) {
426 + if ( ! empty( $field[ $type ] ) ) {
427 + $active = $type;
548 428 }
549 429 }
550 430
551 431 $types[ $active ]['class'] .= ' current';
@@ -555,9 +435,8 @@
555 435 }
556 436
557 437 /**
558 438 * @param string $type
559 - *
560 439 * @return string
561 440 */
562 441 public static function change_type( $type ) {
563 442 $type_switch = array(
@@ -567,9 +446,8 @@
567 446 'rte' => 'textarea',
568 447 'website' => 'url',
569 448 'image' => 'url',
570 449 );
571 -
572 450 if ( isset( $type_switch[ $type ] ) ) {
573 451 $type = $type_switch[ $type ];
574 452 }
575 453
@@ -575,11 +453,15 @@
575 453
576 454 $pro_fields = FrmField::pro_field_selection();
577 455 // We want to keep credit_card types as credit card types for Stripe Lite.
578 456 // The credit_card key is set for backward compatibility.
579 - FrmField::remove_moved_field_types_from_pro( $pro_fields );
457 + unset( $pro_fields['credit_card'] );
580 458
581 - return array_key_exists( $type, $pro_fields ) ? 'text' : $type;
459 + if ( array_key_exists( $type, $pro_fields ) ) {
460 + $type = 'text';
461 + }
462 +
463 + return $type;
582 464 }
583 465
584 466 /**
585 467 * @param array $settings
@@ -604,9 +486,8 @@
604 486 * @since 3.0
605 487 *
606 488 * @param array $field Field data.
607 489 * @param bool $is_hidden Whether the format option should be hidden.
608 - *
609 490 * @return void
610 491 */
611 492 public static function show_format_option( $field, $is_hidden = false ) {
612 493 $attributes = array(
@@ -620,14 +501,8 @@
620 501
621 502 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
622 503 }
623 504
624 - /**
625 - * @param array $field
626 - * @param bool $echo
627 - *
628 - * @return string
629 - */
630 505 public static function input_html( $field, $echo = true ) {
631 506 $class = array();
632 507 self::add_input_classes( $field, $class );
633 508
@@ -642,9 +517,8 @@
642 517 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
643 518
644 519 self::add_shortcodes_to_html( $field, $add_html );
645 520 self::add_pattern_attribute( $field, $add_html );
646 - self::add_currency_field_attributes( $field, $add_html );
647 521
648 522 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
649 523 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
650 524
@@ -657,9 +531,8 @@
657 531
658 532 /**
659 533 * @param array $field
660 534 * @param array $class
661 - *
662 535 * @return void
663 536 */
664 537 private static function add_input_classes( $field, array &$class ) {
665 538 if ( ! empty( $field['input_class'] ) ) {
@@ -677,9 +550,8 @@
677 550
678 551 /**
679 552 * @param array $field
680 553 * @param array $add_html
681 - *
682 554 * @return void
683 555 */
684 556 private static function add_html_size( $field, array &$add_html ) {
685 557 $size_fields = array(
@@ -712,9 +584,8 @@
712 584
713 585 /**
714 586 * @param array $field
715 587 * @param array $add_html
716 - *
717 588 * @return void
718 589 */
719 590 private static function add_html_cols( $field, array &$add_html ) {
720 591 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -728,9 +599,9 @@
728 599 'rem' => 0.444,
729 600 'em' => 0.544,
730 601 );
731 602
732 - // Include "col" for valid html
603 + // include "col" for valid html
733 604 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
734 605
735 606 if ( ! isset( $calc[ $unit ] ) ) {
736 607 return;
@@ -735,9 +606,10 @@
735 606 if ( ! isset( $calc[ $unit ] ) ) {
736 607 return;
737 608 }
738 609
739 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
610 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
611 +
740 612 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
741 613 }
742 614
743 615 /**
@@ -742,9 +614,8 @@
742 614
743 615 /**
744 616 * @param array $field
745 617 * @param array $add_html
746 - *
747 618 * @return void
748 619 */
749 620 private static function add_html_length( $field, array &$add_html ) {
750 621 // Check for max setting and if this field accepts maxlength.
@@ -770,13 +641,11 @@
770 641 /**
771 642 * @param array $field
772 643 * @param array $add_html
773 644 * @param array $class
774 - *
775 645 * @return void
776 646 */
777 647 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
778 - // phpcs:ignore Universal.Operators.StrictComparisons
779 648 if ( $field['default_value'] != '' ) {
780 649 if ( is_array( $field['default_value'] ) ) {
781 650 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
782 651 } else {
@@ -784,12 +653,10 @@
784 653 }
785 654 }
786 655
787 656 $field['placeholder'] = self::prepare_placeholder( $field );
788 -
789 - // phpcs:ignore Universal.Operators.StrictComparisons
790 657 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
791 - // Don't include a json placeholder
658 + // don't include a json placeholder
792 659 return;
793 660 }
794 661
795 662 self::add_placeholder_to_input( $field, $add_html );
@@ -800,13 +667,14 @@
800 667 *
801 668 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
802 669 *
803 670 * @param array $field Field array.
804 - *
805 671 * @return string
806 672 */
807 673 private static function prepare_placeholder( $field ) {
808 - return $field['placeholder'] ?? '';
674 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
675 +
676 + return $placeholder;
809 677 }
810 678
811 679 /**
812 680 * If the label position is "inside",
@@ -827,17 +695,13 @@
827 695 * Maybe add a blank placeholder option before any options
828 696 * in a dropdown.
829 697 *
830 698 * @since 4.04
831 - *
832 - * @param array|object $field
833 - *
834 699 * @return bool True if placeholder was added.
835 700 */
836 701 public static function add_placeholder_to_select( $field ) {
837 702 $placeholder = FrmField::get_option( $field, 'placeholder' );
838 -
839 - if ( ! $placeholder ) {
703 + if ( empty( $placeholder ) ) {
840 704 $placeholder = self::get_default_value_from_name( $field );
841 705 }
842 706
843 707 $use_placeholder = $placeholder;
@@ -844,9 +708,8 @@
844 708 $autocomplete = FrmField::get_option( $field, 'autocom' );
845 709
846 710 if ( $autocomplete ) {
847 711 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
848 -
849 712 if ( $use_chosen ) {
850 713 $use_placeholder = '';
851 714 }
852 715 }
@@ -869,9 +732,8 @@
869 732 * Use HTML5 placeholder with js fallback.
870 733 *
871 734 * @param array $field
872 735 * @param array $add_html
873 - *
874 736 * @return void
875 737 */
876 738 private static function add_placeholder_to_input( $field, &$add_html ) {
877 739 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -881,13 +743,11 @@
881 743
882 744 /**
883 745 * @param array $field
884 746 * @param array $add_html
885 - *
886 747 * @return void
887 748 */
888 749 private static function add_frmval_to_input( $field, &$add_html ) {
889 - // phpcs:ignore Universal.Operators.StrictComparisons
890 750 if ( $field['placeholder'] != '' ) {
891 751 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
892 752
893 753 if ( 'select' === $field['type'] ) {
@@ -894,20 +754,13 @@
894 754 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
895 755 }
896 756 }
897 757
898 - // phpcs:ignore Universal.Operators.StrictComparisons
899 758 if ( $field['default_value'] != '' ) {
900 759 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
901 760 }
902 761 }
903 762
904 - /**
905 - * @param array $field
906 - * @param array $add_html
907 - *
908 - * @return void
909 - */
910 763 private static function add_validation_messages( $field, array &$add_html ) {
911 764 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
912 765
913 766 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -931,9 +784,8 @@
931 784 *
932 785 * @since 6.9
933 786 *
934 787 * @param array|object $field
935 - *
936 788 * @return array
937 789 */
938 790 private static function get_validation_data_attribute_visibility_info( $field ) {
939 791 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -963,26 +815,21 @@
963 815 * @since 5.0.03
964 816 *
965 817 * @param array $field
966 818 * @param array $add_html
967 - *
968 819 * @return void
969 820 */
970 821 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
971 822 $form = self::get_form_for_js_validation( $field );
972 -
973 823 if ( false === $form ) {
974 824 return;
975 825 }
976 826
977 827 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
978 -
979 - if ( false === $error_body ) {
980 - return;
828 + if ( false !== $error_body ) {
829 + $error_body = urlencode( $error_body );
830 + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
981 831 }
982 -
983 - $error_body = urlencode( $error_body );
984 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
985 832 }
986 833
987 834 /**
988 835 * @since 5.0.03
@@ -987,24 +834,20 @@
987 834 /**
988 835 * @since 5.0.03
989 836 *
990 837 * @param array $field
991 - *
992 838 * @return false|stdClass false if there is no form object found with JS validation active.
993 839 */
994 840 private static function get_form_for_js_validation( $field ) {
995 841 global $frm_vars;
996 -
997 842 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
998 843 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
999 844 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
1000 845 }
1001 -
1002 846 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
1003 847 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
1004 848 }
1005 849 }
1006 -
1007 850 return false;
1008 851 }
1009 852
1010 853 /**
@@ -1010,9 +853,8 @@
1010 853 /**
1011 854 * @param stdClass $form
1012 855 * @param array $field
1013 856 * @param array $errors
1014 - *
1015 857 * @return false|string
1016 858 */
1017 859 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
1018 860 if ( empty( $field['custom_html'] ) ) {
@@ -1020,16 +862,15 @@
1020 862 }
1021 863
1022 864 $custom_html = $field['custom_html'];
1023 865 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
1024 - $start = strpos( $custom_html, '[if error]' );
1025 866
867 + $start = strpos( $custom_html, '[if error]' );
1026 868 if ( false === $start ) {
1027 869 return false;
1028 870 }
1029 871
1030 872 $end = strpos( $custom_html, '[/if error]' );
1031 -
1032 873 if ( false === $end || $end < $start ) {
1033 874 return false;
1034 875 }
1035 876
@@ -1040,9 +881,13 @@
1040 881 '<div class="frm_error">[error]</div>',
1041 882 '<div class="frm_error" role="alert">[error]</div>',
1042 883 );
1043 884
1044 - return in_array( $error_body, $default_html, true ) ? false : $error_body;
885 + if ( in_array( $error_body, $default_html, true ) ) {
886 + return false;
887 + }
888 +
889 + return $error_body;
1045 890 }
1046 891
1047 892 /**
1048 893 * If 'required' is added to a conditionally hidden field, the form won't
@@ -1049,16 +894,13 @@
1049 894 * submit in many browsers. Check to make sure the javascript to conditionally
1050 895 * remove it is present if needed.
1051 896 *
1052 897 * @since 3.06.01
1053 - *
1054 898 * @param array $field
1055 899 * @param array $add_html
1056 - *
1057 900 * @return void
1058 901 */
1059 902 private static function maybe_add_html_required( $field, array &$add_html ) {
1060 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1061 903 $excluded_field_types =
1062 904 FrmField::is_radio( $field ) ||
1063 905 FrmField::is_checkbox( $field ) ||
1064 906 FrmField::is_field_type( $field, 'file' ) ||
@@ -1063,9 +905,8 @@
1063 905 FrmField::is_checkbox( $field ) ||
1064 906 FrmField::is_field_type( $field, 'file' ) ||
1065 907 FrmField::is_field_type( $field, 'nps' ) ||
1066 908 FrmField::is_field_type( $field, 'scale' );
1067 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1068 909
1069 910 if ( $excluded_field_types ) {
1070 911 return;
1071 912 }
@@ -1075,9 +916,8 @@
1075 916
1076 917 /**
1077 918 * @param array $field
1078 919 * @param array $add_html
1079 - *
1080 920 * @return void
1081 921 */
1082 922 private static function add_shortcodes_to_html( $field, array &$add_html ) {
1083 923 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -1088,11 +928,10 @@
1088 928 unset( $field['shortcodes']['autocomplete'] );
1089 929 }
1090 930
1091 931 foreach ( $field['shortcodes'] as $k => $v ) {
1092 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
932 + if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
1093 933 $subfield_name = $field['subfield_name'];
1094 -
1095 934 if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
1096 935 continue;
1097 936 }
1098 937 // 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 +938,13 @@
1099 938 $k = 'aria-invalid';
1100 939 $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1101 940 unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1102 941 }
1103 -
1104 942 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
1105 943 continue;
1106 944 }
1107 945
1108 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
946 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1109 947 $add_html[] = $v;
1110 948 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1111 949 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1112 950 } else {
@@ -1122,9 +960,8 @@
1122 960 *
1123 961 * @since 6.11.2
1124 962 *
1125 963 * @param string $key The option key.
1126 - *
1127 964 * @return bool
1128 965 */
1129 966 private static function should_allow_input_attribute( $key ) {
1130 967 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1139,9 +976,8 @@
1139 976 * @since 3.0
1140 977 *
1141 978 * @param array $field
1142 979 * @param array $add_html
1143 - *
1144 980 * @return void
1145 981 */
1146 982 private static function add_pattern_attribute( $field, array &$add_html ) {
1147 983 $format_value = FrmField::get_option( $field, 'format' );
@@ -1147,83 +983,22 @@
1147 983 $format_value = FrmField::get_option( $field, 'format' );
1148 984 $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
1149 985 $format_field = FrmField::is_field_type( $field, 'text' );
1150 986
1151 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1152 - return;
1153 - }
987 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
988 + $format = FrmEntryValidate::phone_format( $field );
989 + $format = substr( $format, 2, - 1 );
1154 990
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;
991 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1175 992 }
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 993 }
1190 994
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 995 public static function check_value( $opt, $opt_key, $field ) {
1221 996 if ( is_array( $opt ) ) {
1222 997 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1223 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
998 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1224 999 } else {
1225 - $opt = $opt['label'] ?? reset( $opt );
1000 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1226 1001 }
1227 1002 }
1228 1003
1229 1004 return $opt;
@@ -1228,13 +1003,12 @@
1228 1003
1229 1004 return $opt;
1230 1005 }
1231 1006
1232 - /**
1233 - * @param mixed $opt
1234 - *
1235 - * @return mixed
1236 - */
1237 1007 public static function check_label( $opt ) {
1238 - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt;
1008 + if ( is_array( $opt ) ) {
1009 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1010 + }
1011 +
1012 + return $opt;
1239 1013 }
1240 1014 }