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