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