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