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

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