PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.12
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.12
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 +96 -349 6.326.12 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 86 * @return array|false
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';
@@ -210,9 +193,8 @@
210 193 *
211 194 * @param array $field
212 195 * @param array $display
213 196 * @param FrmFieldType $field_info
214 - *
215 197 * @return string
216 198 */
217 199 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
218 200 $li_classes = $field_info->form_builder_classes( $display['type'] );
@@ -217,14 +199,8 @@
217 199 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
218 200 $li_classes = $field_info->form_builder_classes( $display['type'] );
219 201 $li_classes .= ' frm_form_field frmstart ';
220 202
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 203 if ( isset( $field['classes'] ) ) {
228 204 $li_classes .= trim( $field['classes'] ) . ' ';
229 205 }
230 206
@@ -230,45 +206,14 @@
230 206
231 207 $li_classes .= 'frmend';
232 208
233 209 if ( $field ) {
234 - return apply_filters( 'frm_build_field_class', $li_classes, $field );
210 + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
235 211 }
236 212
237 213 return $li_classes;
238 214 }
239 215
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 216 public static function destroy() {
272 217 FrmAppHelper::permission_check( 'frm_edit_forms' );
273 218 check_ajax_referer( 'frm_ajax', 'nonce' );
274 219
@@ -297,9 +242,8 @@
297 242 *
298 243 * @since 6.8.4
299 244 *
300 245 * @param array $bulk_edit_types
301 - *
302 246 * @return array
303 247 */
304 248 $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
305 249
@@ -307,19 +251,18 @@
307 251 return;
308 252 }
309 253
310 254 $field = FrmFieldsHelper::setup_edit_vars( $field );
255 + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
256 + $opts = explode( "\n", rtrim( $opts, "\n" ) );
257 + $opts = array_map( 'trim', $opts );
311 258
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 259 $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
317 260 $field['separate_value'] = $separate === 'true';
318 261
319 262 if ( $field['separate_value'] ) {
320 263 foreach ( $opts as $opt_key => $opt ) {
321 - if ( str_contains( $opt, '|' ) ) {
264 + if ( strpos( $opt, '|' ) !== false ) {
322 265 $vals = explode( '|', $opt );
323 266 $opts[ $opt_key ] = array(
324 267 'label' => trim( $vals[0] ),
325 268 'value' => trim( $vals[1] ),
@@ -330,11 +273,10 @@
330 273 }
331 274 }
332 275
333 276 // Keep other options after bulk update.
334 - if ( ! empty( $field['field_options']['other'] ) ) {
277 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
335 278 $other_array = array();
336 -
337 279 foreach ( $field['options'] as $opt_key => $opt ) {
338 280 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
339 281 $other_array[ $opt_key ] = $opt;
340 282 }
@@ -339,10 +281,9 @@
339 281 $other_array[ $opt_key ] = $opt;
340 282 }
341 283 unset( $opt_key, $opt );
342 284 }
343 -
344 - if ( $other_array ) {
285 + if ( ! empty( $other_array ) ) {
345 286 $opts = array_merge( $opts, $other_array );
346 287 }
347 288 }
348 289
@@ -356,9 +297,8 @@
356 297 /**
357 298 * @since 4.0
358 299 *
359 300 * @param array $atts - Includes field array, field_obj, display array, values array.
360 - *
361 301 * @return void
362 302 */
363 303 public static function load_single_field_settings( $atts ) {
364 304 $field = $atts['field'];
@@ -384,9 +324,9 @@
384 324 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
385 325 // Add fallback for an add-on field type that has been deactivated.
386 326 $all_field_types[ $field['type'] ] = array(
387 327 'name' => ucfirst( $field['type'] ),
388 - 'icon' => 'frmfont frm_pencil_icon',
328 + 'icon' => 'frm_icon_font frm_pencil_icon',
389 329 );
390 330 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
391 331 // Fallback for fields added in a more basic way.
392 332 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -392,9 +332,8 @@
392 332 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
393 333 }
394 334
395 335 $type_name = $all_field_types[ $field['type'] ]['name'];
396 -
397 336 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
398 337 $type_name = $all_field_types['divider|repeat']['name'];
399 338 }
400 339
@@ -405,79 +344,8 @@
405 344 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
406 345 $field['placeholder'] = implode( ', ', $field['placeholder'] );
407 346 }
408 347
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 348 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
481 349 }
482 350
483 351 /**
@@ -498,9 +366,8 @@
498 366 * @since 4.0
499 367 *
500 368 * @param array $field
501 369 * @param array $atts
502 - *
503 370 * @return array
504 371 */
505 372 private static function default_value_types( $field, $atts ) {
506 373 $types = array(
@@ -505,33 +372,31 @@
505 372 private static function default_value_types( $field, $atts ) {
506 373 $types = array(
507 374 'default_value' => array(
508 375 'class' => '',
509 - 'icon' => 'frmfont frm_text2_icon',
510 - 'title' => __( 'Default Value', 'formidable' ),
376 + 'icon' => 'frm_icon_font frm_text2_icon',
377 + 'title' => __( 'Default Value (Text)', 'formidable' ),
511 378 'data' => array(
512 379 'frmshow' => '#default-value-for-',
513 380 ),
514 381 ),
515 382 'calc' => array(
516 - 'class' => 'frm_show_upgrade frm_noallow',
517 - 'title' => __( 'Calculate Value', 'formidable' ),
518 - 'icon' => 'frmfont frm_calculator_icon',
519 - 'data' => array(
383 + 'class' => 'frm_show_upgrade frm_noallow',
384 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
385 + 'icon' => 'frm_icon_font frm_calculator_icon',
386 + 'data' => array(
520 387 'medium' => 'calculations',
521 388 'upgrade' => __( 'Calculator forms', 'formidable' ),
522 389 ),
523 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
524 390 ),
525 391 'get_values_field' => array(
526 - 'class' => 'frm_show_upgrade frm_noallow',
527 - 'title' => __( 'Lookup', 'formidable' ),
528 - 'icon' => 'frmfont frm_search_icon',
529 - 'data' => array(
392 + 'class' => 'frm_show_upgrade frm_noallow',
393 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
394 + 'icon' => 'frm_icon_font frm_search_icon',
395 + 'data' => array(
530 396 'medium' => 'lookup',
531 397 'upgrade' => __( 'Lookup fields', 'formidable' ),
532 398 ),
533 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
534 399 ),
535 400 );
536 401
537 402 $types = apply_filters( 'frm_default_value_types', $types, $atts );
@@ -539,13 +404,11 @@
539 404 // Set active class.
540 405 $settings = array_keys( $types );
541 406 $active = 'default_value';
542 407
543 - if ( FrmAppHelper::pro_is_connected() ) {
544 - foreach ( $settings as $type ) {
545 - if ( ! empty( $field[ $type ] ) ) {
546 - $active = $type;
547 - }
408 + foreach ( $settings as $type ) {
409 + if ( ! empty( $field[ $type ] ) ) {
410 + $active = $type;
548 411 }
549 412 }
550 413
551 414 $types[ $active ]['class'] .= ' current';
@@ -555,9 +418,8 @@
555 418 }
556 419
557 420 /**
558 421 * @param string $type
559 - *
560 422 * @return string
561 423 */
562 424 public static function change_type( $type ) {
563 425 $type_switch = array(
@@ -567,9 +429,8 @@
567 429 'rte' => 'textarea',
568 430 'website' => 'url',
569 431 'image' => 'url',
570 432 );
571 -
572 433 if ( isset( $type_switch[ $type ] ) ) {
573 434 $type = $type_switch[ $type ];
574 435 }
575 436
@@ -575,24 +436,26 @@
575 436
576 437 $pro_fields = FrmField::pro_field_selection();
577 438 // We want to keep credit_card types as credit card types for Stripe Lite.
578 439 // The credit_card key is set for backward compatibility.
579 - FrmField::remove_moved_field_types_from_pro( $pro_fields );
440 + unset( $pro_fields['credit_card'] );
580 441
581 - return array_key_exists( $type, $pro_fields ) ? 'text' : $type;
442 + if ( array_key_exists( $type, $pro_fields ) ) {
443 + $type = 'text';
444 + }
445 +
446 + return $type;
582 447 }
583 448
584 449 /**
585 - * @param array $settings
586 - * @param FrmFieldType|null $field_info
450 + * @param array $settings
451 + * @param object|null $field_info
587 452 *
588 453 * @return array
589 454 */
590 455 public static function display_field_options( $settings, $field_info = null ) {
591 456 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.
457 + $settings = $field_info->display_field_settings();
595 458 $settings['field_data'] = $field_info->field;
596 459 }
597 460
598 461 return apply_filters( 'frm_display_field_options', $settings );
@@ -602,20 +465,17 @@
602 465 * Display the format option
603 466 *
604 467 * @since 3.0
605 468 *
606 - * @param array $field Field data.
607 - * @param bool $is_hidden Whether the format option should be hidden.
608 - *
469 + * @param array $field
609 470 * @return void
610 471 */
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 - );
472 + public static function show_format_option( $field ) {
473 + $attributes = array();
474 + $attributes['class'] = 'frm-has-modal';
616 475
617 - if ( $is_hidden ) {
476 + if ( 'phone' === $field['type'] ) {
477 + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id'];
618 478 $attributes['class'] .= ' frm_hidden';
619 479 }
620 480
621 481 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
@@ -620,14 +480,8 @@
620 480
621 481 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
622 482 }
623 483
624 - /**
625 - * @param array $field
626 - * @param bool $echo
627 - *
628 - * @return string
629 - */
630 484 public static function input_html( $field, $echo = true ) {
631 485 $class = array();
632 486 self::add_input_classes( $field, $class );
633 487
@@ -642,9 +496,8 @@
642 496 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
643 497
644 498 self::add_shortcodes_to_html( $field, $add_html );
645 499 self::add_pattern_attribute( $field, $add_html );
646 - self::add_currency_field_attributes( $field, $add_html );
647 500
648 501 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
649 502 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
650 503
@@ -657,9 +510,8 @@
657 510
658 511 /**
659 512 * @param array $field
660 513 * @param array $class
661 - *
662 514 * @return void
663 515 */
664 516 private static function add_input_classes( $field, array &$class ) {
665 517 if ( ! empty( $field['input_class'] ) ) {
@@ -677,9 +529,8 @@
677 529
678 530 /**
679 531 * @param array $field
680 532 * @param array $add_html
681 - *
682 533 * @return void
683 534 */
684 535 private static function add_html_size( $field, array &$add_html ) {
685 536 $size_fields = array(
@@ -712,9 +563,8 @@
712 563
713 564 /**
714 565 * @param array $field
715 566 * @param array $add_html
716 - *
717 567 * @return void
718 568 */
719 569 private static function add_html_cols( $field, array &$add_html ) {
720 570 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -728,9 +578,9 @@
728 578 'rem' => 0.444,
729 579 'em' => 0.544,
730 580 );
731 581
732 - // Include "col" for valid html
582 + // include "col" for valid html
733 583 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
734 584
735 585 if ( ! isset( $calc[ $unit ] ) ) {
736 586 return;
@@ -735,9 +585,10 @@
735 585 if ( ! isset( $calc[ $unit ] ) ) {
736 586 return;
737 587 }
738 588
739 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
589 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
590 +
740 591 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
741 592 }
742 593
743 594 /**
@@ -742,9 +593,8 @@
742 593
743 594 /**
744 595 * @param array $field
745 596 * @param array $add_html
746 - *
747 597 * @return void
748 598 */
749 599 private static function add_html_length( $field, array &$add_html ) {
750 600 // Check for max setting and if this field accepts maxlength.
@@ -770,13 +620,11 @@
770 620 /**
771 621 * @param array $field
772 622 * @param array $add_html
773 623 * @param array $class
774 - *
775 624 * @return void
776 625 */
777 626 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
778 - // phpcs:ignore Universal.Operators.StrictComparisons
779 627 if ( $field['default_value'] != '' ) {
780 628 if ( is_array( $field['default_value'] ) ) {
781 629 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
782 630 } else {
@@ -784,12 +632,10 @@
784 632 }
785 633 }
786 634
787 635 $field['placeholder'] = self::prepare_placeholder( $field );
788 -
789 - // phpcs:ignore Universal.Operators.StrictComparisons
790 636 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
791 - // Don't include a json placeholder
637 + // don't include a json placeholder
792 638 return;
793 639 }
794 640
795 641 self::add_placeholder_to_input( $field, $add_html );
@@ -800,13 +646,14 @@
800 646 *
801 647 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
802 648 *
803 649 * @param array $field Field array.
804 - *
805 650 * @return string
806 651 */
807 652 private static function prepare_placeholder( $field ) {
808 - return $field['placeholder'] ?? '';
653 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
654 +
655 + return $placeholder;
809 656 }
810 657
811 658 /**
812 659 * If the label position is "inside",
@@ -827,17 +674,13 @@
827 674 * Maybe add a blank placeholder option before any options
828 675 * in a dropdown.
829 676 *
830 677 * @since 4.04
831 - *
832 - * @param array|object $field
833 - *
834 678 * @return bool True if placeholder was added.
835 679 */
836 680 public static function add_placeholder_to_select( $field ) {
837 681 $placeholder = FrmField::get_option( $field, 'placeholder' );
838 -
839 - if ( ! $placeholder ) {
682 + if ( empty( $placeholder ) ) {
840 683 $placeholder = self::get_default_value_from_name( $field );
841 684 }
842 685
843 686 $use_placeholder = $placeholder;
@@ -844,9 +687,8 @@
844 687 $autocomplete = FrmField::get_option( $field, 'autocom' );
845 688
846 689 if ( $autocomplete ) {
847 690 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
848 -
849 691 if ( $use_chosen ) {
850 692 $use_placeholder = '';
851 693 }
852 694 }
@@ -857,8 +699,13 @@
857 699 'value' => '',
858 700 'data-placeholder' => 'true',
859 701 );
860 702
703 + if ( $autocomplete && empty( $use_chosen ) ) {
704 + // This is required for Slim Select.
705 + $placeholder_attributes['data-placeholder'] = 'true';
706 + }
707 +
861 708 FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
862 709 return true;
863 710 }
864 711
@@ -869,9 +716,8 @@
869 716 * Use HTML5 placeholder with js fallback.
870 717 *
871 718 * @param array $field
872 719 * @param array $add_html
873 - *
874 720 * @return void
875 721 */
876 722 private static function add_placeholder_to_input( $field, &$add_html ) {
877 723 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -881,13 +727,11 @@
881 727
882 728 /**
883 729 * @param array $field
884 730 * @param array $add_html
885 - *
886 731 * @return void
887 732 */
888 733 private static function add_frmval_to_input( $field, &$add_html ) {
889 - // phpcs:ignore Universal.Operators.StrictComparisons
890 734 if ( $field['placeholder'] != '' ) {
891 735 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
892 736
893 737 if ( 'select' === $field['type'] ) {
@@ -894,20 +738,13 @@
894 738 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
895 739 }
896 740 }
897 741
898 - // phpcs:ignore Universal.Operators.StrictComparisons
899 742 if ( $field['default_value'] != '' ) {
900 743 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
901 744 }
902 745 }
903 746
904 - /**
905 - * @param array $field
906 - * @param array $add_html
907 - *
908 - * @return void
909 - */
910 747 private static function add_validation_messages( $field, array &$add_html ) {
911 748 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
912 749
913 750 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -931,9 +768,8 @@
931 768 *
932 769 * @since 6.9
933 770 *
934 771 * @param array|object $field
935 - *
936 772 * @return array
937 773 */
938 774 private static function get_validation_data_attribute_visibility_info( $field ) {
939 775 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -963,26 +799,21 @@
963 799 * @since 5.0.03
964 800 *
965 801 * @param array $field
966 802 * @param array $add_html
967 - *
968 803 * @return void
969 804 */
970 805 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
971 806 $form = self::get_form_for_js_validation( $field );
972 -
973 807 if ( false === $form ) {
974 808 return;
975 809 }
976 810
977 811 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
978 -
979 - if ( false === $error_body ) {
980 - return;
812 + if ( false !== $error_body ) {
813 + $error_body = urlencode( $error_body );
814 + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
981 815 }
982 -
983 - $error_body = urlencode( $error_body );
984 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
985 816 }
986 817
987 818 /**
988 819 * @since 5.0.03
@@ -987,24 +818,20 @@
987 818 /**
988 819 * @since 5.0.03
989 820 *
990 821 * @param array $field
991 - *
992 822 * @return false|stdClass false if there is no form object found with JS validation active.
993 823 */
994 824 private static function get_form_for_js_validation( $field ) {
995 825 global $frm_vars;
996 -
997 826 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
998 827 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
999 828 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
1000 829 }
1001 -
1002 830 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
1003 831 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
1004 832 }
1005 833 }
1006 -
1007 834 return false;
1008 835 }
1009 836
1010 837 /**
@@ -1010,9 +837,8 @@
1010 837 /**
1011 838 * @param stdClass $form
1012 839 * @param array $field
1013 840 * @param array $errors
1014 - *
1015 841 * @return false|string
1016 842 */
1017 843 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
1018 844 if ( empty( $field['custom_html'] ) ) {
@@ -1020,16 +846,15 @@
1020 846 }
1021 847
1022 848 $custom_html = $field['custom_html'];
1023 849 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
1024 - $start = strpos( $custom_html, '[if error]' );
1025 850
851 + $start = strpos( $custom_html, '[if error]' );
1026 852 if ( false === $start ) {
1027 853 return false;
1028 854 }
1029 855
1030 856 $end = strpos( $custom_html, '[/if error]' );
1031 -
1032 857 if ( false === $end || $end < $start ) {
1033 858 return false;
1034 859 }
1035 860
@@ -1040,9 +865,13 @@
1040 865 '<div class="frm_error">[error]</div>',
1041 866 '<div class="frm_error" role="alert">[error]</div>',
1042 867 );
1043 868
1044 - return in_array( $error_body, $default_html, true ) ? false : $error_body;
869 + if ( in_array( $error_body, $default_html, true ) ) {
870 + return false;
871 + }
872 +
873 + return $error_body;
1045 874 }
1046 875
1047 876 /**
1048 877 * If 'required' is added to a conditionally hidden field, the form won't
@@ -1049,16 +878,13 @@
1049 878 * submit in many browsers. Check to make sure the javascript to conditionally
1050 879 * remove it is present if needed.
1051 880 *
1052 881 * @since 3.06.01
1053 - *
1054 882 * @param array $field
1055 883 * @param array $add_html
1056 - *
1057 884 * @return void
1058 885 */
1059 886 private static function maybe_add_html_required( $field, array &$add_html ) {
1060 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1061 887 $excluded_field_types =
1062 888 FrmField::is_radio( $field ) ||
1063 889 FrmField::is_checkbox( $field ) ||
1064 890 FrmField::is_field_type( $field, 'file' ) ||
@@ -1063,9 +889,8 @@
1063 889 FrmField::is_checkbox( $field ) ||
1064 890 FrmField::is_field_type( $field, 'file' ) ||
1065 891 FrmField::is_field_type( $field, 'nps' ) ||
1066 892 FrmField::is_field_type( $field, 'scale' );
1067 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1068 893
1069 894 if ( $excluded_field_types ) {
1070 895 return;
1071 896 }
@@ -1075,9 +900,8 @@
1075 900
1076 901 /**
1077 902 * @param array $field
1078 903 * @param array $add_html
1079 - *
1080 904 * @return void
1081 905 */
1082 906 private static function add_shortcodes_to_html( $field, array &$add_html ) {
1083 907 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -1088,25 +912,13 @@
1088 912 unset( $field['shortcodes']['autocomplete'] );
1089 913 }
1090 914
1091 915 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 916 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
1105 917 continue;
1106 918 }
1107 919
1108 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
920 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1109 921 $add_html[] = $v;
1110 922 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1111 923 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1112 924 } else {
@@ -1113,9 +925,9 @@
1113 925 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1114 926 }
1115 927
1116 928 unset( $k, $v );
1117 - }//end foreach
929 + }
1118 930 }
1119 931
1120 932 /**
1121 933 * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
@@ -1122,9 +934,8 @@
1122 934 *
1123 935 * @since 6.11.2
1124 936 *
1125 937 * @param string $key The option key.
1126 - *
1127 938 * @return bool
1128 939 */
1129 940 private static function should_allow_input_attribute( $key ) {
1130 941 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1139,91 +950,28 @@
1139 950 * @since 3.0
1140 951 *
1141 952 * @param array $field
1142 953 * @param array $add_html
1143 - *
1144 954 * @return void
1145 955 */
1146 956 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 );
957 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1149 958 $format_field = FrmField::is_field_type( $field, 'text' );
1150 959
1151 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1152 - return;
1153 - }
960 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
961 + $format = FrmEntryValidate::phone_format( $field );
962 + $format = substr( $format, 2, - 1 );
1154 963
1155 - $format = FrmEntryValidate::phone_format( $field );
1156 - $format = substr( $format, 2, - 1 );
1157 -
1158 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1159 - }
1160 -
1161 - /**
1162 - * Add product attributes to fields in multi-paged forms.
1163 - *
1164 - * @param array $field
1165 - * @param array $add_html
1166 - *
1167 - * @return void
1168 - */
1169 - private static function add_currency_field_attributes( $field, &$add_html ) {
1170 - $type = $field['original_type'] ?? $field['type'];
1171 - $is_product_field = in_array( $type, array( 'total', 'quantity', 'product' ), true );
1172 -
1173 - if ( ! $is_product_field ) {
1174 - return;
964 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1175 965 }
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 966 }
1190 967
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 968 public static function check_value( $opt, $opt_key, $field ) {
1221 969 if ( is_array( $opt ) ) {
1222 970 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1223 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
971 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1224 972 } else {
1225 - $opt = $opt['label'] ?? reset( $opt );
973 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1226 974 }
1227 975 }
1228 976
1229 977 return $opt;
@@ -1228,13 +976,12 @@
1228 976
1229 977 return $opt;
1230 978 }
1231 979
1232 - /**
1233 - * @param mixed $opt
1234 - *
1235 - * @return mixed
1236 - */
1237 980 public static function check_label( $opt ) {
1238 - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt;
981 + if ( is_array( $opt ) ) {
982 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
983 + }
984 +
985 + return $opt;
1239 986 }
1240 987 }