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