PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7.2
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 +181 -342 6.26.16.7.2 View file →
@@ -4,15 +4,8 @@
4 4 }
5 5
6 6 class FrmFieldsController {
7 7
8 - /**
9 - * This is stored statically so we can re-use this data for every field.
10 - *
11 - * @var FrmFieldSelectionData|null
12 - */
13 - private static $field_selection_data;
14 -
15 8 public static function load_field() {
16 9 FrmAppHelper::permission_check( 'frm_edit_forms' );
17 10 check_ajax_referer( 'frm_ajax', 'nonce' );
18 11
@@ -18,9 +11,8 @@
18 11
19 12 // Javascript may be included in some field settings.
20 13 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
21 14 $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array();
22 -
23 15 if ( empty( $fields ) ) {
24 16 wp_die();
25 17 }
26 18
@@ -34,9 +26,8 @@
34 26
35 27 foreach ( $fields as $field ) {
36 28 $field = htmlspecialchars_decode( nl2br( $field ) );
37 29 $field = json_decode( $field );
38 -
39 30 if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
40 31 // this field may have already been loaded
41 32 continue;
42 33 }
@@ -51,9 +42,9 @@
51 42 ob_start();
52 43 self::load_single_field( $field, $values );
53 44 $field_html[ absint( $field->id ) ] = ob_get_contents();
54 45 ob_end_clean();
55 - }//end foreach
46 + }
56 47
57 48 echo json_encode( $field_html );
58 49
59 50 wp_die();
@@ -65,15 +56,14 @@
65 56 public static function create() {
66 57 FrmAppHelper::permission_check( 'frm_edit_forms' );
67 58 check_ajax_referer( 'frm_ajax', 'nonce' );
68 59
69 - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
70 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
71 - $field_options = FrmAppHelper::get_post_param( 'field_options', array(), 'wp_kses_post' );
60 + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
61 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
72 62
73 63 do_action( 'frm_before_create_field', $field_type, $form_id );
74 64
75 - $field = self::include_new_field( $field_type, $form_id, $field_options );
65 + $field = self::include_new_field( $field_type, $form_id );
76 66
77 67 // this hook will allow for multiple fields to be added at once
78 68 do_action( 'frm_after_field_created', $field, $form_id );
79 69
@@ -82,24 +72,16 @@
82 72
83 73 /**
84 74 * Set up and create a new field
85 75 *
86 - * @param string $field_type
87 - * @param int $form_id
88 - * @param array $field_options
76 + * @param string $field_type
77 + * @param integer $form_id
89 78 *
90 - * @return array|false
79 + * @return array|bool
91 80 */
92 - public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
81 + public static function include_new_field( $field_type, $form_id ) {
93 82 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
94 83
95 - if ( ! empty( $field_options ) ) {
96 - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
97 - }
98 -
99 - // When a new field is added to the form, flag it as draft and hide it from the front-end.
100 - $field_values['field_options']['draft'] = 1;
101 -
102 84 /**
103 85 * @param array $field_values
104 86 */
105 87 $field_values = apply_filters( 'frm_before_field_created', $field_values );
@@ -111,14 +93,12 @@
111 93
112 94 $field = self::get_field_array_from_id( $field_id );
113 95
114 96 $values = array();
115 -
116 97 if ( FrmAppHelper::pro_is_installed() ) {
117 98 $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
118 99
119 100 $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
120 -
121 101 if ( $parent_form_id ) {
122 102 $field['parent_form_id'] = $parent_form_id;
123 103 }
124 104 }
@@ -159,13 +139,11 @@
159 139
160 140 /**
161 141 * @since 3.0
162 142 *
163 - * @param array|int|object $field_object
143 + * @param int|array|object $field_object
164 144 * @param array $values
165 145 * @param int $form_id
166 - *
167 - * @return void
168 146 */
169 147 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
170 148 global $frm_vars;
171 149 $frm_vars['is_admin'] = true;
@@ -179,47 +157,30 @@
179 157
180 158 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
181 159 $display = self::display_field_options( array(), $field_obj );
182 160
183 - $ajax_loading = ! empty( $values['ajax_load'] );
184 - $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
161 + $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
162 + $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) );
185 163
186 164 if ( $ajax_loading && $ajax_this_field ) {
187 165 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
188 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php';
189 - return;
190 - }
166 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' );
167 + } else {
168 + if ( ! isset( $field ) && is_object( $field_object ) ) {
169 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
191 170
192 - if ( ! isset( $field ) && is_object( $field_object ) ) {
193 - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id;
194 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
195 - }
171 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
172 + }
196 173
197 - /**
198 - * Filter for adding extra attributes to the field container.
199 - *
200 - * @since 6.23
201 - *
202 - * @param array $extra_field_attributes
203 - * @param array $field
204 - * @param array $display
205 - */
206 - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display );
174 + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
175 + $li_classes .= ' ui-state-default widgets-holder-wrap';
207 176
208 - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
209 - $li_classes .= ' ui-state-default widgets-holder-wrap';
210 -
211 - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
177 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
178 + }
212 179 }
213 180
214 181 /**
215 182 * @since 3.0
216 - *
217 - * @param array $field
218 - * @param array $display
219 - * @param FrmFieldType $field_info
220 - *
221 - * @return string
222 183 */
223 184 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
224 185 $li_classes = $field_info->form_builder_classes( $display['type'] );
225 186 $li_classes .= ' frm_form_field frmstart ';
@@ -256,24 +217,12 @@
256 217 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
257 218 return;
258 219 }
259 220
260 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
261 - $field = FrmField::getOne( $field_id );
262 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
221 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
222 + $field = FrmField::getOne( $field_id );
263 223
264 - /**
265 - * Filter to add new fields that will support import_options/Bulk Edit Options.
266 - *
267 - * @since 6.8.4
268 - *
269 - * @param array $bulk_edit_types
270 - *
271 - * @return array
272 - */
273 - $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
274 -
275 - if ( ! in_array( $field->type, $bulk_edit_types, true ) ) {
224 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
276 225 return;
277 226 }
278 227
279 228 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -280,15 +229,15 @@
280 229 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
281 230 $opts = explode( "\n", rtrim( $opts, "\n" ) );
282 231 $opts = array_map( 'trim', $opts );
283 232
284 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
285 - $field['separate_value'] = $separate === 'true';
233 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
234 + $field['separate_value'] = ( $separate === 'true' );
286 235
287 236 if ( $field['separate_value'] ) {
288 237 foreach ( $opts as $opt_key => $opt ) {
289 238 if ( strpos( $opt, '|' ) !== false ) {
290 - $vals = explode( '|', $opt );
239 + $vals = explode( '|', $opt );
291 240 $opts[ $opt_key ] = array(
292 241 'label' => trim( $vals[0] ),
293 242 'value' => trim( $vals[1] ),
294 243 );
@@ -300,9 +249,8 @@
300 249
301 250 // Keep other options after bulk update.
302 251 if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
303 252 $other_array = array();
304 -
305 253 foreach ( $field['options'] as $opt_key => $opt ) {
306 254 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
307 255 $other_array[ $opt_key ] = $opt;
308 256 }
@@ -307,9 +255,8 @@
307 255 $other_array[ $opt_key ] = $opt;
308 256 }
309 257 unset( $opt_key, $opt );
310 258 }
311 -
312 259 if ( ! empty( $other_array ) ) {
313 260 $opts = array_merge( $opts, $other_array );
314 261 }
315 262 }
@@ -324,10 +271,8 @@
324 271 /**
325 272 * @since 4.0
326 273 *
327 274 * @param array $atts - Includes field array, field_obj, display array, values array.
328 - *
329 - * @return void
330 275 */
331 276 public static function load_single_field_settings( $atts ) {
332 277 $field = $atts['field'];
333 278 $field_obj = $atts['field_obj'];
@@ -342,13 +287,13 @@
342 287 if ( ! isset( $field['read_only'] ) ) {
343 288 $field['read_only'] = false;
344 289 }
345 290
346 - $field_selection_data = self::maybe_define_field_selection_data();
347 - $all_field_types = $field_selection_data->all_field_types;
348 - $disabled_fields = $field_selection_data->disabled_fields;
349 - $frm_settings = FrmAppHelper::get_settings();
350 - $field_types = FrmFieldTypeOptionData::get_field_types( $field['type'] );
291 + $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
292 + $pro_field_selection = FrmField::pro_field_selection();
293 + $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
294 + $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
295 + $frm_settings = FrmAppHelper::get_settings();
351 296
352 297 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
353 298 // Add fallback for an add-on field type that has been deactivated.
354 299 $all_field_types[ $field['type'] ] = array(
@@ -360,9 +305,8 @@
360 305 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
361 306 }
362 307
363 308 $type_name = $all_field_types[ $field['type'] ]['name'];
364 -
365 309 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
366 310 $type_name = $all_field_types['divider|repeat']['name'];
367 311 }
368 312
@@ -377,72 +321,57 @@
377 321 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
378 322 }
379 323
380 324 /**
381 - * @since 6.9.1
382 - *
383 - * @return FrmFieldSelectionData
384 - */
385 - private static function maybe_define_field_selection_data() {
386 - if ( ! isset( self::$field_selection_data ) ) {
387 - self::$field_selection_data = new FrmFieldSelectionData();
388 - }
389 - return self::$field_selection_data;
390 - }
391 -
392 - /**
393 325 * Get the list of default value types that can be toggled in the builder.
394 326 *
395 327 * @since 4.0
396 - *
397 - * @param array $field
398 - * @param array $atts
399 - *
400 328 * @return array
401 329 */
402 330 private static function default_value_types( $field, $atts ) {
403 331 $types = array(
404 - 'default_value' => array(
332 + 'default_value' => array(
405 333 'class' => '',
406 334 'icon' => 'frm_icon_font frm_text2_icon',
407 - 'title' => __( 'Default Value', 'formidable' ),
335 + 'title' => __( 'Default Value (Text)', 'formidable' ),
408 336 'data' => array(
409 337 'frmshow' => '#default-value-for-',
410 338 ),
411 339 ),
412 - 'calc' => array(
413 - 'class' => 'frm_show_upgrade frm_noallow',
414 - 'title' => __( 'Calculate Value', 'formidable' ),
415 - 'icon' => 'frm_icon_font frm_calculator_icon',
416 - 'data' => array(
340 + 'calc' => array(
341 + 'class' => 'frm_show_upgrade frm_noallow',
342 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
343 + 'icon' => 'frm_icon_font frm_calculator_icon',
344 + 'data' => array(
417 345 'medium' => 'calculations',
418 346 'upgrade' => __( 'Calculator forms', 'formidable' ),
419 347 ),
420 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
421 348 ),
422 349 'get_values_field' => array(
423 - 'class' => 'frm_show_upgrade frm_noallow',
424 - 'title' => __( 'Lookup', 'formidable' ),
425 - 'icon' => 'frm_icon_font frm_search_icon',
426 - 'data' => array(
350 + 'class' => 'frm_show_upgrade frm_noallow',
351 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
352 + 'icon' => 'frm_icon_font frm_search_icon',
353 + 'data' => array(
427 354 'medium' => 'lookup',
428 355 'upgrade' => __( 'Lookup fields', 'formidable' ),
429 356 ),
430 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
431 357 ),
432 358 );
433 359
434 360 $types = apply_filters( 'frm_default_value_types', $types, $atts );
435 361
362 + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
363 + // Prevent settings from showing in 2 spots.
364 + unset( $types['calc'], $types['get_values_field'] );
365 + }
366 +
436 367 // Set active class.
437 368 $settings = array_keys( $types );
438 369 $active = 'default_value';
439 370
440 - if ( FrmAppHelper::pro_is_connected() ) {
441 - foreach ( $settings as $type ) {
442 - if ( ! empty( $field[ $type ] ) ) {
443 - $active = $type;
444 - }
371 + foreach ( $settings as $type ) {
372 + if ( ! empty( $field[ $type ] ) ) {
373 + $active = $type;
445 374 }
446 375 }
447 376
448 377 $types[ $active ]['class'] .= ' current';
@@ -450,13 +379,8 @@
450 379
451 380 return $types;
452 381 }
453 382
454 - /**
455 - * @param string $type
456 - *
457 - * @return string
458 - */
459 383 public static function change_type( $type ) {
460 384 $type_switch = array(
461 385 'scale' => 'radio',
462 386 'star' => 'radio',
@@ -464,9 +388,8 @@
464 388 'rte' => 'textarea',
465 389 'website' => 'url',
466 390 'image' => 'url',
467 391 );
468 -
469 392 if ( isset( $type_switch[ $type ] ) ) {
470 393 $type = $type_switch[ $type ];
471 394 }
472 395
@@ -482,18 +405,16 @@
482 405 return $type;
483 406 }
484 407
485 408 /**
486 - * @param array $settings
487 - * @param FrmFieldType|null $field_info
409 + * @param array $settings
410 + * @param object $field_info
488 411 *
489 412 * @return array
490 413 */
491 414 public static function display_field_options( $settings, $field_info = null ) {
492 415 if ( $field_info ) {
493 - $settings = $field_info->display_field_settings();
494 -
495 - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
416 + $settings = $field_info->display_field_settings();
496 417 $settings['field_data'] = $field_info->field;
497 418 }
498 419
499 420 return apply_filters( 'frm_display_field_options', $settings );
@@ -503,32 +424,14 @@
503 424 * Display the format option
504 425 *
505 426 * @since 3.0
506 427 *
507 - * @param array $field Field data.
508 - * @param bool $is_hidden Whether the format option should be hidden.
509 - *
510 - * @return void
428 + * @param array $field
511 429 */
512 - public static function show_format_option( $field, $is_hidden = false ) {
513 - $attributes = array(
514 - 'class' => 'frm-has-modal',
515 - 'id' => 'frm-field-format-custom-' . $field['id'],
516 - );
517 -
518 - if ( $is_hidden ) {
519 - $attributes['class'] .= ' frm_hidden';
520 - }
521 -
522 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
430 + public static function show_format_option( $field ) {
431 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
523 432 }
524 433
525 - /**
526 - * @param array $field
527 - * @param bool $echo
528 - *
529 - * @return string
530 - */
531 434 public static function input_html( $field, $echo = true ) {
532 435 $class = array();
533 436 self::add_input_classes( $field, $class );
534 437
@@ -554,20 +457,14 @@
554 457
555 458 return $add_html;
556 459 }
557 460
558 - /**
559 - * @param array $field
560 - * @param array $class
561 - *
562 - * @return void
563 - */
564 461 private static function add_input_classes( $field, array &$class ) {
565 - if ( ! empty( $field['input_class'] ) ) {
462 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
566 463 $class[] = $field['input_class'];
567 464 }
568 465
569 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
466 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
570 467 return;
571 468 }
572 469
573 470 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -574,14 +471,8 @@
574 471 $class[] = 'auto_width';
575 472 }
576 473 }
577 474
578 - /**
579 - * @param array $field
580 - * @param array $add_html
581 - *
582 - * @return void
583 - */
584 475 private static function add_html_size( $field, array &$add_html ) {
585 476 $size_fields = array(
586 477 'select',
587 478 'data',
@@ -590,9 +481,9 @@
590 481 'file',
591 482 'lookup',
592 483 );
593 484
594 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
485 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
595 486 return;
596 487 }
597 488
598 489 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -609,14 +500,8 @@
609 500
610 501 self::add_html_cols( $field, $add_html );
611 502 }
612 503
613 - /**
614 - * @param array $field
615 - * @param array $add_html
616 - *
617 - * @return void
618 - */
619 504 private static function add_html_cols( $field, array &$add_html ) {
620 505 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
621 506 return;
622 507 }
@@ -640,14 +525,8 @@
640 525
641 526 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
642 527 }
643 528
644 - /**
645 - * @param array $field
646 - * @param array $add_html
647 - *
648 - * @return void
649 - */
650 529 private static function add_html_length( $field, array &$add_html ) {
651 530 // Check for max setting and if this field accepts maxlength.
652 531 $fields = array(
653 532 'textarea',
@@ -655,9 +534,9 @@
655 534 'hidden',
656 535 'file',
657 536 );
658 537
659 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
538 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
660 539 return;
661 540 }
662 541
663 542 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -667,15 +546,8 @@
667 546
668 547 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
669 548 }
670 549
671 - /**
672 - * @param array $field
673 - * @param array $add_html
674 - * @param array $class
675 - *
676 - * @return void
677 - */
678 550 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
679 551 if ( $field['default_value'] != '' ) {
680 552 if ( is_array( $field['default_value'] ) ) {
681 553 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -684,15 +556,26 @@
684 556 }
685 557 }
686 558
687 559 $field['placeholder'] = self::prepare_placeholder( $field );
688 -
689 560 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
690 561 // don't include a json placeholder
691 562 return;
692 563 }
693 564
694 - self::add_placeholder_to_input( $field, $add_html );
565 + $frm_settings = FrmAppHelper::get_settings();
566 +
567 + if ( $frm_settings->use_html ) {
568 + self::add_placeholder_to_input( $field, $add_html );
569 + } else {
570 + self::add_frmval_to_input( $field, $add_html );
571 +
572 + $class[] = 'frm_toggle_default';
573 +
574 + if ( $field['value'] == $field['placeholder'] ) {
575 + $class[] = 'frm_default';
576 + }
577 + }
695 578 }
696 579
697 580 /**
698 581 * Prepares field placeholder.
@@ -699,13 +582,12 @@
699 582 *
700 583 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
701 584 *
702 585 * @param array $field Field array.
703 - *
704 586 * @return string
705 587 */
706 588 private static function prepare_placeholder( $field ) {
707 - $placeholder = $field['placeholder'] ?? '';
589 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
708 590
709 591 return $placeholder;
710 592 }
711 593
@@ -728,39 +610,22 @@
728 610 * Maybe add a blank placeholder option before any options
729 611 * in a dropdown.
730 612 *
731 613 * @since 4.04
732 - *
733 - * @param array|object $field
734 - *
735 614 * @return bool True if placeholder was added.
736 615 */
737 616 public static function add_placeholder_to_select( $field ) {
738 617 $placeholder = FrmField::get_option( $field, 'placeholder' );
739 -
740 618 if ( empty( $placeholder ) ) {
741 619 $placeholder = self::get_default_value_from_name( $field );
742 620 }
743 621
744 - $use_placeholder = $placeholder;
745 - $autocomplete = FrmField::get_option( $field, 'autocom' );
746 -
747 - if ( $autocomplete ) {
748 - $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
749 -
750 - if ( $use_chosen ) {
751 - $use_placeholder = '';
752 - }
753 - }
754 -
755 622 if ( $placeholder !== '' ) {
756 - $placeholder_attributes = array(
757 - 'class' => 'frm-select-placeholder',
758 - 'value' => '',
759 - 'data-placeholder' => 'true',
760 - );
761 -
762 - FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
623 + ?>
624 + <option class="frm-select-placeholder" value="">
625 + <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
626 + </option>
627 + <?php
763 628 return true;
764 629 }
765 630
766 631 return false;
@@ -766,14 +631,12 @@
766 631 return false;
767 632 }
768 633
769 634 /**
770 - * Use HTML5 placeholder with js fallback.
635 + * Use HMTL5 placeholder with js fallback
771 636 *
772 637 * @param array $field
773 638 * @param array $add_html
774 - *
775 - * @return void
776 639 */
777 640 private static function add_placeholder_to_input( $field, &$add_html ) {
778 641 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
779 642 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -779,14 +642,8 @@
779 642 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
780 643 }
781 644 }
782 645
783 - /**
784 - * @param array $field
785 - * @param array $add_html
786 - *
787 - * @return void
788 - */
789 646 private static function add_frmval_to_input( $field, &$add_html ) {
790 647 if ( $field['placeholder'] != '' ) {
791 648 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
792 649
@@ -799,24 +656,16 @@
799 656 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
800 657 }
801 658 }
802 659
803 - /**
804 - * @param array $field
805 - * @param array $add_html
806 - *
807 - * @return void
808 - */
809 660 private static function add_validation_messages( $field, array &$add_html ) {
810 - $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
811 -
812 - if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
661 + if ( FrmField::is_required( $field ) ) {
813 662 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
814 663 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
815 664 self::maybe_add_html_required( $field, $add_html );
816 665 }
817 666
818 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
667 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
819 668 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
820 669 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
821 670 }
822 671
@@ -825,57 +674,20 @@
825 674 }
826 675 }
827 676
828 677 /**
829 - * Returns an array that contains field validation messages status.
830 - *
831 - * @since 6.9
832 - *
833 - * @param array|object $field
834 - *
835 - * @return array
836 - */
837 - private static function get_validation_data_attribute_visibility_info( $field ) {
838 - if ( FrmField::get_field_type( $field ) === 'hidden' ) {
839 - $field_validation_data_attributes = array(
840 - 'data-invmsg' => false,
841 - 'data-reqmsg' => false,
842 - );
843 - } else {
844 - $field_validation_data_attributes = array(
845 - 'data-invmsg' => true,
846 - 'data-reqmsg' => true,
847 - );
848 - }
849 -
850 - /**
851 - * Allows controlling which field validation messages would be included in the field html.
852 - *
853 - * @since 6.9
854 - *
855 - * @param array $field_validation_messages_status
856 - * @param array|object $field
857 - */
858 - return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
859 - }
860 -
861 - /**
862 678 * @since 5.0.03
863 679 *
864 680 * @param array $field
865 681 * @param array $add_html
866 - *
867 - * @return void
868 682 */
869 683 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
870 684 $form = self::get_form_for_js_validation( $field );
871 -
872 685 if ( false === $form ) {
873 686 return;
874 687 }
875 688
876 689 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
877 -
878 690 if ( false !== $error_body ) {
879 691 $error_body = urlencode( $error_body );
880 692 $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
881 693 }
@@ -884,19 +696,16 @@
884 696 /**
885 697 * @since 5.0.03
886 698 *
887 699 * @param array $field
888 - *
889 - * @return false|stdClass false if there is no form object found with JS validation active.
700 + * @return stdClass|false false if there is no form object found with JS validation active.
890 701 */
891 702 private static function get_form_for_js_validation( $field ) {
892 703 global $frm_vars;
893 -
894 704 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
895 705 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
896 706 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
897 707 }
898 -
899 708 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
900 709 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
901 710 }
902 711 }
@@ -906,10 +715,9 @@
906 715 /**
907 716 * @param stdClass $form
908 717 * @param array $field
909 718 * @param array $errors
910 - *
911 - * @return false|string
719 + * @return string|false
912 720 */
913 721 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
914 722 if ( empty( $field['custom_html'] ) ) {
915 723 return false;
@@ -918,15 +726,13 @@
918 726 $custom_html = $field['custom_html'];
919 727 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
920 728
921 729 $start = strpos( $custom_html, '[if error]' );
922 -
923 730 if ( false === $start ) {
924 731 return false;
925 732 }
926 733
927 734 $end = strpos( $custom_html, '[/if error]' );
928 -
929 735 if ( false === $end || $end < $start ) {
930 736 return false;
931 737 }
932 738
@@ -950,13 +756,10 @@
950 756 * submit in many browsers. Check to make sure the javascript to conditionally
951 757 * remove it is present if needed.
952 758 *
953 759 * @since 3.06.01
954 - *
955 760 * @param array $field
956 761 * @param array $add_html
957 - *
958 - * @return void
959 762 */
960 763 private static function maybe_add_html_required( $field, array &$add_html ) {
961 764 $excluded_field_types =
962 765 FrmField::is_radio( $field ) ||
@@ -968,17 +771,14 @@
968 771 if ( $excluded_field_types ) {
969 772 return;
970 773 }
971 774
972 - $add_html['aria-required'] = 'aria-required="true"';
775 + $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
776 + if ( $include_html ) {
777 + $add_html['aria-required'] = 'aria-required="true"';
778 + }
973 779 }
974 780
975 - /**
976 - * @param array $field
977 - * @param array $add_html
978 - *
979 - * @return void
980 - */
981 781 private static function add_shortcodes_to_html( $field, array &$add_html ) {
982 782 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
983 783 return;
984 784 }
@@ -987,21 +787,9 @@
987 787 unset( $field['shortcodes']['autocomplete'] );
988 788 }
989 789
990 790 foreach ( $field['shortcodes'] as $k => $v ) {
991 - if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
992 - $subfield_name = $field['subfield_name'];
993 -
994 - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
995 - continue;
996 - }
997 - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
998 - $k = 'aria-invalid';
999 - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1000 - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1001 - }
1002 -
1003 - if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
791 + if ( 'opt' === $k ) {
1004 792 continue;
1005 793 }
1006 794
1007 795 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -1012,63 +800,41 @@
1012 800 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1013 801 }
1014 802
1015 803 unset( $k, $v );
1016 - }//end foreach
1017 - }
1018 -
1019 - /**
1020 - * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
1021 - *
1022 - * @since 6.11.2
1023 - *
1024 - * @param string $key The option key.
1025 - *
1026 - * @return bool
1027 - */
1028 - private static function should_allow_input_attribute( $key ) {
1029 - if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
1030 - return true;
1031 804 }
1032 - return FrmAppHelper::input_key_is_safe( $key );
1033 805 }
1034 806
1035 807 /**
1036 - * Add pattern attribute.
808 + * Add pattern attribute
1037 809 *
1038 810 * @since 3.0
1039 811 *
1040 812 * @param array $field
1041 813 * @param array $add_html
1042 - *
1043 - * @return void
1044 814 */
1045 815 private static function add_pattern_attribute( $field, array &$add_html ) {
1046 - $format_value = FrmField::get_option( $field, 'format' );
1047 - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
816 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1048 817 $format_field = FrmField::is_field_type( $field, 'text' );
1049 818
1050 - if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
1051 - $format = FrmEntryValidate::phone_format( $field );
1052 - $format = substr( $format, 2, - 1 );
819 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
820 + $frm_settings = FrmAppHelper::get_settings();
1053 821
1054 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
822 + if ( $frm_settings->use_html ) {
823 + $format = FrmEntryValidate::phone_format( $field );
824 + $format = substr( $format, 2, - 1 );
825 +
826 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
827 + }
1055 828 }
1056 829 }
1057 830
1058 - /**
1059 - * @param mixed $opt
1060 - * @param mixed $opt_key
1061 - * @param array|object $field
1062 - *
1063 - * @return mixed
1064 - */
1065 831 public static function check_value( $opt, $opt_key, $field ) {
1066 832 if ( is_array( $opt ) ) {
1067 833 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1068 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
834 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1069 835 } else {
1070 - $opt = $opt['label'] ?? reset( $opt );
836 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1071 837 }
1072 838 }
1073 839
1074 840 return $opt;
@@ -1073,17 +839,90 @@
1073 839
1074 840 return $opt;
1075 841 }
1076 842
1077 - /**
1078 - * @param mixed $opt
1079 - *
1080 - * @return mixed
1081 - */
1082 843 public static function check_label( $opt ) {
1083 844 if ( is_array( $opt ) ) {
1084 - $opt = $opt['label'] ?? reset( $opt );
845 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1085 846 }
1086 847
1087 848 return $opt;
849 + }
850 +
851 + /**
852 + * @deprecated 4.0
853 + */
854 + public static function update_ajax_option() {
855 + _deprecated_function( __METHOD__, '4.0' );
856 + FrmAppHelper::permission_check( 'frm_edit_forms' );
857 + check_ajax_referer( 'frm_ajax', 'nonce' );
858 +
859 + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
860 + if ( ! $field_id ) {
861 + wp_die();
862 + }
863 +
864 + $field = FrmField::getOne( $field_id );
865 +
866 + if ( isset( $_POST['separate_value'] ) ) {
867 + $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
868 +
869 + $field->field_options['separate_value'] = $new_val;
870 + unset( $new_val );
871 + }
872 +
873 + FrmField::update(
874 + $field_id,
875 + array(
876 + 'field_options' => $field->field_options,
877 + 'form_id' => $field->form_id,
878 + )
879 + );
880 + wp_die();
881 + }
882 +
883 + /**
884 + * @deprecated 4.0
885 + */
886 + public static function import_choices() {
887 + _deprecated_function( __METHOD__, '4.0' );
888 + wp_die();
889 + }
890 +
891 + /**
892 + * Add Single Option or Other Option.
893 + *
894 + * @deprecated 4.0 Moved to Pro for Other option only.
895 + */
896 + public static function add_option() {
897 + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
898 + }
899 +
900 + /**
901 + * @deprecated 4.0
902 + */
903 + public static function update_order() {
904 + FrmDeprecated::update_order();
905 + }
906 +
907 + /**
908 + * @deprecated 3.0
909 + * @codeCoverageIgnore
910 + */
911 + public static function edit_name( $field = 'name', $id = '' ) {
912 + FrmDeprecated::edit_name( $field, $id );
913 + }
914 +
915 + /**
916 + * @deprecated 3.0
917 + * @codeCoverageIgnore
918 + *
919 + * @param int $field_id
920 + * @param array $values
921 + * @param int $form_id
922 + *
923 + * @return array
924 + */
925 + public static function include_single_field( $field_id, $values, $form_id = 0 ) {
926 + return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
1088 927 }
1089 928 }