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

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