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