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 +97 -353 6.346.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,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,24 +436,26 @@
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 - * @param array $settings
589 - * @param FrmFieldType|null $field_info
450 + * @param array $settings
451 + * @param object|null $field_info
590 452 *
591 453 * @return array
592 454 */
593 455 public static function display_field_options( $settings, $field_info = null ) {
594 456 if ( $field_info ) {
595 - $settings = $field_info->display_field_settings();
596 -
597 - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
457 + $settings = $field_info->display_field_settings();
598 458 $settings['field_data'] = $field_info->field;
599 459 }
600 460
601 461 return apply_filters( 'frm_display_field_options', $settings );
@@ -605,20 +465,17 @@
605 465 * Display the format option
606 466 *
607 467 * @since 3.0
608 468 *
609 - * @param array $field Field data.
610 - * @param bool $is_hidden Whether the format option should be hidden.
611 - *
469 + * @param array $field
612 470 * @return void
613 471 */
614 - public static function show_format_option( $field, $is_hidden = false ) {
615 - $attributes = array(
616 - 'class' => 'frm-has-modal',
617 - 'id' => 'frm-field-format-custom-' . $field['id'],
618 - );
472 + public static function show_format_option( $field ) {
473 + $attributes = array();
474 + $attributes['class'] = 'frm-has-modal';
619 475
620 - if ( $is_hidden ) {
476 + if ( 'phone' === $field['type'] ) {
477 + $attributes['id'] = 'frm-phone-field-custom-format-' . $field['id'];
621 478 $attributes['class'] .= ' frm_hidden';
622 479 }
623 480
624 481 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
@@ -623,14 +480,8 @@
623 480
624 481 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
625 482 }
626 483
627 - /**
628 - * @param array $field
629 - * @param bool $echo
630 - *
631 - * @return string
632 - */
633 484 public static function input_html( $field, $echo = true ) {
634 485 $class = array();
635 486 self::add_input_classes( $field, $class );
636 487
@@ -645,9 +496,8 @@
645 496 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
646 497
647 498 self::add_shortcodes_to_html( $field, $add_html );
648 499 self::add_pattern_attribute( $field, $add_html );
649 - self::add_currency_field_attributes( $field, $add_html );
650 500
651 501 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
652 502 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
653 503
@@ -660,9 +510,8 @@
660 510
661 511 /**
662 512 * @param array $field
663 513 * @param array $class
664 - *
665 514 * @return void
666 515 */
667 516 private static function add_input_classes( $field, array &$class ) {
668 517 if ( ! empty( $field['input_class'] ) ) {
@@ -680,9 +529,8 @@
680 529
681 530 /**
682 531 * @param array $field
683 532 * @param array $add_html
684 - *
685 533 * @return void
686 534 */
687 535 private static function add_html_size( $field, array &$add_html ) {
688 536 $size_fields = array(
@@ -715,9 +563,8 @@
715 563
716 564 /**
717 565 * @param array $field
718 566 * @param array $add_html
719 - *
720 567 * @return void
721 568 */
722 569 private static function add_html_cols( $field, array &$add_html ) {
723 570 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
@@ -731,9 +578,9 @@
731 578 'rem' => 0.444,
732 579 'em' => 0.544,
733 580 );
734 581
735 - // Include "col" for valid html
582 + // include "col" for valid html
736 583 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
737 584
738 585 if ( ! isset( $calc[ $unit ] ) ) {
739 586 return;
@@ -738,9 +585,10 @@
738 585 if ( ! isset( $calc[ $unit ] ) ) {
739 586 return;
740 587 }
741 588
742 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
589 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
590 +
743 591 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
744 592 }
745 593
746 594 /**
@@ -745,9 +593,8 @@
745 593
746 594 /**
747 595 * @param array $field
748 596 * @param array $add_html
749 - *
750 597 * @return void
751 598 */
752 599 private static function add_html_length( $field, array &$add_html ) {
753 600 // Check for max setting and if this field accepts maxlength.
@@ -773,13 +620,11 @@
773 620 /**
774 621 * @param array $field
775 622 * @param array $add_html
776 623 * @param array $class
777 - *
778 624 * @return void
779 625 */
780 626 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
781 - // phpcs:ignore Universal.Operators.StrictComparisons
782 627 if ( $field['default_value'] != '' ) {
783 628 if ( is_array( $field['default_value'] ) ) {
784 629 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
785 630 } else {
@@ -787,12 +632,10 @@
787 632 }
788 633 }
789 634
790 635 $field['placeholder'] = self::prepare_placeholder( $field );
791 -
792 - // phpcs:ignore Universal.Operators.StrictComparisons
793 636 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
794 - // Don't include a json placeholder
637 + // don't include a json placeholder
795 638 return;
796 639 }
797 640
798 641 self::add_placeholder_to_input( $field, $add_html );
@@ -803,13 +646,14 @@
803 646 *
804 647 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
805 648 *
806 649 * @param array $field Field array.
807 - *
808 650 * @return string
809 651 */
810 652 private static function prepare_placeholder( $field ) {
811 - return $field['placeholder'] ?? '';
653 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
654 +
655 + return $placeholder;
812 656 }
813 657
814 658 /**
815 659 * If the label position is "inside",
@@ -830,17 +674,13 @@
830 674 * Maybe add a blank placeholder option before any options
831 675 * in a dropdown.
832 676 *
833 677 * @since 4.04
834 - *
835 - * @param array|object $field
836 - *
837 678 * @return bool True if placeholder was added.
838 679 */
839 680 public static function add_placeholder_to_select( $field ) {
840 681 $placeholder = FrmField::get_option( $field, 'placeholder' );
841 -
842 - if ( ! $placeholder ) {
682 + if ( empty( $placeholder ) ) {
843 683 $placeholder = self::get_default_value_from_name( $field );
844 684 }
845 685
846 686 $use_placeholder = $placeholder;
@@ -847,9 +687,8 @@
847 687 $autocomplete = FrmField::get_option( $field, 'autocom' );
848 688
849 689 if ( $autocomplete ) {
850 690 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
851 -
852 691 if ( $use_chosen ) {
853 692 $use_placeholder = '';
854 693 }
855 694 }
@@ -860,8 +699,13 @@
860 699 'value' => '',
861 700 'data-placeholder' => 'true',
862 701 );
863 702
703 + if ( $autocomplete && empty( $use_chosen ) ) {
704 + // This is required for Slim Select.
705 + $placeholder_attributes['data-placeholder'] = 'true';
706 + }
707 +
864 708 FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
865 709 return true;
866 710 }
867 711
@@ -872,9 +716,8 @@
872 716 * Use HTML5 placeholder with js fallback.
873 717 *
874 718 * @param array $field
875 719 * @param array $add_html
876 - *
877 720 * @return void
878 721 */
879 722 private static function add_placeholder_to_input( $field, &$add_html ) {
880 723 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
@@ -884,13 +727,11 @@
884 727
885 728 /**
886 729 * @param array $field
887 730 * @param array $add_html
888 - *
889 731 * @return void
890 732 */
891 733 private static function add_frmval_to_input( $field, &$add_html ) {
892 - // phpcs:ignore Universal.Operators.StrictComparisons
893 734 if ( $field['placeholder'] != '' ) {
894 735 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
895 736
896 737 if ( 'select' === $field['type'] ) {
@@ -897,20 +738,13 @@
897 738 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
898 739 }
899 740 }
900 741
901 - // phpcs:ignore Universal.Operators.StrictComparisons
902 742 if ( $field['default_value'] != '' ) {
903 743 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
904 744 }
905 745 }
906 746
907 - /**
908 - * @param array $field
909 - * @param array $add_html
910 - *
911 - * @return void
912 - */
913 747 private static function add_validation_messages( $field, array &$add_html ) {
914 748 $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
915 749
916 750 if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
@@ -934,9 +768,8 @@
934 768 *
935 769 * @since 6.9
936 770 *
937 771 * @param array|object $field
938 - *
939 772 * @return array
940 773 */
941 774 private static function get_validation_data_attribute_visibility_info( $field ) {
942 775 if ( FrmField::get_field_type( $field ) === 'hidden' ) {
@@ -966,26 +799,21 @@
966 799 * @since 5.0.03
967 800 *
968 801 * @param array $field
969 802 * @param array $add_html
970 - *
971 803 * @return void
972 804 */
973 805 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
974 806 $form = self::get_form_for_js_validation( $field );
975 -
976 807 if ( false === $form ) {
977 808 return;
978 809 }
979 810
980 811 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
981 -
982 - if ( false === $error_body ) {
983 - 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 ) . '"';
984 815 }
985 -
986 - $error_body = urlencode( $error_body );
987 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
988 816 }
989 817
990 818 /**
991 819 * @since 5.0.03
@@ -990,24 +818,20 @@
990 818 /**
991 819 * @since 5.0.03
992 820 *
993 821 * @param array $field
994 - *
995 822 * @return false|stdClass false if there is no form object found with JS validation active.
996 823 */
997 824 private static function get_form_for_js_validation( $field ) {
998 825 global $frm_vars;
999 -
1000 826 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
1001 827 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
1002 828 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
1003 829 }
1004 -
1005 830 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
1006 831 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
1007 832 }
1008 833 }
1009 -
1010 834 return false;
1011 835 }
1012 836
1013 837 /**
@@ -1013,9 +837,8 @@
1013 837 /**
1014 838 * @param stdClass $form
1015 839 * @param array $field
1016 840 * @param array $errors
1017 - *
1018 841 * @return false|string
1019 842 */
1020 843 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
1021 844 if ( empty( $field['custom_html'] ) ) {
@@ -1023,16 +846,15 @@
1023 846 }
1024 847
1025 848 $custom_html = $field['custom_html'];
1026 849 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
1027 - $start = strpos( $custom_html, '[if error]' );
1028 850
851 + $start = strpos( $custom_html, '[if error]' );
1029 852 if ( false === $start ) {
1030 853 return false;
1031 854 }
1032 855
1033 856 $end = strpos( $custom_html, '[/if error]' );
1034 -
1035 857 if ( false === $end || $end < $start ) {
1036 858 return false;
1037 859 }
1038 860
@@ -1043,9 +865,13 @@
1043 865 '<div class="frm_error">[error]</div>',
1044 866 '<div class="frm_error" role="alert">[error]</div>',
1045 867 );
1046 868
1047 - 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;
1048 874 }
1049 875
1050 876 /**
1051 877 * If 'required' is added to a conditionally hidden field, the form won't
@@ -1052,16 +878,13 @@
1052 878 * submit in many browsers. Check to make sure the javascript to conditionally
1053 879 * remove it is present if needed.
1054 880 *
1055 881 * @since 3.06.01
1056 - *
1057 882 * @param array $field
1058 883 * @param array $add_html
1059 - *
1060 884 * @return void
1061 885 */
1062 886 private static function maybe_add_html_required( $field, array &$add_html ) {
1063 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1064 887 $excluded_field_types =
1065 888 FrmField::is_radio( $field ) ||
1066 889 FrmField::is_checkbox( $field ) ||
1067 890 FrmField::is_field_type( $field, 'file' ) ||
@@ -1066,9 +889,8 @@
1066 889 FrmField::is_checkbox( $field ) ||
1067 890 FrmField::is_field_type( $field, 'file' ) ||
1068 891 FrmField::is_field_type( $field, 'nps' ) ||
1069 892 FrmField::is_field_type( $field, 'scale' );
1070 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1071 893
1072 894 if ( $excluded_field_types ) {
1073 895 return;
1074 896 }
@@ -1078,9 +900,8 @@
1078 900
1079 901 /**
1080 902 * @param array $field
1081 903 * @param array $add_html
1082 - *
1083 904 * @return void
1084 905 */
1085 906 private static function add_shortcodes_to_html( $field, array &$add_html ) {
1086 907 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
@@ -1091,25 +912,13 @@
1091 912 unset( $field['shortcodes']['autocomplete'] );
1092 913 }
1093 914
1094 915 foreach ( $field['shortcodes'] as $k => $v ) {
1095 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
1096 - $subfield_name = $field['subfield_name'];
1097 -
1098 - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
1099 - continue;
1100 - }
1101 - // 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 - $k = 'aria-invalid';
1103 - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1104 - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1105 - }
1106 -
1107 916 if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
1108 917 continue;
1109 918 }
1110 919
1111 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
920 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1112 921 $add_html[] = $v;
1113 922 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1114 923 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1115 924 } else {
@@ -1116,9 +925,9 @@
1116 925 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1117 926 }
1118 927
1119 928 unset( $k, $v );
1120 - }//end foreach
929 + }
1121 930 }
1122 931
1123 932 /**
1124 933 * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
@@ -1125,9 +934,8 @@
1125 934 *
1126 935 * @since 6.11.2
1127 936 *
1128 937 * @param string $key The option key.
1129 - *
1130 938 * @return bool
1131 939 */
1132 940 private static function should_allow_input_attribute( $key ) {
1133 941 if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
@@ -1142,91 +950,28 @@
1142 950 * @since 3.0
1143 951 *
1144 952 * @param array $field
1145 953 * @param array $add_html
1146 - *
1147 954 * @return void
1148 955 */
1149 956 private static function add_pattern_attribute( $field, array &$add_html ) {
1150 - $format_value = FrmField::get_option( $field, 'format' );
1151 - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
957 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1152 958 $format_field = FrmField::is_field_type( $field, 'text' );
1153 959
1154 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1155 - return;
1156 - }
960 + if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
961 + $format = FrmEntryValidate::phone_format( $field );
962 + $format = substr( $format, 2, - 1 );
1157 963
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;
964 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
1178 965 }
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 966 }
1193 967
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 968 public static function check_value( $opt, $opt_key, $field ) {
1224 969 if ( is_array( $opt ) ) {
1225 970 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1226 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
971 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1227 972 } else {
1228 - $opt = $opt['label'] ?? reset( $opt );
973 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1229 974 }
1230 975 }
1231 976
1232 977 return $opt;
@@ -1231,13 +976,12 @@
1231 976
1232 977 return $opt;
1233 978 }
1234 979
1235 - /**
1236 - * @param mixed $opt
1237 - *
1238 - * @return mixed
1239 - */
1240 980 public static function check_label( $opt ) {
1241 - 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;
1242 986 }
1243 987 }