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

874 lines 24.0 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 /**
587 * @param array $field
588 * @return string
589 */
590 private static function prepare_placeholder( $field ) {
591 $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
592 $placeholder_is_blank = empty( $placeholder ) && '0' !== $placeholder;
593 $is_placeholder_field = FrmFieldsHelper::is_placeholder_field_type( $field['type'] );
594 $is_combo_field = in_array( $field['type'], array( 'address', 'credit_card' ), true );
595
596 if ( $placeholder_is_blank && $is_placeholder_field && ! $is_combo_field ) {
597 $placeholder = self::get_default_value_from_name( $field );
598 }
599
600 return $placeholder;
601 }
602
603 /**
604 * If the label position is "inside",
605 * get the label to use as the placeholder
606 *
607 * @since 2.05
608 *
609 * @param array $field
610 *
611 * @return string
612 */
613 public static function get_default_value_from_name( $field ) {
614 $position = FrmField::get_option( $field, 'label' );
615 if ( $position == 'inside' ) {
616 $default_value = $field['name'];
617 if ( FrmField::is_required( $field ) ) {
618 $default_value .= ' ' . $field['required_indicator'];
619 }
620 } else {
621 $default_value = '';
622 }
623
624 return $default_value;
625 }
626
627 /**
628 * Maybe add a blank placeholder option before any options
629 * in a dropdown.
630 *
631 * @since 4.04
632 * @return bool True if placeholder was added.
633 */
634 public static function add_placeholder_to_select( $field ) {
635 $placeholder = FrmField::get_option( $field, 'placeholder' );
636 if ( empty( $placeholder ) ) {
637 $placeholder = self::get_default_value_from_name( $field );
638 }
639
640 if ( $placeholder !== '' ) {
641 ?>
642 <option value="">
643 <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
644 </option>
645 <?php
646 return true;
647 }
648
649 return false;
650 }
651
652 /**
653 * Use HMTL5 placeholder with js fallback
654 *
655 * @param array $field
656 * @param array $add_html
657 */
658 private static function add_placeholder_to_input( $field, &$add_html ) {
659 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
660 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
661 }
662 }
663
664 private static function add_frmval_to_input( $field, &$add_html ) {
665 if ( $field['placeholder'] != '' ) {
666 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
667
668 if ( 'select' === $field['type'] ) {
669 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
670 }
671 }
672
673 if ( $field['default_value'] != '' ) {
674 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
675 }
676 }
677
678 private static function add_validation_messages( $field, array &$add_html ) {
679 if ( FrmField::is_required( $field ) ) {
680 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
681 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
682 self::maybe_add_html_required( $field, $add_html );
683 }
684
685 if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
686 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
687 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
688 }
689 }
690
691 /**
692 * If 'required' is added to a conditionall hidden field, the form won't
693 * submit in many browsers. Check to make sure the javascript to conditionally
694 * remove it is present if needed.
695 *
696 * @since 3.06.01
697 * @param array $field
698 * @param array $add_html
699 */
700 private static function maybe_add_html_required( $field, array &$add_html ) {
701 if ( in_array( $field['type'], array( 'radio', 'checkbox', 'file', 'data', 'lookup' ) ) ) {
702 return;
703 }
704
705 $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
706 if ( $include_html ) {
707 $add_html['aria-required'] = 'aria-required="true"';
708 }
709 }
710
711 private static function add_shortcodes_to_html( $field, array &$add_html ) {
712 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
713 return;
714 }
715
716 foreach ( $field['shortcodes'] as $k => $v ) {
717 if ( 'opt' === $k ) {
718 continue;
719 }
720
721 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
722 $add_html[] = $v;
723 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
724 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
725 } else {
726 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
727 }
728
729 unset( $k, $v );
730 }
731 }
732
733 /**
734 * Add pattern attribute
735 *
736 * @since 3.0
737 *
738 * @param array $field
739 * @param array $add_html
740 */
741 private static function add_pattern_attribute( $field, array &$add_html ) {
742 $has_format = FrmField::is_option_true_in_array( $field, 'format' );
743 $format_field = FrmField::is_field_type( $field, 'text' );
744
745 if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
746 $frm_settings = FrmAppHelper::get_settings();
747
748 if ( $frm_settings->use_html ) {
749 $format = FrmEntryValidate::phone_format( $field );
750 $format = substr( $format, 2, - 1 );
751
752 $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
753 }
754 }
755 }
756
757 public static function check_value( $opt, $opt_key, $field ) {
758 if ( is_array( $opt ) ) {
759 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
760 $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
761 } else {
762 $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
763 }
764 }
765
766 return $opt;
767 }
768
769 public static function check_label( $opt ) {
770 if ( is_array( $opt ) ) {
771 $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
772 }
773
774 return $opt;
775 }
776
777 /**
778 * @deprecated 4.0
779 */
780 public static function update_ajax_option() {
781 _deprecated_function( __METHOD__, '4.0' );
782 FrmAppHelper::permission_check( 'frm_edit_forms' );
783 check_ajax_referer( 'frm_ajax', 'nonce' );
784
785 $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
786 if ( ! $field_id ) {
787 wp_die();
788 }
789
790 $field = FrmField::getOne( $field_id );
791
792 if ( isset( $_POST['separate_value'] ) ) {
793 $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
794
795 $field->field_options['separate_value'] = $new_val;
796 unset( $new_val );
797 }
798
799 FrmField::update(
800 $field_id,
801 array(
802 'field_options' => $field->field_options,
803 'form_id' => $field->form_id,
804 )
805 );
806 wp_die();
807 }
808
809 /**
810 * @deprecated 4.0
811 */
812 public static function import_choices() {
813 _deprecated_function( __METHOD__, '4.0' );
814 wp_die();
815 }
816
817 /**
818 * Add Single Option or Other Option.
819 *
820 * @deprecated 4.0 Moved to Pro for Other option only.
821 */
822 public static function add_option() {
823 _deprecated_function( __METHOD__, '4.0', 'FrmProFormsController::add_other_option' );
824 if ( is_callable( 'FrmProFormsController::add_other_option' ) ) {
825 FrmProFormsController::add_other_option();
826 }
827 }
828
829 /**
830 * @deprecated 4.0
831 */
832 public static function update_order() {
833 FrmDeprecated::update_order();
834 }
835
836 /**
837 * @deprecated 3.0
838 * @codeCoverageIgnore
839 */
840 public static function edit_name( $field = 'name', $id = '' ) {
841 FrmDeprecated::edit_name( $field, $id );
842 }
843
844 /**
845 * @deprecated 3.0
846 * @codeCoverageIgnore
847 *
848 * @param int $field_id
849 * @param array $values
850 * @param int $form_id
851 *
852 * @return array
853 */
854 public static function include_single_field( $field_id, $values, $form_id = 0 ) {
855 return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
856 }
857
858 /**
859 * @deprecated 2.3
860 * @codeCoverageIgnore
861 */
862 public static function edit_option() {
863 FrmDeprecated::deprecated( __METHOD__, '2.3' );
864 }
865
866 /**
867 * @deprecated 2.3
868 * @codeCoverageIgnore
869 */
870 public static function delete_option() {
871 FrmDeprecated::deprecated( __METHOD__, '2.3' );
872 }
873 }
874