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
formidable / classes / controllers / FrmFieldsController.php

FrmFieldsController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.0, at classes/controllers/FrmFieldsController.php

883 lines 24.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmFieldsController {
7
8 public static function load_field() {
9 FrmAppHelper::permission_check( 'frm_edit_forms' );
10 check_ajax_referer( 'frm_ajax', 'nonce' );
11
12 // Javascript may be included in some field settings.
13 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
14 $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array();
15 if ( empty( $fields ) ) {
16 wp_die();
17 }
18
19 $_GET['page'] = 'formidable';
20
21 $values = array(
22 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
23 'doing_ajax' => true,
24 );
25 $field_html = array();
26
27 foreach ( $fields as $field ) {
28 $field = htmlspecialchars_decode( nl2br( $field ) );
29 $field = json_decode( $field );
30 if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
31 // this field may have already been loaded
32 continue;
33 }
34
35 if ( ! isset( $field->value ) ) {
36 $field->value = '';
37 }
38 $field->field_options = json_decode( json_encode( $field->field_options ), true );
39 $field->options = json_decode( json_encode( $field->options ), true );
40 $field->default_value = json_decode( json_encode( $field->default_value ), true );
41
42 ob_start();
43 self::load_single_field( $field, $values );
44 $field_html[ absint( $field->id ) ] = ob_get_contents();
45 ob_end_clean();
46 }
47
48 echo json_encode( $field_html );
49
50 wp_die();
51 }
52
53 /**
54 * Create a new field with ajax
55 */
56 public static function create() {
57 FrmAppHelper::permission_check( 'frm_edit_forms' );
58 check_ajax_referer( 'frm_ajax', 'nonce' );
59
60 $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
61 $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
62
63 do_action( 'frm_before_create_field', $field_type, $form_id );
64
65 $field = self::include_new_field( $field_type, $form_id );
66
67 // this hook will allow for multiple fields to be added at once
68 do_action( 'frm_after_field_created', $field, $form_id );
69
70 wp_die();
71 }
72
73 /**
74 * Set up and create a new field
75 *
76 * @param string $field_type
77 * @param integer $form_id
78 *
79 * @return array|bool
80 */
81 public static function include_new_field( $field_type, $form_id ) {
82 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
83 $field_values = apply_filters( 'frm_before_field_created', $field_values );
84
85 $field_id = FrmField::create( $field_values );
86
87 if ( ! $field_id ) {
88 return false;
89 }
90
91 $field = self::get_field_array_from_id( $field_id );
92
93 $values = array();
94 if ( FrmAppHelper::pro_is_installed() ) {
95 $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
96
97 $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
98 if ( $parent_form_id ) {
99 $field['parent_form_id'] = $parent_form_id;
100 }
101 }
102
103 self::load_single_field( $field, $values, $form_id );
104
105 return $field;
106 }
107
108 public static function duplicate() {
109 FrmAppHelper::permission_check( 'frm_edit_forms' );
110 check_ajax_referer( 'frm_ajax', 'nonce' );
111
112 $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
113 $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
114
115 $copy_field = FrmField::getOne( $field_id );
116 if ( ! $copy_field ) {
117 wp_die();
118 }
119
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 );
132 }
133
134 wp_die();
135 }
136
137 /**
138 * @since 3.0
139 *
140 * @param int $field_id
141 *
142 * @return array
143 */
144 public static function get_field_array_from_id( $field_id ) {
145 $field = FrmField::getOne( $field_id );
146
147 return FrmFieldsHelper::setup_edit_vars( $field );
148 }
149
150 /**
151 * @since 3.0
152 *
153 * @param int|array|object $field_object
154 * @param array $values
155 * @param int $form_id
156 */
157 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
158 global $frm_vars;
159 $frm_vars['is_admin'] = true;
160
161 if ( is_numeric( $field_object ) ) {
162 $field_object = FrmField::getOne( $field_object );
163 } elseif ( is_array( $field_object ) ) {
164 $field = $field_object;
165 $field_object = FrmField::getOne( $field['id'] );
166 }
167
168 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
169 $display = self::display_field_options( array(), $field_obj );
170
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' ) );
173
174 if ( $ajax_loading && $ajax_this_field ) {
175 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
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;
180
181 $field = FrmFieldsHelper::setup_edit_vars( $field_object );
182 }
183
184 $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
185 $li_classes .= ' ui-state-default widgets-holder-wrap';
186
187 require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
188 }
189 }
190
191 /**
192 * @since 3.0
193 */
194 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
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
206 $li_classes .= ' frm_form_field frmstart ';
207
208 if ( $classes ) {
209 $li_classes .= $classes . ' ';
210 }
211
212 $li_classes .= 'frmend';
213
214 if ( $field ) {
215 $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
216 }
217
218 return $li_classes;
219 }
220
221 public static function destroy() {
222 FrmAppHelper::permission_check( 'frm_edit_forms' );
223 check_ajax_referer( 'frm_ajax', 'nonce' );
224
225 $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
226 FrmField::destroy( $field_id );
227 wp_die();
228 }
229
230 /* Field Options */
231
232 public static function import_options() {
233 FrmAppHelper::permission_check( 'frm_edit_forms' );
234 check_ajax_referer( 'frm_ajax', 'nonce' );
235
236 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
237 return;
238 }
239
240 $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
241 $field = FrmField::getOne( $field_id );
242
243 if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
244 return;
245 }
246
247 $field = FrmFieldsHelper::setup_edit_vars( $field );
248 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
249 $opts = explode( "\n", rtrim( $opts, "\n" ) );
250 $opts = array_map( 'trim', $opts );
251
252 $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
253 $field['separate_value'] = ( $separate === 'true' );
254
255 if ( $field['separate_value'] ) {
256 foreach ( $opts as $opt_key => $opt ) {
257 if ( strpos( $opt, '|' ) !== false ) {
258 $vals = explode( '|', $opt );
259 $opts[ $opt_key ] = array(
260 'label' => trim( $vals[0] ),
261 'value' => trim( $vals[1] ),
262 );
263 unset( $vals );
264 }
265 unset( $opt_key, $opt );
266 }
267 }
268
269 // Keep other options after bulk update.
270 if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
271 $other_array = array();
272 foreach ( $field['options'] as $opt_key => $opt ) {
273 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
274 $other_array[ $opt_key ] = $opt;
275 }
276 unset( $opt_key, $opt );
277 }
278 if ( ! empty( $other_array ) ) {
279 $opts = array_merge( $opts, $other_array );
280 }
281 }
282
283 $field['options'] = $opts;
284
285 FrmFieldsHelper::show_single_option( $field );
286
287 wp_die();
288 }
289
290 /**
291 * @since 4.0
292 *
293 * @param array $atts - Includes field array, field_obj, display array, values array.
294 */
295 public static function load_single_field_settings( $atts ) {
296 $field = $atts['field'];
297 $field_obj = $atts['field_obj'];
298 $values = $atts['values'];
299 $display = $atts['display'];
300 unset( $atts );
301
302 if ( ! isset( $field['unique'] ) ) {
303 $field['unique'] = false;
304 }
305
306 if ( ! isset( $field['read_only'] ) ) {
307 $field['read_only'] = false;
308 }
309
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();
315
316 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
317 // Add fallback for an add-on field type that has been deactivated.
318 $all_field_types[ $field['type'] ] = array(
319 'name' => ucfirst( $field['type'] ),
320 'icon' => 'frm_icon_font frm_pencil_icon',
321 );
322 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
323 // Fallback for fields added in a more basic way.
324 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
325 }
326
327 $type_name = $all_field_types[ $field['type'] ]['name'];
328 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
329 $type_name = $all_field_types['divider|repeat']['name'];
330 }
331
332 if ( $display['default'] ) {
333 $default_value_types = self::default_value_types( $field, compact( 'display' ) );
334 }
335
336 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
337 $field['placeholder'] = implode( ', ', $field['placeholder'] );
338 }
339 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
340 }
341
342 /**
343 * Get the list of default value types that can be toggled in the builder.
344 *
345 * @since 4.0
346 * @return array
347 */
348 private static function default_value_types( $field, $atts ) {
349 $types = array(
350 'default_value' => array(
351 'class' => '',
352 'icon' => 'frm_icon_font frm_text2_icon',
353 'title' => __( 'Default Value (Text)', 'formidable' ),
354 'data' => array(
355 'frmshow' => '#default-value-for-',
356 ),
357 ),
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(
363 'medium' => 'calculations',
364 'upgrade' => __( 'Calculator forms', 'formidable' ),
365 ),
366 ),
367 'get_values_field' => 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(
372 'medium' => 'lookup',
373 'upgrade' => __( 'Lookup fields', 'formidable' ),
374 ),
375 ),
376 );
377
378 $types = apply_filters( 'frm_default_value_types', $types, $atts );
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
385 // Set active class.
386 $settings = array_keys( $types );
387 $active = 'default_value';
388
389 foreach ( $settings as $type ) {
390 if ( ! empty( $field[ $type ] ) ) {
391 $active = $type;
392 }
393 }
394
395 $types[ $active ]['class'] .= ' current';
396 $types[ $active ]['current'] = true;
397
398 return $types;
399 }
400
401 public static function change_type( $type ) {
402 $type_switch = array(
403 'scale' => 'radio',
404 'star' => 'radio',
405 '10radio' => 'radio',
406 'rte' => 'textarea',
407 'website' => 'url',
408 'image' => 'url',
409 );
410 if ( isset( $type_switch[ $type ] ) ) {
411 $type = $type_switch[ $type ];
412 }
413
414 $pro_fields = FrmField::pro_field_selection();
415 $types = array_keys( $pro_fields );
416 if ( in_array( $type, $types ) ) {
417 $type = 'text';
418 }
419
420 return $type;
421 }
422
423 /**
424 * @param array $settings
425 * @param object $field_info
426 *
427 * @return array
428 */
429 public static function display_field_options( $settings, $field_info = null ) {
430 if ( $field_info ) {
431 $settings = $field_info->display_field_settings();
432 $settings['field_data'] = $field_info->field;
433 }
434
435 return apply_filters( 'frm_display_field_options', $settings );
436 }
437
438 /**
439 * Display the format option
440 *
441 * @since 3.0
442 *
443 * @param array $field
444 */
445 public static function show_format_option( $field ) {
446 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
447 }
448
449 public static function input_html( $field, $echo = true ) {
450 $class = array();
451 self::add_input_classes( $field, $class );
452
453 $add_html = array();
454 self::add_html_size( $field, $add_html );
455 self::add_html_length( $field, $add_html );
456 self::add_html_placeholder( $field, $add_html, $class );
457 self::add_validation_messages( $field, $add_html );
458
459 $class = apply_filters( 'frm_field_classes', implode( ' ', $class ), $field );
460
461 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
462
463 self::add_shortcodes_to_html( $field, $add_html );
464 self::add_pattern_attribute( $field, $add_html );
465
466 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
467 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
468
469 if ( $echo ) {
470 echo $add_html; // WPCS: XSS ok.
471 }
472
473 return $add_html;
474 }
475
476 private static function add_input_classes( $field, array &$class ) {
477 if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
478 $class[] = $field['input_class'];
479 }
480
481 if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
482 return;
483 }
484
485 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
486 $class[] = 'auto_width';
487 }
488 }
489
490 private static function add_html_size( $field, array &$add_html ) {
491 $size_fields = array(
492 'select',
493 'data',
494 'time',
495 'hidden',
496 'file',
497 'lookup',
498 );
499
500 if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
501 return;
502 }
503
504 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
505 return;
506 }
507
508 if ( is_numeric( $field['size'] ) ) {
509 $field['size'] .= 'px';
510 }
511
512 $important = apply_filters( 'frm_use_important_width', 1, $field );
513 // Note: This inline styling must stay since we cannot realistically set a class for every possible field size.
514 $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"';
515
516 self::add_html_cols( $field, $add_html );
517 }
518
519 private static function add_html_cols( $field, array &$add_html ) {
520 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
521 return;
522 }
523
524 // Convert to cols for textareas.
525 $calc = array(
526 '' => 9,
527 'px' => 9,
528 'rem' => 0.444,
529 'em' => 0.544,
530 );
531
532 // include "col" for valid html
533 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
534
535 if ( ! isset( $calc[ $unit ] ) ) {
536 return;
537 }
538
539 $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
540
541 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
542 }
543
544 private static function add_html_length( $field, array &$add_html ) {
545 // Check for max setting and if this field accepts maxlength.
546 $fields = array(
547 'textarea',
548 'rte',
549 'hidden',
550 'file',
551 );
552
553 if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
554 return;
555 }
556
557 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
558 // Don't load on form builder page.
559 return;
560 }
561
562 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
563 }
564
565 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
566 if ( $field['default_value'] != '' ) {
567 if ( is_array( $field['default_value'] ) ) {
568 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
569 } else {
570 self::add_frmval_to_input( $field, $add_html );
571 }
572 }
573
574 $field['placeholder'] = self::prepare_placeholder( $field );
575 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
576 // don't include a json placeholder
577 return;
578 }
579
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 }
593 }
594
595 /**
596 * @param array $field
597 * @return string
598 */
599 private static function prepare_placeholder( $field ) {
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 );
604
605 if ( $placeholder_is_blank && $is_placeholder_field && ! $is_combo_field ) {
606 $placeholder = self::get_default_value_from_name( $field );
607 }
608
609 return $placeholder;
610 }
611
612 /**
613 * If the label position is "inside",
614 * get the label to use as the placeholder
615 *
616 * @since 2.05
617 *
618 * @param array $field
619 *
620 * @return string
621 */
622 public static function get_default_value_from_name( $field ) {
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;
634 }
635
636 /**
637 * Maybe add a blank placeholder option before any options
638 * in a dropdown.
639 *
640 * @since 4.04
641 * @return bool True if placeholder was added.
642 */
643 public static function add_placeholder_to_select( $field ) {
644 $placeholder = FrmField::get_option( $field, 'placeholder' );
645 if ( empty( $placeholder ) ) {
646 $placeholder = self::get_default_value_from_name( $field );
647 }
648
649 if ( $placeholder !== '' ) {
650 ?>
651 <option value="">
652 <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
653 </option>
654 <?php
655 return true;
656 }
657
658 return false;
659 }
660
661 /**
662 * Use HMTL5 placeholder with js fallback
663 *
664 * @param array $field
665 * @param array $add_html
666 */
667 private static function add_placeholder_to_input( $field, &$add_html ) {
668 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
669 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
670 }
671 }
672
673 private static function add_frmval_to_input( $field, &$add_html ) {
674 if ( $field['placeholder'] != '' ) {
675 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
676
677 if ( 'select' === $field['type'] ) {
678 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
679 }
680 }
681
682 if ( $field['default_value'] != '' ) {
683 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
684 }
685 }
686
687 private static function add_validation_messages( $field, array &$add_html ) {
688 if ( FrmField::is_required( $field ) ) {
689 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
690 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
691 self::maybe_add_html_required( $field, $add_html );
692 }
693
694 if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
695 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
696 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
697 }
698 }
699
700 /**
701 * If 'required' is added to a conditionall hidden field, the form won't
702 * submit in many browsers. Check to make sure the javascript to conditionally
703 * remove it is present if needed.
704 *
705 * @since 3.06.01
706 * @param array $field
707 * @param array $add_html
708 */
709 private static function maybe_add_html_required( $field, array &$add_html ) {
710 if ( in_array( $field['type'], array( 'radio', 'checkbox', 'file', 'data', 'lookup' ) ) ) {
711 return;
712 }
713
714 $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
715 if ( $include_html ) {
716 $add_html['aria-required'] = 'aria-required="true"';
717 }
718 }
719
720 private static function add_shortcodes_to_html( $field, array &$add_html ) {
721 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
722 return;
723 }
724
725 foreach ( $field['shortcodes'] as $k => $v ) {
726 if ( 'opt' === $k ) {
727 continue;
728 }
729
730 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
731 $add_html[] = $v;
732 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
733 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
734 } else {
735 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
736 }
737
738 unset( $k, $v );
739 }
740 }
741
742 /**
743 * Add pattern attribute
744 *
745 * @since 3.0
746 *
747 * @param array $field
748 * @param array $add_html
749 */
750 private static function add_pattern_attribute( $field, array &$add_html ) {
751 $has_format = FrmField::is_option_true_in_array( $field, 'format' );
752 $format_field = FrmField::is_field_type( $field, 'text' );
753
754 if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
755 $frm_settings = FrmAppHelper::get_settings();
756
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 }
763 }
764 }
765
766 public static function check_value( $opt, $opt_key, $field ) {
767 if ( is_array( $opt ) ) {
768 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
769 $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
770 } else {
771 $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
772 }
773 }
774
775 return $opt;
776 }
777
778 public static function check_label( $opt ) {
779 if ( is_array( $opt ) ) {
780 $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
781 }
782
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' );
881 }
882 }
883