PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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 +257 -393 6.255.0 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
@@ -63,15 +56,14 @@
63 56 public static function create() {
64 57 FrmAppHelper::permission_check( 'frm_edit_forms' );
65 58 check_ajax_referer( 'frm_ajax', 'nonce' );
66 59
67 - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
68 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
69 - $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' );
70 62
71 63 do_action( 'frm_before_create_field', $field_type, $form_id );
72 64
73 - $field = self::include_new_field( $field_type, $form_id, $field_options );
65 + $field = self::include_new_field( $field_type, $form_id );
74 66
75 67 // this hook will allow for multiple fields to be added at once
76 68 do_action( 'frm_after_field_created', $field, $form_id );
77 69
@@ -81,29 +73,18 @@
81 73 /**
82 74 * Set up and create a new field
83 75 *
84 76 * @param string $field_type
85 - * @param int $form_id
86 - * @param array $field_options
77 + * @param integer $form_id
87 78 *
88 - * @return array|false
79 + * @return array|bool
89 80 */
90 - public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
81 + public static function include_new_field( $field_type, $form_id ) {
91 82 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
83 + $field_values = apply_filters( 'frm_before_field_created', $field_values );
92 84
93 - if ( ! empty( $field_options ) ) {
94 - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
95 - }
85 + $field_id = FrmField::create( $field_values );
96 86
97 - // When a new field is added to the form, flag it as draft and hide it from the front-end.
98 - $field_values['field_options']['draft'] = 1;
99 -
100 - /**
101 - * @param array $field_values
102 - */
103 - $field_values = apply_filters( 'frm_before_field_created', $field_values );
104 - $field_id = FrmField::create( $field_values );
105 -
106 87 if ( ! $field_id ) {
107 88 return false;
108 89 }
109 90
@@ -130,12 +111,25 @@
130 111
131 112 $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
132 113 $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
133 114
134 - $new_field = FrmField::duplicate_single_field( $field_id, $form_id );
115 + $copy_field = FrmField::getOne( $field_id );
116 + if ( ! $copy_field ) {
117 + wp_die();
118 + }
135 119
136 - if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) {
137 - self::load_single_field( $new_field['field_id'], $new_field['values'] );
120 + do_action( 'frm_duplicate_field', $copy_field, $form_id );
121 + do_action( 'frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id );
122 +
123 + $values = array(
124 + 'id' => $copy_field->id,
125 + );
126 + FrmFieldsHelper::fill_field( $values, $copy_field, $copy_field->form_id );
127 + $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values );
128 +
129 + $field_id = FrmField::create( $values );
130 + if ( $field_id ) {
131 + self::load_single_field( $field_id, $values );
138 132 }
139 133
140 134 wp_die();
141 135 }
@@ -155,11 +149,11 @@
155 149
156 150 /**
157 151 * @since 3.0
158 152 *
159 - * @param array|int|object $field_object
160 - * @param array $values
161 - * @param int $form_id
153 + * @param int|array|object $field_object
154 + * @param array $values
155 + * @param int $form_id
162 156 */
163 157 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
164 158 global $frm_vars;
165 159 $frm_vars['is_admin'] = true;
@@ -173,53 +167,47 @@
173 167
174 168 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
175 169 $display = self::display_field_options( array(), $field_obj );
176 170
177 - $ajax_loading = ! empty( $values['ajax_load'] );
178 - $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
171 + $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
172 + $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) );
179 173
180 174 if ( $ajax_loading && $ajax_this_field ) {
181 175 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
182 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php';
183 - return;
184 - }
176 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' );
177 + } else {
178 + if ( ! isset( $field ) && is_object( $field_object ) ) {
179 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
185 180
186 - if ( ! isset( $field ) && is_object( $field_object ) ) {
187 - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id;
188 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
189 - }
181 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
182 + }
190 183
191 - /**
192 - * Filter for adding extra attributes to the field container.
193 - *
194 - * @since 6.23
195 - *
196 - * @param array $extra_field_attributes
197 - * @param array $field
198 - * @param array $display
199 - */
200 - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display );
184 + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
185 + $li_classes .= ' ui-state-default widgets-holder-wrap';
201 186
202 - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
203 - $li_classes .= ' ui-state-default widgets-holder-wrap';
204 -
205 - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
187 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
188 + }
206 189 }
207 190
208 191 /**
209 192 * @since 3.0
210 - *
211 - * @param array $field
212 - * @param array $display
213 - * @param FrmFieldType $field_info
214 - * @return string
215 193 */
216 194 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
217 - $li_classes = $field_info->form_builder_classes( $display['type'] );
195 + $li_classes = $field_info->form_builder_classes( $display['type'] );
196 + $classes = isset( $field['classes'] ) ? $field['classes'] : '';
197 +
198 + // Exclude alignright for now since we aren't using widths.
199 + $classes = str_replace( ' frm_alignright ', ' ', $classes );
200 + $classes = trim( $classes );
201 +
202 + if ( 'frm_alignright' === $classes ) {
203 + $classes = '';
204 + }
205 +
218 206 $li_classes .= ' frm_form_field frmstart ';
219 207
220 - if ( isset( $field['classes'] ) ) {
221 - $li_classes .= trim( $field['classes'] ) . ' ';
208 + if ( $classes ) {
209 + $li_classes .= $classes . ' ';
222 210 }
223 211
224 212 $li_classes .= 'frmend';
225 213
@@ -238,11 +226,10 @@
238 226 FrmField::destroy( $field_id );
239 227 wp_die();
240 228 }
241 229
242 - /**
243 - * Field Options.
244 - */
230 + /* Field Options */
231 +
245 232 public static function import_options() {
246 233 FrmAppHelper::permission_check( 'frm_edit_forms' );
247 234 check_ajax_referer( 'frm_ajax', 'nonce' );
248 235
@@ -249,23 +236,12 @@
249 236 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
250 237 return;
251 238 }
252 239
253 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
254 - $field = FrmField::getOne( $field_id );
255 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
240 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
241 + $field = FrmField::getOne( $field_id );
256 242
257 - /**
258 - * Filter to add new fields that will support import_options/Bulk Edit Options.
259 - *
260 - * @since 6.8.4
261 - *
262 - * @param array $bulk_edit_types
263 - * @return array
264 - */
265 - $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
266 -
267 - if ( ! in_array( $field->type, $bulk_edit_types, true ) ) {
243 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
268 244 return;
269 245 }
270 246
271 247 $field = FrmFieldsHelper::setup_edit_vars( $field );
@@ -272,15 +248,15 @@
272 248 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
273 249 $opts = explode( "\n", rtrim( $opts, "\n" ) );
274 250 $opts = array_map( 'trim', $opts );
275 251
276 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
277 - $field['separate_value'] = $separate === 'true';
252 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
253 + $field['separate_value'] = ( $separate === 'true' );
278 254
279 255 if ( $field['separate_value'] ) {
280 256 foreach ( $opts as $opt_key => $opt ) {
281 257 if ( strpos( $opt, '|' ) !== false ) {
282 - $vals = explode( '|', $opt );
258 + $vals = explode( '|', $opt );
283 259 $opts[ $opt_key ] = array(
284 260 'label' => trim( $vals[0] ),
285 261 'value' => trim( $vals[1] ),
286 262 );
@@ -314,9 +290,8 @@
314 290 /**
315 291 * @since 4.0
316 292 *
317 293 * @param array $atts - Includes field array, field_obj, display array, values array.
318 - * @return void
319 294 */
320 295 public static function load_single_field_settings( $atts ) {
321 296 $field = $atts['field'];
322 297 $field_obj = $atts['field_obj'];
@@ -331,13 +306,13 @@
331 306 if ( ! isset( $field['read_only'] ) ) {
332 307 $field['read_only'] = false;
333 308 }
334 309
335 - $field_selection_data = self::maybe_define_field_selection_data();
336 - $all_field_types = $field_selection_data->all_field_types;
337 - $disabled_fields = $field_selection_data->disabled_fields;
338 - $frm_settings = FrmAppHelper::get_settings();
339 - $field_types = FrmFieldTypeOptionData::get_field_types( $field['type'] );
310 + $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
311 + $pro_field_selection = FrmField::pro_field_selection();
312 + $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
313 + $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
314 + $frm_settings = FrmAppHelper::get_settings();
340 315
341 316 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
342 317 // Add fallback for an add-on field type that has been deactivated.
343 318 $all_field_types[ $field['type'] ] = array(
@@ -360,76 +335,61 @@
360 335
361 336 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
362 337 $field['placeholder'] = implode( ', ', $field['placeholder'] );
363 338 }
364 -
365 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
339 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
366 340 }
367 341
368 342 /**
369 - * @since 6.9.1
370 - *
371 - * @return FrmFieldSelectionData
372 - */
373 - private static function maybe_define_field_selection_data() {
374 - if ( ! isset( self::$field_selection_data ) ) {
375 - self::$field_selection_data = new FrmFieldSelectionData();
376 - }
377 - return self::$field_selection_data;
378 - }
379 -
380 - /**
381 343 * Get the list of default value types that can be toggled in the builder.
382 344 *
383 345 * @since 4.0
384 - *
385 - * @param array $field
386 - * @param array $atts
387 346 * @return array
388 347 */
389 348 private static function default_value_types( $field, $atts ) {
390 349 $types = array(
391 - 'default_value' => array(
350 + 'default_value' => array(
392 351 'class' => '',
393 352 'icon' => 'frm_icon_font frm_text2_icon',
394 - 'title' => __( 'Default Value', 'formidable' ),
353 + 'title' => __( 'Default Value (Text)', 'formidable' ),
395 354 'data' => array(
396 355 'frmshow' => '#default-value-for-',
397 356 ),
398 357 ),
399 - 'calc' => array(
400 - 'class' => 'frm_show_upgrade frm_noallow',
401 - 'title' => __( 'Calculate Value', 'formidable' ),
402 - 'icon' => 'frm_icon_font frm_calculator_icon',
403 - 'data' => array(
358 + 'calc' => array(
359 + 'class' => 'frm_show_upgrade frm_noallow',
360 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
361 + 'icon' => 'frm_icon_font frm_calculator_icon',
362 + 'data' => array(
404 363 'medium' => 'calculations',
405 364 'upgrade' => __( 'Calculator forms', 'formidable' ),
406 365 ),
407 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
408 366 ),
409 367 'get_values_field' => array(
410 - 'class' => 'frm_show_upgrade frm_noallow',
411 - 'title' => __( 'Lookup', 'formidable' ),
412 - 'icon' => 'frm_icon_font frm_search_icon',
413 - 'data' => array(
368 + 'class' => 'frm_show_upgrade frm_noallow',
369 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
370 + 'icon' => 'frm_icon_font frm_search_icon',
371 + 'data' => array(
414 372 'medium' => 'lookup',
415 373 'upgrade' => __( 'Lookup fields', 'formidable' ),
416 374 ),
417 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
418 375 ),
419 376 );
420 377
421 378 $types = apply_filters( 'frm_default_value_types', $types, $atts );
422 379
380 + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
381 + // Prevent settings from showing in 2 spots.
382 + unset( $types['calc'], $types['get_values_field'] );
383 + }
384 +
423 385 // Set active class.
424 386 $settings = array_keys( $types );
425 387 $active = 'default_value';
426 388
427 - if ( FrmAppHelper::pro_is_connected() ) {
428 - foreach ( $settings as $type ) {
429 - if ( ! empty( $field[ $type ] ) ) {
430 - $active = $type;
431 - }
389 + foreach ( $settings as $type ) {
390 + if ( ! empty( $field[ $type ] ) ) {
391 + $active = $type;
432 392 }
433 393 }
434 394
435 395 $types[ $active ]['class'] .= ' current';
@@ -437,12 +397,8 @@
437 397
438 398 return $types;
439 399 }
440 400
441 - /**
442 - * @param string $type
443 - * @return string
444 - */
445 401 public static function change_type( $type ) {
446 402 $type_switch = array(
447 403 'scale' => 'radio',
448 404 'star' => 'radio',
@@ -455,13 +411,10 @@
455 411 $type = $type_switch[ $type ];
456 412 }
457 413
458 414 $pro_fields = FrmField::pro_field_selection();
459 - // We want to keep credit_card types as credit card types for Stripe Lite.
460 - // The credit_card key is set for backward compatibility.
461 - unset( $pro_fields['credit_card'] );
462 -
463 - if ( array_key_exists( $type, $pro_fields ) ) {
415 + $types = array_keys( $pro_fields );
416 + if ( in_array( $type, $types ) ) {
464 417 $type = 'text';
465 418 }
466 419
467 420 return $type;
@@ -467,18 +420,16 @@
467 420 return $type;
468 421 }
469 422
470 423 /**
471 - * @param array $settings
472 - * @param FrmFieldType|null $field_info
424 + * @param array $settings
425 + * @param object $field_info
473 426 *
474 427 * @return array
475 428 */
476 429 public static function display_field_options( $settings, $field_info = null ) {
477 430 if ( $field_info ) {
478 - $settings = $field_info->display_field_settings();
479 -
480 - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
431 + $settings = $field_info->display_field_settings();
481 432 $settings['field_data'] = $field_info->field;
482 433 }
483 434
484 435 return apply_filters( 'frm_display_field_options', $settings );
@@ -488,23 +439,12 @@
488 439 * Display the format option
489 440 *
490 441 * @since 3.0
491 442 *
492 - * @param array $field Field data.
493 - * @param bool $is_hidden Whether the format option should be hidden.
494 - * @return void
443 + * @param array $field
495 444 */
496 - public static function show_format_option( $field, $is_hidden = false ) {
497 - $attributes = array(
498 - 'class' => 'frm-has-modal',
499 - 'id' => 'frm-field-format-custom-' . $field['id'],
500 - );
501 -
502 - if ( $is_hidden ) {
503 - $attributes['class'] .= ' frm_hidden';
504 - }
505 -
506 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
445 + public static function show_format_option( $field ) {
446 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
507 447 }
508 448
509 449 public static function input_html( $field, $echo = true ) {
510 450 $class = array();
@@ -526,25 +466,20 @@
526 466 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
527 467 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
528 468
529 469 if ( $echo ) {
530 - echo $add_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
470 + echo $add_html; // WPCS: XSS ok.
531 471 }
532 472
533 473 return $add_html;
534 474 }
535 475
536 - /**
537 - * @param array $field
538 - * @param array $class
539 - * @return void
540 - */
541 476 private static function add_input_classes( $field, array &$class ) {
542 - if ( ! empty( $field['input_class'] ) ) {
477 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
543 478 $class[] = $field['input_class'];
544 479 }
545 480
546 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
481 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
547 482 return;
548 483 }
549 484
550 485 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -551,13 +486,8 @@
551 486 $class[] = 'auto_width';
552 487 }
553 488 }
554 489
555 - /**
556 - * @param array $field
557 - * @param array $add_html
558 - * @return void
559 - */
560 490 private static function add_html_size( $field, array &$add_html ) {
561 491 $size_fields = array(
562 492 'select',
563 493 'data',
@@ -566,9 +496,9 @@
566 496 'file',
567 497 'lookup',
568 498 );
569 499
570 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
500 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
571 501 return;
572 502 }
573 503
574 504 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -585,15 +515,10 @@
585 515
586 516 self::add_html_cols( $field, $add_html );
587 517 }
588 518
589 - /**
590 - * @param array $field
591 - * @param array $add_html
592 - * @return void
593 - */
594 519 private static function add_html_cols( $field, array &$add_html ) {
595 - if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
520 + if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
596 521 return;
597 522 }
598 523
599 524 // Convert to cols for textareas.
@@ -615,13 +540,8 @@
615 540
616 541 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
617 542 }
618 543
619 - /**
620 - * @param array $field
621 - * @param array $add_html
622 - * @return void
623 - */
624 544 private static function add_html_length( $field, array &$add_html ) {
625 545 // Check for max setting and if this field accepts maxlength.
626 546 $fields = array(
627 547 'textarea',
@@ -629,9 +549,9 @@
629 549 'hidden',
630 550 'file',
631 551 );
632 552
633 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
553 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
634 554 return;
635 555 }
636 556
637 557 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -641,14 +561,8 @@
641 561
642 562 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
643 563 }
644 564
645 - /**
646 - * @param array $field
647 - * @param array $add_html
648 - * @param array $class
649 - * @return void
650 - */
651 565 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
652 566 if ( $field['default_value'] != '' ) {
653 567 if ( is_array( $field['default_value'] ) ) {
654 568 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
@@ -662,22 +576,37 @@
662 576 // don't include a json placeholder
663 577 return;
664 578 }
665 579
666 - self::add_placeholder_to_input( $field, $add_html );
580 + $frm_settings = FrmAppHelper::get_settings();
581 +
582 + if ( $frm_settings->use_html ) {
583 + self::add_placeholder_to_input( $field, $add_html );
584 + } else {
585 + self::add_frmval_to_input( $field, $add_html );
586 +
587 + $class[] = 'frm_toggle_default';
588 +
589 + if ( $field['value'] == $field['placeholder'] ) {
590 + $class[] = 'frm_default';
591 + }
592 + }
667 593 }
668 594
669 595 /**
670 - * Prepares field placeholder.
671 - *
672 - * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
673 - *
674 - * @param array $field Field array.
596 + * @param array $field
675 597 * @return string
676 598 */
677 599 private static function prepare_placeholder( $field ) {
678 - $placeholder = $field['placeholder'] ?? '';
600 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
601 + $placeholder_is_blank = empty( $placeholder ) && '0' !== $placeholder;
602 + $is_placeholder_field = FrmFieldsHelper::is_placeholder_field_type( $field['type'] );
603 + $is_combo_field = in_array( $field['type'], array( 'address', 'credit_card' ), true );
679 604
605 + if ( $placeholder_is_blank && $is_placeholder_field && ! $is_combo_field ) {
606 + $placeholder = self::get_default_value_from_name( $field );
607 + }
608 +
680 609 return $placeholder;
681 610 }
682 611
683 612 /**
@@ -684,9 +613,8 @@
684 613 * If the label position is "inside",
685 614 * get the label to use as the placeholder
686 615 *
687 616 * @since 2.05
688 - * @since 5.4 Remove the logic code for "inside" label position.
689 617 *
690 618 * @param array $field
691 619 *
692 620 * @return string
@@ -691,9 +619,19 @@
691 619 *
692 620 * @return string
693 621 */
694 622 public static function get_default_value_from_name( $field ) {
695 - return '';
623 + $position = FrmField::get_option( $field, 'label' );
624 + if ( $position == 'inside' ) {
625 + $default_value = $field['name'];
626 + if ( FrmField::is_required( $field ) ) {
627 + $default_value .= ' ' . $field['required_indicator'];
628 + }
629 + } else {
630 + $default_value = '';
631 + }
632 +
633 + return $default_value;
696 634 }
697 635
698 636 /**
699 637 * Maybe add a blank placeholder option before any options
@@ -707,26 +645,14 @@
707 645 if ( empty( $placeholder ) ) {
708 646 $placeholder = self::get_default_value_from_name( $field );
709 647 }
710 648
711 - $use_placeholder = $placeholder;
712 - $autocomplete = FrmField::get_option( $field, 'autocom' );
713 -
714 - if ( $autocomplete ) {
715 - $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
716 - if ( $use_chosen ) {
717 - $use_placeholder = '';
718 - }
719 - }
720 -
721 649 if ( $placeholder !== '' ) {
722 - $placeholder_attributes = array(
723 - 'class' => 'frm-select-placeholder',
724 - 'value' => '',
725 - 'data-placeholder' => 'true',
726 - );
727 -
728 - FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
650 + ?>
651 + <option value="">
652 + <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
653 + </option>
654 + <?php
729 655 return true;
730 656 }
731 657
732 658 return false;
@@ -732,13 +658,12 @@
732 658 return false;
733 659 }
734 660
735 661 /**
736 - * Use HTML5 placeholder with js fallback.
662 + * Use HMTL5 placeholder with js fallback
737 663 *
738 664 * @param array $field
739 665 * @param array $add_html
740 - * @return void
741 666 */
742 667 private static function add_placeholder_to_input( $field, &$add_html ) {
743 668 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
744 669 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -744,13 +669,8 @@
744 669 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
745 670 }
746 671 }
747 672
748 - /**
749 - * @param array $field
750 - * @param array $add_html
751 - * @return void
752 - */
753 673 private static function add_frmval_to_input( $field, &$add_html ) {
754 674 if ( $field['placeholder'] != '' ) {
755 675 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
756 676
@@ -764,138 +684,22 @@
764 684 }
765 685 }
766 686
767 687 private static function add_validation_messages( $field, array &$add_html ) {
768 - $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
769 -
770 - if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
688 + if ( FrmField::is_required( $field ) ) {
771 689 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
772 690 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
773 691 self::maybe_add_html_required( $field, $add_html );
774 692 }
775 693
776 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
694 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
777 695 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
778 696 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
779 697 }
780 -
781 - if ( ! empty( $add_html['data-reqmsg'] ) || ! empty( $add_html['data-invmsg'] ) ) {
782 - self::maybe_add_error_html_for_js_validation( $field, $add_html );
783 - }
784 698 }
785 699
786 700 /**
787 - * Returns an array that contains field validation messages status.
788 - *
789 - * @since 6.9
790 - *
791 - * @param array|object $field
792 - * @return array
793 - */
794 - private static function get_validation_data_attribute_visibility_info( $field ) {
795 - if ( FrmField::get_field_type( $field ) === 'hidden' ) {
796 - $field_validation_data_attributes = array(
797 - 'data-invmsg' => false,
798 - 'data-reqmsg' => false,
799 - );
800 - } else {
801 - $field_validation_data_attributes = array(
802 - 'data-invmsg' => true,
803 - 'data-reqmsg' => true,
804 - );
805 - }
806 -
807 - /**
808 - * Allows controlling which field validation messages would be included in the field html.
809 - *
810 - * @since 6.9
811 - *
812 - * @param array $field_validation_messages_status
813 - * @param array|object $field
814 - */
815 - return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
816 - }
817 -
818 - /**
819 - * @since 5.0.03
820 - *
821 - * @param array $field
822 - * @param array $add_html
823 - * @return void
824 - */
825 - private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
826 - $form = self::get_form_for_js_validation( $field );
827 - if ( false === $form ) {
828 - return;
829 - }
830 -
831 - $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
832 - if ( false !== $error_body ) {
833 - $error_body = urlencode( $error_body );
834 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
835 - }
836 - }
837 -
838 - /**
839 - * @since 5.0.03
840 - *
841 - * @param array $field
842 - * @return false|stdClass false if there is no form object found with JS validation active.
843 - */
844 - private static function get_form_for_js_validation( $field ) {
845 - global $frm_vars;
846 - if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
847 - if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
848 - return $frm_vars['js_validate_forms'][ $field['form_id'] ];
849 - }
850 - if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
851 - return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
852 - }
853 - }
854 - return false;
855 - }
856 -
857 - /**
858 - * @param stdClass $form
859 - * @param array $field
860 - * @param array $errors
861 - * @return false|string
862 - */
863 - public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
864 - if ( empty( $field['custom_html'] ) ) {
865 - return false;
866 - }
867 -
868 - $custom_html = $field['custom_html'];
869 - $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
870 -
871 - $start = strpos( $custom_html, '[if error]' );
872 - if ( false === $start ) {
873 - return false;
874 - }
875 -
876 - $end = strpos( $custom_html, '[/if error]' );
877 - if ( false === $end || $end < $start ) {
878 - return false;
879 - }
880 -
881 - $error_body = substr( $custom_html, $start + 10, $end - $start - 10 );
882 - $default_html = array(
883 - '<div class="frm_error" id="frm_error_field_[key]">[error]</div>',
884 - '<div class="frm_error" role="alert" id="frm_error_field_[key]">[error]</div>',
885 - '<div class="frm_error">[error]</div>',
886 - '<div class="frm_error" role="alert">[error]</div>',
887 - );
888 -
889 - if ( in_array( $error_body, $default_html, true ) ) {
890 - return false;
891 - }
892 -
893 - return $error_body;
894 - }
895 -
896 - /**
897 - * If 'required' is added to a conditionally hidden field, the form won't
701 + * If 'required' is added to a conditionall hidden field, the form won't
898 702 * submit in many browsers. Check to make sure the javascript to conditionally
899 703 * remove it is present if needed.
900 704 *
901 705 * @since 3.06.01
@@ -900,51 +704,27 @@
900 704 *
901 705 * @since 3.06.01
902 706 * @param array $field
903 707 * @param array $add_html
904 - * @return void
905 708 */
906 709 private static function maybe_add_html_required( $field, array &$add_html ) {
907 - $excluded_field_types =
908 - FrmField::is_radio( $field ) ||
909 - FrmField::is_checkbox( $field ) ||
910 - FrmField::is_field_type( $field, 'file' ) ||
911 - FrmField::is_field_type( $field, 'nps' ) ||
912 - FrmField::is_field_type( $field, 'scale' );
913 -
914 - if ( $excluded_field_types ) {
710 + if ( in_array( $field['type'], array( 'radio', 'checkbox', 'file', 'data', 'lookup' ) ) ) {
915 711 return;
916 712 }
917 713
918 - $add_html['aria-required'] = 'aria-required="true"';
714 + $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
715 + if ( $include_html ) {
716 + $add_html['aria-required'] = 'aria-required="true"';
717 + }
919 718 }
920 719
921 - /**
922 - * @param array $field
923 - * @param array $add_html
924 - * @return void
925 - */
926 720 private static function add_shortcodes_to_html( $field, array &$add_html ) {
927 721 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
928 722 return;
929 723 }
930 724
931 - if ( ! empty( $field['autocomplete'] ) ) {
932 - unset( $field['shortcodes']['autocomplete'] );
933 - }
934 -
935 725 foreach ( $field['shortcodes'] as $k => $v ) {
936 - if ( isset( $field['subfield_name'] ) && 0 === strpos( $k, 'aria-invalid' ) ) {
937 - $subfield_name = $field['subfield_name'];
938 - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
939 - continue;
940 - }
941 - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
942 - $k = 'aria-invalid';
943 - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
944 - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
945 - }
946 - if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
726 + if ( 'opt' === $k ) {
947 727 continue;
948 728 }
949 729
950 730 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
@@ -955,45 +735,32 @@
955 735 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
956 736 }
957 737
958 738 unset( $k, $v );
959 - }//end foreach
960 - }
961 -
962 - /**
963 - * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
964 - *
965 - * @since 6.11.2
966 - *
967 - * @param string $key The option key.
968 - * @return bool
969 - */
970 - private static function should_allow_input_attribute( $key ) {
971 - if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
972 - return true;
973 739 }
974 - return FrmAppHelper::input_key_is_safe( $key );
975 740 }
976 741
977 742 /**
978 - * Add pattern attribute.
743 + * Add pattern attribute
979 744 *
980 745 * @since 3.0
981 746 *
982 747 * @param array $field
983 748 * @param array $add_html
984 - * @return void
985 749 */
986 750 private static function add_pattern_attribute( $field, array &$add_html ) {
987 - $format_value = FrmField::get_option( $field, 'format' );
988 - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
751 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
989 752 $format_field = FrmField::is_field_type( $field, 'text' );
990 753
991 - if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
992 - $format = FrmEntryValidate::phone_format( $field );
993 - $format = substr( $format, 2, - 1 );
754 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
755 + $frm_settings = FrmAppHelper::get_settings();
994 756
995 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
757 + if ( $frm_settings->use_html ) {
758 + $format = FrmEntryValidate::phone_format( $field );
759 + $format = substr( $format, 2, - 1 );
760 +
761 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
762 + }
996 763 }
997 764 }
998 765
999 766 public static function check_value( $opt, $opt_key, $field ) {
@@ -998,11 +765,11 @@
998 765
999 766 public static function check_value( $opt, $opt_key, $field ) {
1000 767 if ( is_array( $opt ) ) {
1001 768 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1002 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
769 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1003 770 } else {
1004 - $opt = $opt['label'] ?? reset( $opt );
771 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1005 772 }
1006 773 }
1007 774
1008 775 return $opt;
@@ -1009,10 +776,107 @@
1009 776 }
1010 777
1011 778 public static function check_label( $opt ) {
1012 779 if ( is_array( $opt ) ) {
1013 - $opt = $opt['label'] ?? reset( $opt );
780 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1014 781 }
1015 782
1016 783 return $opt;
784 + }
785 +
786 + /**
787 + * @deprecated 4.0
788 + */
789 + public static function update_ajax_option() {
790 + _deprecated_function( __METHOD__, '4.0' );
791 + FrmAppHelper::permission_check( 'frm_edit_forms' );
792 + check_ajax_referer( 'frm_ajax', 'nonce' );
793 +
794 + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
795 + if ( ! $field_id ) {
796 + wp_die();
797 + }
798 +
799 + $field = FrmField::getOne( $field_id );
800 +
801 + if ( isset( $_POST['separate_value'] ) ) {
802 + $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
803 +
804 + $field->field_options['separate_value'] = $new_val;
805 + unset( $new_val );
806 + }
807 +
808 + FrmField::update(
809 + $field_id,
810 + array(
811 + 'field_options' => $field->field_options,
812 + 'form_id' => $field->form_id,
813 + )
814 + );
815 + wp_die();
816 + }
817 +
818 + /**
819 + * @deprecated 4.0
820 + */
821 + public static function import_choices() {
822 + _deprecated_function( __METHOD__, '4.0' );
823 + wp_die();
824 + }
825 +
826 + /**
827 + * Add Single Option or Other Option.
828 + *
829 + * @deprecated 4.0 Moved to Pro for Other option only.
830 + */
831 + public static function add_option() {
832 + _deprecated_function( __METHOD__, '4.0', 'FrmProFormsController::add_other_option' );
833 + if ( is_callable( 'FrmProFormsController::add_other_option' ) ) {
834 + FrmProFormsController::add_other_option();
835 + }
836 + }
837 +
838 + /**
839 + * @deprecated 4.0
840 + */
841 + public static function update_order() {
842 + FrmDeprecated::update_order();
843 + }
844 +
845 + /**
846 + * @deprecated 3.0
847 + * @codeCoverageIgnore
848 + */
849 + public static function edit_name( $field = 'name', $id = '' ) {
850 + FrmDeprecated::edit_name( $field, $id );
851 + }
852 +
853 + /**
854 + * @deprecated 3.0
855 + * @codeCoverageIgnore
856 + *
857 + * @param int $field_id
858 + * @param array $values
859 + * @param int $form_id
860 + *
861 + * @return array
862 + */
863 + public static function include_single_field( $field_id, $values, $form_id = 0 ) {
864 + return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
865 + }
866 +
867 + /**
868 + * @deprecated 2.3
869 + * @codeCoverageIgnore
870 + */
871 + public static function edit_option() {
872 + FrmDeprecated::deprecated( __METHOD__, '2.3' );
873 + }
874 +
875 + /**
876 + * @deprecated 2.3
877 + * @codeCoverageIgnore
878 + */
879 + public static function delete_option() {
880 + FrmDeprecated::deprecated( __METHOD__, '2.3' );
1017 881 }
1018 882 }