PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
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 +184 -346 6.266.7 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
@@ -83,23 +73,15 @@
83 73 /**
84 74 * Set up and create a new field
85 75 *
86 76 * @param string $field_type
87 - * @param int $form_id
88 - * @param array $field_options
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
164 - * @param array $values
165 - * @param int $form_id
166 - *
167 - * @return void
143 + * @param int|array|object $field_object
144 + * @param array $values
145 + * @param int $form_id
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 ';
@@ -245,11 +206,10 @@
245 206 FrmField::destroy( $field_id );
246 207 wp_die();
247 208 }
248 209
249 - /**
250 - * Field Options.
251 - */
210 + /* Field Options */
211 +
252 212 public static function import_options() {
253 213 FrmAppHelper::permission_check( 'frm_edit_forms' );
254 214 check_ajax_referer( 'frm_ajax', 'nonce' );
255 215
@@ -256,24 +216,12 @@
256 216 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
257 217 return;
258 218 }
259 219
260 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
261 - $field = FrmField::getOne( $field_id );
262 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
220 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
221 + $field = FrmField::getOne( $field_id );
263 222
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 ) ) {
223 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
276 224 return;
277 225 }
278 226
279 227 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -280,15 +228,15 @@
280 228 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
281 229 $opts = explode( "\n", rtrim( $opts, "\n" ) );
282 230 $opts = array_map( 'trim', $opts );
283 231
284 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
285 - $field['separate_value'] = $separate === 'true';
232 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
233 + $field['separate_value'] = ( $separate === 'true' );
286 234
287 235 if ( $field['separate_value'] ) {
288 236 foreach ( $opts as $opt_key => $opt ) {
289 237 if ( strpos( $opt, '|' ) !== false ) {
290 - $vals = explode( '|', $opt );
238 + $vals = explode( '|', $opt );
291 239 $opts[ $opt_key ] = array(
292 240 'label' => trim( $vals[0] ),
293 241 'value' => trim( $vals[1] ),
294 242 );
@@ -300,9 +248,8 @@
300 248
301 249 // Keep other options after bulk update.
302 250 if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
303 251 $other_array = array();
304 -
305 252 foreach ( $field['options'] as $opt_key => $opt ) {
306 253 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
307 254 $other_array[ $opt_key ] = $opt;
308 255 }
@@ -307,9 +254,8 @@
307 254 $other_array[ $opt_key ] = $opt;
308 255 }
309 256 unset( $opt_key, $opt );
310 257 }
311 -
312 258 if ( ! empty( $other_array ) ) {
313 259 $opts = array_merge( $opts, $other_array );
314 260 }
315 261 }
@@ -324,10 +270,8 @@
324 270 /**
325 271 * @since 4.0
326 272 *
327 273 * @param array $atts - Includes field array, field_obj, display array, values array.
328 - *
329 - * @return void
330 274 */
331 275 public static function load_single_field_settings( $atts ) {
332 276 $field = $atts['field'];
333 277 $field_obj = $atts['field_obj'];
@@ -342,13 +286,13 @@
342 286 if ( ! isset( $field['read_only'] ) ) {
343 287 $field['read_only'] = false;
344 288 }
345 289
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'] );
290 + $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
291 + $pro_field_selection = FrmField::pro_field_selection();
292 + $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
293 + $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
294 + $frm_settings = FrmAppHelper::get_settings();
351 295
352 296 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
353 297 // Add fallback for an add-on field type that has been deactivated.
354 298 $all_field_types[ $field['type'] ] = array(
@@ -360,9 +304,8 @@
360 304 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
361 305 }
362 306
363 307 $type_name = $all_field_types[ $field['type'] ]['name'];
364 -
365 308 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
366 309 $type_name = $all_field_types['divider|repeat']['name'];
367 310 }
368 311
@@ -377,72 +320,57 @@
377 320 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
378 321 }
379 322
380 323 /**
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 324 * Get the list of default value types that can be toggled in the builder.
394 325 *
395 326 * @since 4.0
396 - *
397 - * @param array $field
398 - * @param array $atts
399 - *
400 327 * @return array
401 328 */
402 329 private static function default_value_types( $field, $atts ) {
403 330 $types = array(
404 - 'default_value' => array(
331 + 'default_value' => array(
405 332 'class' => '',
406 333 'icon' => 'frm_icon_font frm_text2_icon',
407 - 'title' => __( 'Default Value', 'formidable' ),
334 + 'title' => __( 'Default Value (Text)', 'formidable' ),
408 335 'data' => array(
409 336 'frmshow' => '#default-value-for-',
410 337 ),
411 338 ),
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(
339 + 'calc' => array(
340 + 'class' => 'frm_show_upgrade frm_noallow',
341 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
342 + 'icon' => 'frm_icon_font frm_calculator_icon',
343 + 'data' => array(
417 344 'medium' => 'calculations',
418 345 'upgrade' => __( 'Calculator forms', 'formidable' ),
419 346 ),
420 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
421 347 ),
422 348 '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(
349 + 'class' => 'frm_show_upgrade frm_noallow',
350 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
351 + 'icon' => 'frm_icon_font frm_search_icon',
352 + 'data' => array(
427 353 'medium' => 'lookup',
428 354 'upgrade' => __( 'Lookup fields', 'formidable' ),
429 355 ),
430 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
431 356 ),
432 357 );
433 358
434 359 $types = apply_filters( 'frm_default_value_types', $types, $atts );
435 360
361 + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
362 + // Prevent settings from showing in 2 spots.
363 + unset( $types['calc'], $types['get_values_field'] );
364 + }
365 +
436 366 // Set active class.
437 367 $settings = array_keys( $types );
438 368 $active = 'default_value';
439 369
440 - if ( FrmAppHelper::pro_is_connected() ) {
441 - foreach ( $settings as $type ) {
442 - if ( ! empty( $field[ $type ] ) ) {
443 - $active = $type;
444 - }
370 + foreach ( $settings as $type ) {
371 + if ( ! empty( $field[ $type ] ) ) {
372 + $active = $type;
445 373 }
446 374 }
447 375
448 376 $types[ $active ]['class'] .= ' current';
@@ -450,13 +378,8 @@
450 378
451 379 return $types;
452 380 }
453 381
454 - /**
455 - * @param string $type
456 - *
457 - * @return string
458 - */
459 382 public static function change_type( $type ) {
460 383 $type_switch = array(
461 384 'scale' => 'radio',
462 385 'star' => 'radio',
@@ -464,9 +387,8 @@
464 387 'rte' => 'textarea',
465 388 'website' => 'url',
466 389 'image' => 'url',
467 390 );
468 -
469 391 if ( isset( $type_switch[ $type ] ) ) {
470 392 $type = $type_switch[ $type ];
471 393 }
472 394
@@ -482,18 +404,16 @@
482 404 return $type;
483 405 }
484 406
485 407 /**
486 - * @param array $settings
487 - * @param FrmFieldType|null $field_info
408 + * @param array $settings
409 + * @param object $field_info
488 410 *
489 411 * @return array
490 412 */
491 413 public static function display_field_options( $settings, $field_info = null ) {
492 414 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.
415 + $settings = $field_info->display_field_settings();
496 416 $settings['field_data'] = $field_info->field;
497 417 }
498 418
499 419 return apply_filters( 'frm_display_field_options', $settings );
@@ -503,32 +423,14 @@
503 423 * Display the format option
504 424 *
505 425 * @since 3.0
506 426 *
507 - * @param array $field Field data.
508 - * @param bool $is_hidden Whether the format option should be hidden.
509 - *
510 - * @return void
427 + * @param array $field
511 428 */
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';
429 + public static function show_format_option( $field ) {
430 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
523 431 }
524 432
525 - /**
526 - * @param array $field
527 - * @param bool $echo
528 - *
529 - * @return string
530 - */
531 433 public static function input_html( $field, $echo = true ) {
532 434 $class = array();
533 435 self::add_input_classes( $field, $class );
534 436
@@ -554,20 +456,14 @@
554 456
555 457 return $add_html;
556 458 }
557 459
558 - /**
559 - * @param array $field
560 - * @param array $class
561 - *
562 - * @return void
563 - */
564 460 private static function add_input_classes( $field, array &$class ) {
565 - if ( ! empty( $field['input_class'] ) ) {
461 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
566 462 $class[] = $field['input_class'];
567 463 }
568 464
569 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
465 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
570 466 return;
571 467 }
572 468
573 469 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -574,14 +470,8 @@
574 470 $class[] = 'auto_width';
575 471 }
576 472 }
577 473
578 - /**
579 - * @param array $field
580 - * @param array $add_html
581 - *
582 - * @return void
583 - */
584 474 private static function add_html_size( $field, array &$add_html ) {
585 475 $size_fields = array(
586 476 'select',
587 477 'data',
@@ -590,9 +480,9 @@
590 480 'file',
591 481 'lookup',
592 482 );
593 483
594 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
484 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
595 485 return;
596 486 }
597 487
598 488 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -609,14 +499,8 @@
609 499
610 500 self::add_html_cols( $field, $add_html );
611 501 }
612 502
613 - /**
614 - * @param array $field
615 - * @param array $add_html
616 - *
617 - * @return void
618 - */
619 503 private static function add_html_cols( $field, array &$add_html ) {
620 504 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
621 505 return;
622 506 }
@@ -640,14 +524,8 @@
640 524
641 525 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
642 526 }
643 527
644 - /**
645 - * @param array $field
646 - * @param array $add_html
647 - *
648 - * @return void
649 - */
650 528 private static function add_html_length( $field, array &$add_html ) {
651 529 // Check for max setting and if this field accepts maxlength.
652 530 $fields = array(
653 531 'textarea',
@@ -655,9 +533,9 @@
655 533 'hidden',
656 534 'file',
657 535 );
658 536
659 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
537 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
660 538 return;
661 539 }
662 540
663 541 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -667,15 +545,8 @@
667 545
668 546 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
669 547 }
670 548
671 - /**
672 - * @param array $field
673 - * @param array $add_html
674 - * @param array $class
675 - *
676 - * @return void
677 - */
678 549 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
679 550 if ( $field['default_value'] != '' ) {
680 551 if ( is_array( $field['default_value'] ) ) {
681 552 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -684,15 +555,26 @@
684 555 }
685 556 }
686 557
687 558 $field['placeholder'] = self::prepare_placeholder( $field );
688 -
689 559 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
690 560 // don't include a json placeholder
691 561 return;
692 562 }
693 563
694 - self::add_placeholder_to_input( $field, $add_html );
564 + $frm_settings = FrmAppHelper::get_settings();
565 +
566 + if ( $frm_settings->use_html ) {
567 + self::add_placeholder_to_input( $field, $add_html );
568 + } else {
569 + self::add_frmval_to_input( $field, $add_html );
570 +
571 + $class[] = 'frm_toggle_default';
572 +
573 + if ( $field['value'] == $field['placeholder'] ) {
574 + $class[] = 'frm_default';
575 + }
576 + }
695 577 }
696 578
697 579 /**
698 580 * Prepares field placeholder.
@@ -699,13 +581,12 @@
699 581 *
700 582 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
701 583 *
702 584 * @param array $field Field array.
703 - *
704 585 * @return string
705 586 */
706 587 private static function prepare_placeholder( $field ) {
707 - $placeholder = $field['placeholder'] ?? '';
588 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
708 589
709 590 return $placeholder;
710 591 }
711 592
@@ -728,39 +609,22 @@
728 609 * Maybe add a blank placeholder option before any options
729 610 * in a dropdown.
730 611 *
731 612 * @since 4.04
732 - *
733 - * @param array|object $field
734 - *
735 613 * @return bool True if placeholder was added.
736 614 */
737 615 public static function add_placeholder_to_select( $field ) {
738 616 $placeholder = FrmField::get_option( $field, 'placeholder' );
739 -
740 617 if ( empty( $placeholder ) ) {
741 618 $placeholder = self::get_default_value_from_name( $field );
742 619 }
743 620
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 621 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 );
622 + ?>
623 + <option class="frm-select-placeholder" value="">
624 + <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
625 + </option>
626 + <?php
763 627 return true;
764 628 }
765 629
766 630 return false;
@@ -766,14 +630,12 @@
766 630 return false;
767 631 }
768 632
769 633 /**
770 - * Use HTML5 placeholder with js fallback.
634 + * Use HMTL5 placeholder with js fallback
771 635 *
772 636 * @param array $field
773 637 * @param array $add_html
774 - *
775 - * @return void
776 638 */
777 639 private static function add_placeholder_to_input( $field, &$add_html ) {
778 640 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
779 641 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -779,14 +641,8 @@
779 641 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
780 642 }
781 643 }
782 644
783 - /**
784 - * @param array $field
785 - * @param array $add_html
786 - *
787 - * @return void
788 - */
789 645 private static function add_frmval_to_input( $field, &$add_html ) {
790 646 if ( $field['placeholder'] != '' ) {
791 647 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
792 648
@@ -799,24 +655,16 @@
799 655 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
800 656 }
801 657 }
802 658
803 - /**
804 - * @param array $field
805 - * @param array $add_html
806 - *
807 - * @return void
808 - */
809 659 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'] ) ) {
660 + if ( FrmField::is_required( $field ) ) {
813 661 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
814 662 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
815 663 self::maybe_add_html_required( $field, $add_html );
816 664 }
817 665
818 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
666 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
819 667 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
820 668 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
821 669 }
822 670
@@ -825,57 +673,20 @@
825 673 }
826 674 }
827 675
828 676 /**
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 677 * @since 5.0.03
863 678 *
864 679 * @param array $field
865 680 * @param array $add_html
866 - *
867 - * @return void
868 681 */
869 682 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
870 683 $form = self::get_form_for_js_validation( $field );
871 -
872 684 if ( false === $form ) {
873 685 return;
874 686 }
875 687
876 688 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
877 -
878 689 if ( false !== $error_body ) {
879 690 $error_body = urlencode( $error_body );
880 691 $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
881 692 }
@@ -884,19 +695,16 @@
884 695 /**
885 696 * @since 5.0.03
886 697 *
887 698 * @param array $field
888 - *
889 - * @return false|stdClass false if there is no form object found with JS validation active.
699 + * @return stdClass|false false if there is no form object found with JS validation active.
890 700 */
891 701 private static function get_form_for_js_validation( $field ) {
892 702 global $frm_vars;
893 -
894 703 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
895 704 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
896 705 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
897 706 }
898 -
899 707 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
900 708 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
901 709 }
902 710 }
@@ -906,10 +714,9 @@
906 714 /**
907 715 * @param stdClass $form
908 716 * @param array $field
909 717 * @param array $errors
910 - *
911 - * @return false|string
718 + * @return string|false
912 719 */
913 720 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
914 721 if ( empty( $field['custom_html'] ) ) {
915 722 return false;
@@ -918,15 +725,13 @@
918 725 $custom_html = $field['custom_html'];
919 726 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
920 727
921 728 $start = strpos( $custom_html, '[if error]' );
922 -
923 729 if ( false === $start ) {
924 730 return false;
925 731 }
926 732
927 733 $end = strpos( $custom_html, '[/if error]' );
928 -
929 734 if ( false === $end || $end < $start ) {
930 735 return false;
931 736 }
932 737
@@ -950,13 +755,10 @@
950 755 * submit in many browsers. Check to make sure the javascript to conditionally
951 756 * remove it is present if needed.
952 757 *
953 758 * @since 3.06.01
954 - *
955 759 * @param array $field
956 760 * @param array $add_html
957 - *
958 - * @return void
959 761 */
960 762 private static function maybe_add_html_required( $field, array &$add_html ) {
961 763 $excluded_field_types =
962 764 FrmField::is_radio( $field ) ||
@@ -968,17 +770,14 @@
968 770 if ( $excluded_field_types ) {
969 771 return;
970 772 }
971 773
972 - $add_html['aria-required'] = 'aria-required="true"';
774 + $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
775 + if ( $include_html ) {
776 + $add_html['aria-required'] = 'aria-required="true"';
777 + }
973 778 }
974 779
975 - /**
976 - * @param array $field
977 - * @param array $add_html
978 - *
979 - * @return void
980 - */
981 780 private static function add_shortcodes_to_html( $field, array &$add_html ) {
982 781 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
983 782 return;
984 783 }
@@ -987,21 +786,9 @@
987 786 unset( $field['shortcodes']['autocomplete'] );
988 787 }
989 788
990 789 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 ) ) {
790 + if ( 'opt' === $k ) {
1004 791 continue;
1005 792 }
1006 793
1007 794 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -1012,63 +799,41 @@
1012 799 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1013 800 }
1014 801
1015 802 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 803 }
1032 - return FrmAppHelper::input_key_is_safe( $key );
1033 804 }
1034 805
1035 806 /**
1036 - * Add pattern attribute.
807 + * Add pattern attribute
1037 808 *
1038 809 * @since 3.0
1039 810 *
1040 811 * @param array $field
1041 812 * @param array $add_html
1042 - *
1043 - * @return void
1044 813 */
1045 814 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 );
815 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1048 816 $format_field = FrmField::is_field_type( $field, 'text' );
1049 817
1050 - if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
1051 - $format = FrmEntryValidate::phone_format( $field );
1052 - $format = substr( $format, 2, - 1 );
818 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
819 + $frm_settings = FrmAppHelper::get_settings();
1053 820
1054 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
821 + if ( $frm_settings->use_html ) {
822 + $format = FrmEntryValidate::phone_format( $field );
823 + $format = substr( $format, 2, - 1 );
824 +
825 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
826 + }
1055 827 }
1056 828 }
1057 829
1058 - /**
1059 - * @param mixed $opt
1060 - * @param mixed $opt_key
1061 - * @param array|object $field
1062 - *
1063 - * @return mixed
1064 - */
1065 830 public static function check_value( $opt, $opt_key, $field ) {
1066 831 if ( is_array( $opt ) ) {
1067 832 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1068 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
833 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1069 834 } else {
1070 - $opt = $opt['label'] ?? reset( $opt );
835 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1071 836 }
1072 837 }
1073 838
1074 839 return $opt;
@@ -1073,17 +838,90 @@
1073 838
1074 839 return $opt;
1075 840 }
1076 841
1077 - /**
1078 - * @param mixed $opt
1079 - *
1080 - * @return mixed
1081 - */
1082 842 public static function check_label( $opt ) {
1083 843 if ( is_array( $opt ) ) {
1084 - $opt = $opt['label'] ?? reset( $opt );
844 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1085 845 }
1086 846
1087 847 return $opt;
848 + }
849 +
850 + /**
851 + * @deprecated 4.0
852 + */
853 + public static function update_ajax_option() {
854 + _deprecated_function( __METHOD__, '4.0' );
855 + FrmAppHelper::permission_check( 'frm_edit_forms' );
856 + check_ajax_referer( 'frm_ajax', 'nonce' );
857 +
858 + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
859 + if ( ! $field_id ) {
860 + wp_die();
861 + }
862 +
863 + $field = FrmField::getOne( $field_id );
864 +
865 + if ( isset( $_POST['separate_value'] ) ) {
866 + $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
867 +
868 + $field->field_options['separate_value'] = $new_val;
869 + unset( $new_val );
870 + }
871 +
872 + FrmField::update(
873 + $field_id,
874 + array(
875 + 'field_options' => $field->field_options,
876 + 'form_id' => $field->form_id,
877 + )
878 + );
879 + wp_die();
880 + }
881 +
882 + /**
883 + * @deprecated 4.0
884 + */
885 + public static function import_choices() {
886 + _deprecated_function( __METHOD__, '4.0' );
887 + wp_die();
888 + }
889 +
890 + /**
891 + * Add Single Option or Other Option.
892 + *
893 + * @deprecated 4.0 Moved to Pro for Other option only.
894 + */
895 + public static function add_option() {
896 + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
897 + }
898 +
899 + /**
900 + * @deprecated 4.0
901 + */
902 + public static function update_order() {
903 + FrmDeprecated::update_order();
904 + }
905 +
906 + /**
907 + * @deprecated 3.0
908 + * @codeCoverageIgnore
909 + */
910 + public static function edit_name( $field = 'name', $id = '' ) {
911 + FrmDeprecated::edit_name( $field, $id );
912 + }
913 +
914 + /**
915 + * @deprecated 3.0
916 + * @codeCoverageIgnore
917 + *
918 + * @param int $field_id
919 + * @param array $values
920 + * @param int $form_id
921 + *
922 + * @return array
923 + */
924 + public static function include_single_field( $field_id, $values, $form_id = 0 ) {
925 + return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
1088 926 }
1089 927 }