PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.07.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.07.01
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 4.07.01, at classes/controllers/FrmFieldsController.php

869 lines 23.9 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 if ( trim( $classes ) === 'frm_alignright' ) {
201 $classes = '';
202 }
203
204 $li_classes .= ' frm_form_field frmstart ' . $classes . ' frmend';
205 if ( ! empty( $field ) ) {
206 $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
207 }
208
209 return $li_classes;
210 }
211
212 public static function destroy() {
213 FrmAppHelper::permission_check( 'frm_edit_forms' );
214 check_ajax_referer( 'frm_ajax', 'nonce' );
215
216 $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
217 FrmField::destroy( $field_id );
218 wp_die();
219 }
220
221 /* Field Options */
222
223 public static function import_options() {
224 FrmAppHelper::permission_check( 'frm_edit_forms' );
225 check_ajax_referer( 'frm_ajax', 'nonce' );
226
227 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
228 return;
229 }
230
231 $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
232 $field = FrmField::getOne( $field_id );
233
234 if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
235 return;
236 }
237
238 $field = FrmFieldsHelper::setup_edit_vars( $field );
239 $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
240 $opts = explode( "\n", rtrim( $opts, "\n" ) );
241 $opts = array_map( 'trim', $opts );
242
243 $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
244 $field['separate_value'] = ( $separate === 'true' );
245
246 if ( $field['separate_value'] ) {
247 foreach ( $opts as $opt_key => $opt ) {
248 if ( strpos( $opt, '|' ) !== false ) {
249 $vals = explode( '|', $opt );
250 $opts[ $opt_key ] = array(
251 'label' => trim( $vals[0] ),
252 'value' => trim( $vals[1] ),
253 );
254 unset( $vals );
255 }
256 unset( $opt_key, $opt );
257 }
258 }
259
260 // Keep other options after bulk update.
261 if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
262 $other_array = array();
263 foreach ( $field['options'] as $opt_key => $opt ) {
264 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
265 $other_array[ $opt_key ] = $opt;
266 }
267 unset( $opt_key, $opt );
268 }
269 if ( ! empty( $other_array ) ) {
270 $opts = array_merge( $opts, $other_array );
271 }
272 }
273
274 $field['options'] = $opts;
275
276 FrmFieldsHelper::show_single_option( $field );
277
278 wp_die();
279 }
280
281 /**
282 * @since 4.0
283 *
284 * @param array $atts - Includes field array, field_obj, display array, values array.
285 */
286 public static function load_single_field_settings( $atts ) {
287 $field = $atts['field'];
288 $field_obj = $atts['field_obj'];
289 $values = $atts['values'];
290 $display = $atts['display'];
291 unset( $atts );
292
293 if ( ! isset( $field['unique'] ) ) {
294 $field['unique'] = false;
295 }
296
297 if ( ! isset( $field['read_only'] ) ) {
298 $field['read_only'] = false;
299 }
300
301 $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
302 $pro_field_selection = FrmField::pro_field_selection();
303 $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
304 $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
305 $frm_settings = FrmAppHelper::get_settings();
306
307 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
308 // Add fallback for an add-on field type that has been deactivated.
309 $all_field_types[ $field['type'] ] = array(
310 'name' => ucfirst( $field['type'] ),
311 'icon' => 'frm_icon_font frm_pencil_icon',
312 );
313 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
314 // Fallback for fields added in a more basic way.
315 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
316 }
317
318 $type_name = $all_field_types[ $field['type'] ]['name'];
319 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
320 $type_name = $all_field_types['divider|repeat']['name'];
321 }
322
323 if ( $display['default'] ) {
324 $default_value_types = self::default_value_types( $field, compact( 'display' ) );
325 }
326
327 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
328 $field['placeholder'] = implode( ', ', $field['placeholder'] );
329 }
330 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
331 }
332
333 /**
334 * Get the list of default value types that can be toggled in the builder.
335 *
336 * @since 4.0
337 * @return array
338 */
339 private static function default_value_types( $field, $atts ) {
340 $types = array(
341 'default_value' => array(
342 'class' => '',
343 'icon' => 'frm_icon_font frm_text2_icon',
344 'title' => __( 'Default Value (Text)', 'formidable' ),
345 'data' => array(
346 'frmshow' => '#default-value-for-',
347 ),
348 ),
349 'calc' => array(
350 'class' => 'frm_show_upgrade frm_noallow',
351 'title' => __( 'Default Value (Calculation)', 'formidable' ),
352 'icon' => 'frm_icon_font frm_calculator_icon',
353 'data' => array(
354 'medium' => 'calculations',
355 'upgrade' => __( 'Calculator forms', 'formidable' ),
356 ),
357 ),
358 'get_values_field' => array(
359 'class' => 'frm_show_upgrade frm_noallow',
360 'title' => __( 'Default Value (Lookup)', 'formidable' ),
361 'icon' => 'frm_icon_font frm_search_icon',
362 'data' => array(
363 'medium' => 'lookup',
364 'upgrade' => __( 'Lookup fields', 'formidable' ),
365 ),
366 ),
367 );
368
369 $types = apply_filters( 'frm_default_value_types', $types, $atts );
370
371 if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
372 // Prevent settings from showing in 2 spots.
373 unset( $types['calc'], $types['get_values_field'] );
374 }
375
376 // Set active class.
377 $settings = array_keys( $types );
378 $active = 'default_value';
379
380 foreach ( $settings as $type ) {
381 if ( ! empty( $field[ $type ] ) ) {
382 $active = $type;
383 }
384 }
385
386 $types[ $active ]['class'] .= ' current';
387 $types[ $active ]['current'] = true;
388
389 return $types;
390 }
391
392 public static function change_type( $type ) {
393 $type_switch = array(
394 'scale' => 'radio',
395 'star' => 'radio',
396 '10radio' => 'radio',
397 'rte' => 'textarea',
398 'website' => 'url',
399 'image' => 'url',
400 );
401 if ( isset( $type_switch[ $type ] ) ) {
402 $type = $type_switch[ $type ];
403 }
404
405 $pro_fields = FrmField::pro_field_selection();
406 $types = array_keys( $pro_fields );
407 if ( in_array( $type, $types ) ) {
408 $type = 'text';
409 }
410
411 return $type;
412 }
413
414 /**
415 * @param array $settings
416 * @param object $field_info
417 *
418 * @return array
419 */
420 public static function display_field_options( $settings, $field_info = null ) {
421 if ( $field_info ) {
422 $settings = $field_info->display_field_settings();
423 $settings['field_data'] = $field_info->field;
424 }
425
426 return apply_filters( 'frm_display_field_options', $settings );
427 }
428
429 /**
430 * Display the format option
431 *
432 * @since 3.0
433 *
434 * @param array $field
435 */
436 public static function show_format_option( $field ) {
437 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
438 }
439
440 public static function input_html( $field, $echo = true ) {
441 $class = array();
442 self::add_input_classes( $field, $class );
443
444 $add_html = array();
445 self::add_html_size( $field, $add_html );
446 self::add_html_length( $field, $add_html );
447 self::add_html_placeholder( $field, $add_html, $class );
448 self::add_validation_messages( $field, $add_html );
449
450 $class = apply_filters( 'frm_field_classes', implode( ' ', $class ), $field );
451
452 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
453
454 self::add_shortcodes_to_html( $field, $add_html );
455 self::add_pattern_attribute( $field, $add_html );
456
457 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
458 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
459
460 if ( $echo ) {
461 echo $add_html; // WPCS: XSS ok.
462 }
463
464 return $add_html;
465 }
466
467 private static function add_input_classes( $field, array &$class ) {
468 if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
469 $class[] = $field['input_class'];
470 }
471
472 if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
473 return;
474 }
475
476 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
477 $class[] = 'auto_width';
478 }
479 }
480
481 private static function add_html_size( $field, array &$add_html ) {
482 $size_fields = array(
483 'select',
484 'data',
485 'time',
486 'hidden',
487 'file',
488 'lookup',
489 );
490
491 if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
492 return;
493 }
494
495 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
496 return;
497 }
498
499 if ( is_numeric( $field['size'] ) ) {
500 $field['size'] .= 'px';
501 }
502
503 $important = apply_filters( 'frm_use_important_width', 1, $field );
504 // Note: This inline styling must stay since we cannot realistically set a class for every possible field size.
505 $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"';
506
507 self::add_html_cols( $field, $add_html );
508 }
509
510 private static function add_html_cols( $field, array &$add_html ) {
511 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
512 return;
513 }
514
515 // Convert to cols for textareas.
516 $calc = array(
517 '' => 9,
518 'px' => 9,
519 'rem' => 0.444,
520 'em' => 0.544,
521 );
522
523 // include "col" for valid html
524 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
525
526 if ( ! isset( $calc[ $unit ] ) ) {
527 return;
528 }
529
530 $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
531
532 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
533 }
534
535 private static function add_html_length( $field, array &$add_html ) {
536 // Check for max setting and if this field accepts maxlength.
537 $fields = array(
538 'textarea',
539 'rte',
540 'hidden',
541 'file',
542 );
543
544 if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
545 return;
546 }
547
548 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
549 // Don't load on form builder page.
550 return;
551 }
552
553 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
554 }
555
556 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
557 if ( $field['default_value'] != '' ) {
558 if ( is_array( $field['default_value'] ) ) {
559 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
560 } else {
561 self::add_frmval_to_input( $field, $add_html );
562 }
563 }
564
565 $field['placeholder'] = self::prepare_placeholder( $field );
566 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
567 // don't include a json placeholder
568 return;
569 }
570
571 $frm_settings = FrmAppHelper::get_settings();
572
573 if ( $frm_settings->use_html ) {
574 self::add_placeholder_to_input( $field, $add_html );
575 } else {
576 self::add_frmval_to_input( $field, $add_html );
577
578 $class[] = 'frm_toggle_default';
579
580 if ( $field['value'] == $field['placeholder'] ) {
581 $class[] = 'frm_default';
582 }
583 }
584 }
585
586 private static function prepare_placeholder( $field ) {
587 $is_placeholder_field = FrmFieldsHelper::is_placeholder_field_type( $field['type'] );
588 $is_combo_field = in_array( $field['type'], array( 'address', 'credit_card' ) );
589
590 $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
591 if ( empty( $placeholder ) && $is_placeholder_field && ! $is_combo_field ) {
592 $placeholder = self::get_default_value_from_name( $field );
593 }
594
595 return $placeholder;
596 }
597
598 /**
599 * If the label position is "inside",
600 * get the label to use as the placeholder
601 *
602 * @since 2.05
603 *
604 * @param array $field
605 *
606 * @return string
607 */
608 public static function get_default_value_from_name( $field ) {
609 $position = FrmField::get_option( $field, 'label' );
610 if ( $position == 'inside' ) {
611 $default_value = $field['name'];
612 if ( FrmField::is_required( $field ) ) {
613 $default_value .= ' ' . $field['required_indicator'];
614 }
615 } else {
616 $default_value = '';
617 }
618
619 return $default_value;
620 }
621
622 /**
623 * Maybe add a blank placeholder option before any options
624 * in a dropdown.
625 *
626 * @since 4.04
627 * @return bool True if placeholder was added.
628 */
629 public static function add_placeholder_to_select( $field ) {
630 $placeholder = FrmField::get_option( $field, 'placeholder' );
631 if ( empty( $placeholder ) ) {
632 $placeholder = self::get_default_value_from_name( $field );
633 }
634
635 if ( $placeholder !== '' ) {
636 ?>
637 <option value="">
638 <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
639 </option>
640 <?php
641 return true;
642 }
643
644 return false;
645 }
646
647 /**
648 * Use HMTL5 placeholder with js fallback
649 *
650 * @param array $field
651 * @param array $add_html
652 */
653 private static function add_placeholder_to_input( $field, &$add_html ) {
654 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
655 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
656 }
657 }
658
659 private static function add_frmval_to_input( $field, &$add_html ) {
660 if ( $field['placeholder'] != '' ) {
661 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
662
663 if ( 'select' === $field['type'] ) {
664 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
665 }
666 }
667
668 if ( $field['default_value'] != '' ) {
669 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
670 }
671 }
672
673 private static function add_validation_messages( $field, array &$add_html ) {
674 if ( FrmField::is_required( $field ) ) {
675 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
676 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
677 self::maybe_add_html_required( $field, $add_html );
678 }
679
680 if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
681 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
682 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
683 }
684 }
685
686 /**
687 * If 'required' is added to a conditionall hidden field, the form won't
688 * submit in many browsers. Check to make sure the javascript to conditionally
689 * remove it is present if needed.
690 *
691 * @since 3.06.01
692 * @param array $field
693 * @param array $add_html
694 */
695 private static function maybe_add_html_required( $field, array &$add_html ) {
696 if ( in_array( $field['type'], array( 'radio', 'checkbox', 'file', 'data', 'lookup' ) ) ) {
697 return;
698 }
699
700 $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
701 if ( $include_html ) {
702 $add_html['aria-required'] = 'aria-required="true"';
703 }
704 }
705
706 private static function add_shortcodes_to_html( $field, array &$add_html ) {
707 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
708 return;
709 }
710
711 foreach ( $field['shortcodes'] as $k => $v ) {
712 if ( 'opt' === $k ) {
713 continue;
714 }
715
716 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
717 $add_html[] = $v;
718 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
719 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
720 } else {
721 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
722 }
723
724 unset( $k, $v );
725 }
726 }
727
728 /**
729 * Add pattern attribute
730 *
731 * @since 3.0
732 *
733 * @param array $field
734 * @param array $add_html
735 */
736 private static function add_pattern_attribute( $field, array &$add_html ) {
737 $has_format = FrmField::is_option_true_in_array( $field, 'format' );
738 $format_field = FrmField::is_field_type( $field, 'text' );
739
740 if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
741 $frm_settings = FrmAppHelper::get_settings();
742
743 if ( $frm_settings->use_html ) {
744 $format = FrmEntryValidate::phone_format( $field );
745 $format = substr( $format, 2, - 1 );
746
747 $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
748 }
749 }
750 }
751
752 public static function check_value( $opt, $opt_key, $field ) {
753 if ( is_array( $opt ) ) {
754 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
755 $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
756 } else {
757 $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
758 }
759 }
760
761 return $opt;
762 }
763
764 public static function check_label( $opt ) {
765 if ( is_array( $opt ) ) {
766 $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
767 }
768
769 return $opt;
770 }
771
772 /**
773 * @deprecated 4.0
774 */
775 public static function update_ajax_option() {
776 _deprecated_function( __METHOD__, '4.0' );
777 FrmAppHelper::permission_check( 'frm_edit_forms' );
778 check_ajax_referer( 'frm_ajax', 'nonce' );
779
780 $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
781 if ( ! $field_id ) {
782 wp_die();
783 }
784
785 $field = FrmField::getOne( $field_id );
786
787 if ( isset( $_POST['separate_value'] ) ) {
788 $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
789
790 $field->field_options['separate_value'] = $new_val;
791 unset( $new_val );
792 }
793
794 FrmField::update(
795 $field_id,
796 array(
797 'field_options' => $field->field_options,
798 'form_id' => $field->form_id,
799 )
800 );
801 wp_die();
802 }
803
804 /**
805 * @deprecated 4.0
806 */
807 public static function import_choices() {
808 _deprecated_function( __METHOD__, '4.0' );
809 wp_die();
810 }
811
812 /**
813 * Add Single Option or Other Option.
814 *
815 * @deprecated 4.0 Moved to Pro for Other option only.
816 */
817 public static function add_option() {
818 _deprecated_function( __METHOD__, '4.0', 'FrmProFormsController::add_other_option' );
819 if ( is_callable( 'FrmProFormsController::add_other_option' ) ) {
820 FrmProFormsController::add_other_option();
821 }
822 }
823
824 /**
825 * @deprecated 4.0
826 */
827 public static function update_order() {
828 FrmDeprecated::update_order();
829 }
830
831 /**
832 * @deprecated 3.0
833 * @codeCoverageIgnore
834 */
835 public static function edit_name( $field = 'name', $id = '' ) {
836 FrmDeprecated::edit_name( $field, $id );
837 }
838
839 /**
840 * @deprecated 3.0
841 * @codeCoverageIgnore
842 *
843 * @param int $field_id
844 * @param array $values
845 * @param int $form_id
846 *
847 * @return array
848 */
849 public static function include_single_field( $field_id, $values, $form_id = 0 ) {
850 return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
851 }
852
853 /**
854 * @deprecated 2.3
855 * @codeCoverageIgnore
856 */
857 public static function edit_option() {
858 FrmDeprecated::deprecated( __METHOD__, '2.3' );
859 }
860
861 /**
862 * @deprecated 2.3
863 * @codeCoverageIgnore
864 */
865 public static function delete_option() {
866 FrmDeprecated::deprecated( __METHOD__, '2.3' );
867 }
868 }
869