PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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
← All changes | classes/controllers/FrmFieldsController.php +222 -517 6.346.8 View file →
@@ -4,15 +4,8 @@
4 4 }
5 5
6 6 class FrmFieldsController {
7 7
8 - /**
9 - * This is stored statically so we can re-use this data for every field.
10 - *
11 - * @var FrmFieldSelectionData|null
12 - */
13 - private static $field_selection_data;
14 -
15 8 public static function load_field() {
16 9 FrmAppHelper::permission_check( 'frm_edit_forms' );
17 10 check_ajax_referer( 'frm_ajax', 'nonce' );
18 11
@@ -18,10 +11,9 @@
18 11
19 12 // Javascript may be included in some field settings.
20 13 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
21 14 $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array();
22 -
23 - if ( ! $fields ) {
15 + if ( empty( $fields ) ) {
24 16 wp_die();
25 17 }
26 18
27 19 $_GET['page'] = 'formidable';
@@ -34,11 +26,10 @@
34 26
35 27 foreach ( $fields as $field ) {
36 28 $field = htmlspecialchars_decode( nl2br( $field ) );
37 29 $field = json_decode( $field );
38 -
39 30 if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
40 - // This field may have already been loaded
31 + // this field may have already been loaded
41 32 continue;
42 33 }
43 34
44 35 if ( ! isset( $field->value ) ) {
@@ -49,10 +40,11 @@
49 40 $field->default_value = json_decode( json_encode( $field->default_value ), true );
50 41
51 42 ob_start();
52 43 self::load_single_field( $field, $values );
53 - $field_html[ absint( $field->id ) ] = ob_get_clean();
54 - }//end foreach
44 + $field_html[ absint( $field->id ) ] = ob_get_contents();
45 + ob_end_clean();
46 + }
55 47
56 48 echo json_encode( $field_html );
57 49
58 50 wp_die();
@@ -64,17 +56,16 @@
64 56 public static function create() {
65 57 FrmAppHelper::permission_check( 'frm_edit_forms' );
66 58 check_ajax_referer( 'frm_ajax', 'nonce' );
67 59
68 - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
69 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
70 - $field_options = FrmAppHelper::get_post_param( 'field_options', array(), 'wp_kses_post' );
60 + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
61 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
71 62
72 63 do_action( 'frm_before_create_field', $field_type, $form_id );
73 64
74 - $field = self::include_new_field( $field_type, $form_id, $field_options );
65 + $field = self::include_new_field( $field_type, $form_id );
75 66
76 - // This hook will allow for multiple fields to be added at once
67 + // this hook will allow for multiple fields to be added at once
77 68 do_action( 'frm_after_field_created', $field, $form_id );
78 69
79 70 wp_die();
80 71 }
@@ -81,21 +72,16 @@
81 72
82 73 /**
83 74 * Set up and create a new field
84 75 *
85 - * @param string $field_type
86 - * @param int $form_id
87 - * @param array $field_options
76 + * @param string $field_type
77 + * @param integer $form_id
88 78 *
89 - * @return array|false
79 + * @return array|bool
90 80 */
91 - public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
81 + public static function include_new_field( $field_type, $form_id ) {
92 82 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
93 83
94 - if ( $field_options ) {
95 - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
96 - }
97 -
98 84 // When a new field is added to the form, flag it as draft and hide it from the front-end.
99 85 $field_values['field_options']['draft'] = 1;
100 86
101 87 /**
@@ -107,15 +93,15 @@
107 93 if ( ! $field_id ) {
108 94 return false;
109 95 }
110 96
111 - $field = self::get_field_array_from_id( $field_id );
97 + $field = self::get_field_array_from_id( $field_id );
98 +
112 99 $values = array();
113 -
114 100 if ( FrmAppHelper::pro_is_installed() ) {
115 101 $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
116 - $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
117 102
103 + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
118 104 if ( $parent_form_id ) {
119 105 $field['parent_form_id'] = $parent_form_id;
120 106 }
121 107 }
@@ -128,14 +114,15 @@
128 114 public static function duplicate() {
129 115 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 116 check_ajax_referer( 'frm_ajax', 'nonce' );
131 117
132 - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
133 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
118 + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
119 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
120 +
134 121 $new_field = FrmField::duplicate_single_field( $field_id, $form_id );
135 122
136 123 if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) {
137 - self::load_single_field( $new_field['field_id'], $new_field['values'], $form_id );
124 + self::load_single_field( $new_field['field_id'], $new_field['values'] );
138 125 }
139 126
140 127 wp_die();
141 128 }
@@ -148,8 +135,9 @@
148 135 * @return array
149 136 */
150 137 public static function get_field_array_from_id( $field_id ) {
151 138 $field = FrmField::getOne( $field_id );
139 +
152 140 return FrmFieldsHelper::setup_edit_vars( $field );
153 141 }
154 142
155 143 /**
@@ -154,13 +142,11 @@
154 142
155 143 /**
156 144 * @since 3.0
157 145 *
158 - * @param array|int|object|string $field_object
159 - * @param array $values
160 - * @param int $form_id
161 - *
162 - * @return void
146 + * @param int|array|object $field_object
147 + * @param array $values
148 + * @param int $form_id
163 149 */
164 150 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
165 151 global $frm_vars;
166 152 $frm_vars['is_admin'] = true;
@@ -171,63 +157,38 @@
171 157 $field = $field_object;
172 158 $field_object = FrmField::getOne( $field['id'] );
173 159 }
174 160
175 - $field_obj = FrmFieldFactory::get_field_factory( $field_object );
176 - $display = self::display_field_options( array(), $field_obj );
177 - $ajax_loading = ! empty( $values['ajax_load'] );
178 - $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
161 + $field_obj = FrmFieldFactory::get_field_factory( $field_object );
162 + $display = self::display_field_options( array(), $field_obj );
179 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 +
180 167 if ( $ajax_loading && $ajax_this_field ) {
181 168 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
182 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php';
183 - return;
184 - }
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;
185 173
186 - if ( ! isset( $field ) && is_object( $field_object ) ) {
187 - // Prefer the explicit form id. $values['id'] is not always a form id (for example when
188 - // duplicating a field it is the copied field's id), so trusting it would set parent_form_id
189 - // to a field id and break settings that resolve fields against the parent form.
190 - $field_object->parent_form_id = $form_id ? $form_id : ( $values['id'] ?? $field_object->form_id );
191 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
192 - }
174 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
175 + }
193 176
194 - /**
195 - * Filter for adding extra attributes to the field container.
196 - *
197 - * @since 6.23
198 - *
199 - * @param array $extra_field_attributes
200 - * @param array $field
201 - * @param array $display
202 - */
203 - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display );
177 + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
178 + $li_classes .= ' ui-state-default widgets-holder-wrap';
204 179
205 - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
206 - $li_classes .= ' ui-state-default widgets-holder-wrap';
207 -
208 - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
180 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
181 + }
209 182 }
210 183
211 184 /**
212 185 * @since 3.0
213 - *
214 - * @param array $field
215 - * @param array $display
216 - * @param FrmFieldType $field_info
217 - *
218 - * @return string
219 186 */
220 187 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
221 188 $li_classes = $field_info->form_builder_classes( $display['type'] );
222 189 $li_classes .= ' frm_form_field frmstart ';
223 190
224 - $style_align_class = self::get_builder_field_style_align_class( $field, $field_info );
225 -
226 - if ( $style_align_class ) {
227 - $li_classes .= $style_align_class . ' ';
228 - }
229 -
230 191 if ( isset( $field['classes'] ) ) {
231 192 $li_classes .= trim( $field['classes'] ) . ' ';
232 193 }
233 194
@@ -233,45 +194,14 @@
233 194
234 195 $li_classes .= 'frmend';
235 196
236 197 if ( $field ) {
237 - return apply_filters( 'frm_build_field_class', $li_classes, $field );
198 + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
238 199 }
239 200
240 201 return $li_classes;
241 202 }
242 203
243 - /**
244 - * Apply the active style alignment to a radio or checkbox builder preview on load.
245 - *
246 - * The per-field alignment setting only exists in Pro, so on load the style setting is
247 - * used. When the field has an explicit alignment (Pro), the frm_build_field_class filter
248 - * applies it instead. When Pro is not installed, any saved alignment is treated as empty.
249 - *
250 - * @since 6.32
251 - *
252 - * @param array $field
253 - * @param FrmFieldType $field_info
254 - *
255 - * @return string
256 - */
257 - private static function get_builder_field_style_align_class( $field, $field_info ) {
258 - if ( ! $field || ! is_array( $field ) || ( ! FrmField::is_radio( $field ) && ! FrmField::is_checkbox( $field ) ) ) {
259 - return '';
260 - }
261 -
262 - $align = FrmAppHelper::pro_is_installed() ? FrmField::get_option( $field, 'align' ) : '';
263 -
264 - if ( $align ) {
265 - return '';
266 - }
267 -
268 - $align = FrmStylesHelper::get_align_from_active_style( $field );
269 - $field_info->prepare_align_class( $align );
270 -
271 - return $align;
272 - }
273 -
274 204 public static function destroy() {
275 205 FrmAppHelper::permission_check( 'frm_edit_forms' );
276 206 check_ajax_referer( 'frm_ajax', 'nonce' );
277 207
@@ -290,40 +220,27 @@
290 220 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
291 221 return;
292 222 }
293 223
294 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
295 - $field = FrmField::getOne( $field_id );
296 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
224 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
225 + $field = FrmField::getOne( $field_id );
297 226
298 - /**
299 - * Filter to add new fields that will support import_options/Bulk Edit Options.
300 - *
301 - * @since 6.8.4
302 - *
303 - * @param array $bulk_edit_types
304 - *
305 - * @return array
306 - */
307 - $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
308 -
309 - if ( ! in_array( $field->type, $bulk_edit_types, true ) ) {
227 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
310 228 return;
311 229 }
312 230
313 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 );
314 235
315 - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
316 - $opts = explode( "\n", rtrim( $opts, "\n" ) );
317 - $opts = array_map( 'trim', $opts );
236 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
237 + $field['separate_value'] = ( $separate === 'true' );
318 238
319 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
320 - $field['separate_value'] = $separate === 'true';
321 -
322 239 if ( $field['separate_value'] ) {
323 240 foreach ( $opts as $opt_key => $opt ) {
324 - if ( str_contains( $opt, '|' ) ) {
325 - $vals = explode( '|', $opt );
241 + if ( strpos( $opt, '|' ) !== false ) {
242 + $vals = explode( '|', $opt );
326 243 $opts[ $opt_key ] = array(
327 244 'label' => trim( $vals[0] ),
328 245 'value' => trim( $vals[1] ),
329 246 );
@@ -333,11 +250,10 @@
333 250 }
334 251 }
335 252
336 253 // Keep other options after bulk update.
337 - if ( ! empty( $field['field_options']['other'] ) ) {
254 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
338 255 $other_array = array();
339 -
340 256 foreach ( $field['options'] as $opt_key => $opt ) {
341 257 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
342 258 $other_array[ $opt_key ] = $opt;
343 259 }
@@ -342,10 +258,9 @@
342 258 $other_array[ $opt_key ] = $opt;
343 259 }
344 260 unset( $opt_key, $opt );
345 261 }
346 -
347 - if ( $other_array ) {
262 + if ( ! empty( $other_array ) ) {
348 263 $opts = array_merge( $opts, $other_array );
349 264 }
350 265 }
351 266
@@ -359,10 +274,8 @@
359 274 /**
360 275 * @since 4.0
361 276 *
362 277 * @param array $atts - Includes field array, field_obj, display array, values array.
363 - *
364 - * @return void
365 278 */
366 279 public static function load_single_field_settings( $atts ) {
367 280 $field = $atts['field'];
368 281 $field_obj = $atts['field_obj'];
@@ -377,19 +290,19 @@
377 290 if ( ! isset( $field['read_only'] ) ) {
378 291 $field['read_only'] = false;
379 292 }
380 293
381 - $field_selection_data = self::maybe_define_field_selection_data();
382 - $all_field_types = $field_selection_data->all_field_types;
383 - $disabled_fields = $field_selection_data->disabled_fields;
384 - $frm_settings = FrmAppHelper::get_settings();
385 - $field_types = FrmFieldTypeOptionData::get_field_types( $field['type'] );
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();
386 299
387 300 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
388 301 // Add fallback for an add-on field type that has been deactivated.
389 302 $all_field_types[ $field['type'] ] = array(
390 303 'name' => ucfirst( $field['type'] ),
391 - 'icon' => 'frmfont frm_pencil_icon',
304 + 'icon' => 'frm_icon_font frm_pencil_icon',
392 305 );
393 306 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
394 307 // Fallback for fields added in a more basic way.
395 308 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -395,9 +308,8 @@
395 308 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
396 309 }
397 310
398 311 $type_name = $all_field_types[ $field['type'] ]['name'];
399 -
400 312 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
401 313 $type_name = $all_field_types['divider|repeat']['name'];
402 314 }
403 315
@@ -408,147 +320,61 @@
408 320 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
409 321 $field['placeholder'] = implode( ', ', $field['placeholder'] );
410 322 }
411 323
412 - $pro_is_installed = FrmAppHelper::pro_is_installed();
413 -
414 - $unique_values_label_atts = array(
415 - 'for' => 'frm_uniq_field_' . $field['id'],
416 - 'class' => 'frm_help frm-mb-0',
417 - 'title' => __(
418 - 'Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\', then no one else will be allowed to enter the same name.',
419 - 'formidable'
420 - ),
421 - 'data-trigger' => 'hover',
422 - );
423 -
424 - $read_only_label_atts = array(
425 - 'for' => 'frm_read_only_field_' . $field['id'],
426 - 'class' => 'frm_help frm-mb-0',
427 - 'title' => __( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ),
428 - 'data-trigger' => 'hover',
429 - );
430 -
431 - if ( ! $pro_is_installed ) {
432 - $visibility_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
433 - array(
434 - 'id' => 'field_options_admin_only_' . $field['id'],
435 - 'readonly' => '1',
436 - ),
437 - 'field_visibility',
438 - __( 'Visibility options', 'formidable' ),
439 - '/field-options/#kb-visibility'
440 - );
441 -
442 - $autocomplete_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
443 - array( 'id' => 'field_options_autocomplete_' . $field['id'] ),
444 - 'autocomplete',
445 - __( 'Autocomplete options', 'formidable' ),
446 - '/email-address/#kb-autocomplete-attribute'
447 - );
448 -
449 - $before_after_content_upsell_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
450 - array(
451 - 'type' => 'text',
452 - 'readonly' => '1',
453 - ),
454 - 'before_after_contents',
455 - __( 'Before and after field contents', 'formidable' ),
456 - '/field-options/#kb-before-after-input'
457 - );
458 -
459 - $show_upsell_for_unique_value = in_array(
460 - $field['type'],
461 - array( 'checkbox', 'email', 'name', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ),
462 - true
463 - );
464 - $show_upsell_for_read_only = in_array( $field['type'], array( 'address', 'email', 'hidden', 'number', 'phone', 'radio', 'text', 'textarea', 'url' ), true );
465 - $show_upsell_for_before_after_contents = in_array( $field['type'], array( 'email', 'number', 'phone', 'quantity', 'select', 'tag', 'text', 'total', 'url' ), true );
466 - $show_upsell_for_autocomplete = in_array( $field['type'], array( 'text', 'email', 'number' ), true );
467 - $show_upsell_for_visibility = $field['type'] !== 'hidden';
468 -
469 - $unique_values_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
470 - $unique_values_label_atts,
471 - 'unique_values',
472 - __( 'Unique Values', 'formidable' ),
473 - '/field-options/#kb-unique'
474 - );
475 - $read_only_label_atts = FrmSettingsUpsellHelper::add_upgrade_modal_atts(
476 - $read_only_label_atts,
477 - 'read_only',
478 - __( 'Read Only Values', 'formidable' ),
479 - '/field-options/#kb-read-only'
480 - );
481 - }//end if
482 -
483 324 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
484 325 }
485 326
486 327 /**
487 - * @since 6.9.1
488 - *
489 - * @return FrmFieldSelectionData
490 - */
491 - private static function maybe_define_field_selection_data() {
492 - if ( ! isset( self::$field_selection_data ) ) {
493 - self::$field_selection_data = new FrmFieldSelectionData();
494 - }
495 - return self::$field_selection_data;
496 - }
497 -
498 - /**
499 328 * Get the list of default value types that can be toggled in the builder.
500 329 *
501 330 * @since 4.0
502 - *
503 - * @param array $field
504 - * @param array $atts
505 - *
506 331 * @return array
507 332 */
508 333 private static function default_value_types( $field, $atts ) {
509 334 $types = array(
510 - 'default_value' => array(
335 + 'default_value' => array(
511 336 'class' => '',
512 - 'icon' => 'frmfont frm_text2_icon',
513 - 'title' => __( 'Default Value', 'formidable' ),
337 + 'icon' => 'frm_icon_font frm_text2_icon',
338 + 'title' => __( 'Default Value (Text)', 'formidable' ),
514 339 'data' => array(
515 340 'frmshow' => '#default-value-for-',
516 341 ),
517 342 ),
518 - 'calc' => array(
519 - 'class' => 'frm_show_upgrade frm_noallow',
520 - 'title' => __( 'Calculate Value', 'formidable' ),
521 - 'icon' => 'frmfont frm_calculator_icon',
522 - 'data' => array(
343 + 'calc' => array(
344 + 'class' => 'frm_show_upgrade frm_noallow',
345 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
346 + 'icon' => 'frm_icon_font frm_calculator_icon',
347 + 'data' => array(
523 348 'medium' => 'calculations',
524 349 'upgrade' => __( 'Calculator forms', 'formidable' ),
525 350 ),
526 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
527 351 ),
528 352 'get_values_field' => array(
529 - 'class' => 'frm_show_upgrade frm_noallow',
530 - 'title' => __( 'Lookup', 'formidable' ),
531 - 'icon' => 'frmfont frm_search_icon',
532 - 'data' => array(
353 + 'class' => 'frm_show_upgrade frm_noallow',
354 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
355 + 'icon' => 'frm_icon_font frm_search_icon',
356 + 'data' => array(
533 357 'medium' => 'lookup',
534 358 'upgrade' => __( 'Lookup fields', 'formidable' ),
535 359 ),
536 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
537 360 ),
538 361 );
539 362
540 363 $types = apply_filters( 'frm_default_value_types', $types, $atts );
541 364
365 + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
366 + // Prevent settings from showing in 2 spots.
367 + unset( $types['calc'], $types['get_values_field'] );
368 + }
369 +
542 370 // Set active class.
543 371 $settings = array_keys( $types );
544 372 $active = 'default_value';
545 373
546 - if ( FrmAppHelper::pro_is_connected() ) {
547 - foreach ( $settings as $type ) {
548 - if ( ! empty( $field[ $type ] ) ) {
549 - $active = $type;
550 - }
374 + foreach ( $settings as $type ) {
375 + if ( ! empty( $field[ $type ] ) ) {
376 + $active = $type;
551 377 }
552 378 }
553 379
554 380 $types[ $active ]['class'] .= ' current';
@@ -556,13 +382,8 @@
556 382
557 383 return $types;
558 384 }
559 385
560 - /**
561 - * @param string $type
562 - *
563 - * @return string
564 - */
565 386 public static function change_type( $type ) {
566 387 $type_switch = array(
567 388 'scale' => 'radio',
568 389 'star' => 'radio',
@@ -570,9 +391,8 @@
570 391 'rte' => 'textarea',
571 392 'website' => 'url',
572 393 'image' => 'url',
573 394 );
574 -
575 395 if ( isset( $type_switch[ $type ] ) ) {
576 396 $type = $type_switch[ $type ];
577 397 }
578 398
@@ -578,24 +398,26 @@
578 398
579 399 $pro_fields = FrmField::pro_field_selection();
580 400 // We want to keep credit_card types as credit card types for Stripe Lite.
581 401 // The credit_card key is set for backward compatibility.
582 - FrmField::remove_moved_field_types_from_pro( $pro_fields );
402 + unset( $pro_fields['credit_card'] );
583 403
584 - return array_key_exists( $type, $pro_fields ) ? 'text' : $type;
404 + if ( array_key_exists( $type, $pro_fields ) ) {
405 + $type = 'text';
406 + }
407 +
408 + return $type;
585 409 }
586 410
587 411 /**
588 - * @param array $settings
589 - * @param FrmFieldType|null $field_info
412 + * @param array $settings
413 + * @param object $field_info
590 414 *
591 415 * @return array
592 416 */
593 417 public static function display_field_options( $settings, $field_info = null ) {
594 418 if ( $field_info ) {
595 - $settings = $field_info->display_field_settings();
596 -
597 - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
419 + $settings = $field_info->display_field_settings();
598 420 $settings['field_data'] = $field_info->field;
599 421 }
600 422
601 423 return apply_filters( 'frm_display_field_options', $settings );
@@ -605,32 +427,14 @@
605 427 * Display the format option
606 428 *
607 429 * @since 3.0
608 430 *
609 - * @param array $field Field data.
610 - * @param bool $is_hidden Whether the format option should be hidden.
611 - *
612 - * @return void
431 + * @param array $field
613 432 */
614 - public static function show_format_option( $field, $is_hidden = false ) {
615 - $attributes = array(
616 - 'class' => 'frm-has-modal',
617 - 'id' => 'frm-field-format-custom-' . $field['id'],
618 - );
619 -
620 - if ( $is_hidden ) {
621 - $attributes['class'] .= ' frm_hidden';
622 - }
623 -
624 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
433 + public static function show_format_option( $field ) {
434 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
625 435 }
626 436
627 - /**
628 - * @param array $field
629 - * @param bool $echo
630 - *
631 - * @return string
632 - */
633 437 public static function input_html( $field, $echo = true ) {
634 438 $class = array();
635 439 self::add_input_classes( $field, $class );
636 440
@@ -645,9 +449,8 @@
645 449 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
646 450
647 451 self::add_shortcodes_to_html( $field, $add_html );
648 452 self::add_pattern_attribute( $field, $add_html );
649 - self::add_currency_field_attributes( $field, $add_html );
650 453
651 454 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
652 455 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
653 456
@@ -657,20 +460,14 @@
657 460
658 461 return $add_html;
659 462 }
660 463
661 - /**
662 - * @param array $field
663 - * @param array $class
664 - *
665 - * @return void
666 - */
667 464 private static function add_input_classes( $field, array &$class ) {
668 - if ( ! empty( $field['input_class'] ) ) {
465 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
669 466 $class[] = $field['input_class'];
670 467 }
671 468
672 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
469 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
673 470 return;
674 471 }
675 472
676 473 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -677,14 +474,8 @@
677 474 $class[] = 'auto_width';
678 475 }
679 476 }
680 477
681 - /**
682 - * @param array $field
683 - * @param array $add_html
684 - *
685 - * @return void
686 - */
687 478 private static function add_html_size( $field, array &$add_html ) {
688 479 $size_fields = array(
689 480 'select',
690 481 'data',
@@ -693,9 +484,9 @@
693 484 'file',
694 485 'lookup',
695 486 );
696 487
697 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
488 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
698 489 return;
699 490 }
700 491
701 492 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -712,14 +503,8 @@
712 503
713 504 self::add_html_cols( $field, $add_html );
714 505 }
715 506
716 - /**
717 - * @param array $field
718 - * @param array $add_html
719 - *
720 - * @return void
721 - */
722 507 private static function add_html_cols( $field, array &$add_html ) {
723 508 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
724 509 return;
725 510 }
@@ -731,9 +516,9 @@
731 516 'rem' => 0.444,
732 517 'em' => 0.544,
733 518 );
734 519
735 - // Include "col" for valid html
520 + // include "col" for valid html
736 521 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
737 522
738 523 if ( ! isset( $calc[ $unit ] ) ) {
739 524 return;
@@ -738,18 +523,13 @@
738 523 if ( ! isset( $calc[ $unit ] ) ) {
739 524 return;
740 525 }
741 526
742 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
527 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
528 +
743 529 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
744 530 }
745 531
746 - /**
747 - * @param array $field
748 - * @param array $add_html
749 - *
750 - * @return void
751 - */
752 532 private static function add_html_length( $field, array &$add_html ) {
753 533 // Check for max setting and if this field accepts maxlength.
754 534 $fields = array(
755 535 'textarea',
@@ -757,9 +537,9 @@
757 537 'hidden',
758 538 'file',
759 539 );
760 540
761 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
541 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
762 542 return;
763 543 }
764 544
765 545 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -769,17 +549,9 @@
769 549
770 550 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
771 551 }
772 552
773 - /**
774 - * @param array $field
775 - * @param array $add_html
776 - * @param array $class
777 - *
778 - * @return void
779 - */
780 553 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
781 - // phpcs:ignore Universal.Operators.StrictComparisons
782 554 if ( $field['default_value'] != '' ) {
783 555 if ( is_array( $field['default_value'] ) ) {
784 556 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
785 557 } else {
@@ -787,16 +559,26 @@
787 559 }
788 560 }
789 561
790 562 $field['placeholder'] = self::prepare_placeholder( $field );
791 -
792 - // phpcs:ignore Universal.Operators.StrictComparisons
793 563 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
794 - // Don't include a json placeholder
564 + // don't include a json placeholder
795 565 return;
796 566 }
797 567
798 - self::add_placeholder_to_input( $field, $add_html );
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 + }
799 581 }
800 582
801 583 /**
802 584 * Prepares field placeholder.
@@ -803,13 +585,14 @@
803 585 *
804 586 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
805 587 *
806 588 * @param array $field Field array.
807 - *
808 589 * @return string
809 590 */
810 591 private static function prepare_placeholder( $field ) {
811 - return $field['placeholder'] ?? '';
592 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
593 +
594 + return $placeholder;
812 595 }
813 596
814 597 /**
815 598 * If the label position is "inside",
@@ -830,17 +613,13 @@
830 613 * Maybe add a blank placeholder option before any options
831 614 * in a dropdown.
832 615 *
833 616 * @since 4.04
834 - *
835 - * @param array|object $field
836 - *
837 617 * @return bool True if placeholder was added.
838 618 */
839 619 public static function add_placeholder_to_select( $field ) {
840 620 $placeholder = FrmField::get_option( $field, 'placeholder' );
841 -
842 - if ( ! $placeholder ) {
621 + if ( empty( $placeholder ) ) {
843 622 $placeholder = self::get_default_value_from_name( $field );
844 623 }
845 624
846 625 $use_placeholder = $placeholder;
@@ -847,9 +626,8 @@
847 626 $autocomplete = FrmField::get_option( $field, 'autocom' );
848 627
849 628 if ( $autocomplete ) {
850 629 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
851 -
852 630 if ( $use_chosen ) {
853 631 $use_placeholder = '';
854 632 }
855 633 }
@@ -860,8 +638,13 @@
860 638 'value' => '',
861 639 'data-placeholder' => 'true',
862 640 );
863 641
642 + if ( $autocomplete && empty( $use_chosen ) ) {
643 + // This is required for Slim Select.
644 + $placeholder_attributes['data-placeholder'] = 'true';
645 + }
646 +
864 647 FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
865 648 return true;
866 649 }
867 650
@@ -868,14 +651,12 @@
868 651 return false;
869 652 }
870 653
871 654 /**
872 - * Use HTML5 placeholder with js fallback.
655 + * Use HMTL5 placeholder with js fallback
873 656 *
874 657 * @param array $field
875 658 * @param array $add_html
876 - *
877 - * @return void
878 659 */
879 660 private static function add_placeholder_to_input( $field, &$add_html ) {
880 661 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
881 662 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -881,16 +662,9 @@
881 662 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
882 663 }
883 664 }
884 665
885 - /**
886 - * @param array $field
887 - * @param array $add_html
888 - *
889 - * @return void
890 - */
891 666 private static function add_frmval_to_input( $field, &$add_html ) {
892 - // phpcs:ignore Universal.Operators.StrictComparisons
893 667 if ( $field['placeholder'] != '' ) {
894 668 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
895 669
896 670 if ( 'select' === $field['type'] ) {
@@ -897,30 +671,21 @@
897 671 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
898 672 }
899 673 }
900 674
901 - // phpcs:ignore Universal.Operators.StrictComparisons
902 675 if ( $field['default_value'] != '' ) {
903 676 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
904 677 }
905 678 }
906 679
907 - /**
908 - * @param array $field
909 - * @param array $add_html
910 - *
911 - * @return void
912 - */
913 680 private static function add_validation_messages( $field, array &$add_html ) {
914 - $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
915 -
916 - if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
681 + if ( FrmField::is_required( $field ) ) {
917 682 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
918 683 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
919 684 self::maybe_add_html_required( $field, $add_html );
920 685 }
921 686
922 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
687 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
923 688 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
924 689 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
925 690 }
926 691
@@ -929,63 +694,24 @@
929 694 }
930 695 }
931 696
932 697 /**
933 - * Returns an array that contains field validation messages status.
934 - *
935 - * @since 6.9
936 - *
937 - * @param array|object $field
938 - *
939 - * @return array
940 - */
941 - private static function get_validation_data_attribute_visibility_info( $field ) {
942 - if ( FrmField::get_field_type( $field ) === 'hidden' ) {
943 - $field_validation_data_attributes = array(
944 - 'data-invmsg' => false,
945 - 'data-reqmsg' => false,
946 - );
947 - } else {
948 - $field_validation_data_attributes = array(
949 - 'data-invmsg' => true,
950 - 'data-reqmsg' => true,
951 - );
952 - }
953 -
954 - /**
955 - * Allows controlling which field validation messages would be included in the field html.
956 - *
957 - * @since 6.9
958 - *
959 - * @param array $field_validation_messages_status
960 - * @param array|object $field
961 - */
962 - return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
963 - }
964 -
965 - /**
966 698 * @since 5.0.03
967 699 *
968 700 * @param array $field
969 701 * @param array $add_html
970 - *
971 - * @return void
972 702 */
973 703 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
974 704 $form = self::get_form_for_js_validation( $field );
975 -
976 705 if ( false === $form ) {
977 706 return;
978 707 }
979 708
980 709 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
981 -
982 - if ( false === $error_body ) {
983 - return;
710 + if ( false !== $error_body ) {
711 + $error_body = urlencode( $error_body );
712 + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
984 713 }
985 -
986 - $error_body = urlencode( $error_body );
987 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
988 714 }
989 715
990 716 /**
991 717 * @since 5.0.03
@@ -990,24 +716,20 @@
990 716 /**
991 717 * @since 5.0.03
992 718 *
993 719 * @param array $field
994 - *
995 - * @return false|stdClass false if there is no form object found with JS validation active.
720 + * @return stdClass|false false if there is no form object found with JS validation active.
996 721 */
997 722 private static function get_form_for_js_validation( $field ) {
998 723 global $frm_vars;
999 -
1000 724 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
1001 725 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
1002 726 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
1003 727 }
1004 -
1005 728 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
1006 729 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
1007 730 }
1008 731 }
1009 -
1010 732 return false;
1011 733 }
1012 734
1013 735 /**
@@ -1013,10 +735,9 @@
1013 735 /**
1014 736 * @param stdClass $form
1015 737 * @param array $field
1016 738 * @param array $errors
1017 - *
1018 - * @return false|string
739 + * @return string|false
1019 740 */
1020 741 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
1021 742 if ( empty( $field['custom_html'] ) ) {
1022 743 return false;
@@ -1023,16 +744,15 @@
1023 744 }
1024 745
1025 746 $custom_html = $field['custom_html'];
1026 747 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
1027 - $start = strpos( $custom_html, '[if error]' );
1028 748
749 + $start = strpos( $custom_html, '[if error]' );
1029 750 if ( false === $start ) {
1030 751 return false;
1031 752 }
1032 753
1033 754 $end = strpos( $custom_html, '[/if error]' );
1034 -
1035 755 if ( false === $end || $end < $start ) {
1036 756 return false;
1037 757 }
1038 758
@@ -1043,9 +763,13 @@
1043 763 '<div class="frm_error">[error]</div>',
1044 764 '<div class="frm_error" role="alert">[error]</div>',
1045 765 );
1046 766
1047 - return in_array( $error_body, $default_html, true ) ? false : $error_body;
767 + if ( in_array( $error_body, $default_html, true ) ) {
768 + return false;
769 + }
770 +
771 + return $error_body;
1048 772 }
1049 773
1050 774 /**
1051 775 * If 'required' is added to a conditionally hidden field, the form won't
@@ -1052,16 +776,12 @@
1052 776 * submit in many browsers. Check to make sure the javascript to conditionally
1053 777 * remove it is present if needed.
1054 778 *
1055 779 * @since 3.06.01
1056 - *
1057 780 * @param array $field
1058 781 * @param array $add_html
1059 - *
1060 - * @return void
1061 782 */
1062 783 private static function maybe_add_html_required( $field, array &$add_html ) {
1063 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1064 784 $excluded_field_types =
1065 785 FrmField::is_radio( $field ) ||
1066 786 FrmField::is_checkbox( $field ) ||
1067 787 FrmField::is_field_type( $field, 'file' ) ||
@@ -1066,23 +786,19 @@
1066 786 FrmField::is_checkbox( $field ) ||
1067 787 FrmField::is_field_type( $field, 'file' ) ||
1068 788 FrmField::is_field_type( $field, 'nps' ) ||
1069 789 FrmField::is_field_type( $field, 'scale' );
1070 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1071 790
1072 791 if ( $excluded_field_types ) {
1073 792 return;
1074 793 }
1075 794
1076 - $add_html['aria-required'] = 'aria-required="true"';
795 + $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
796 + if ( $include_html ) {
797 + $add_html['aria-required'] = 'aria-required="true"';
798 + }
1077 799 }
1078 800
1079 - /**
1080 - * @param array $field
1081 - * @param array $add_html
1082 - *
1083 - * @return void
1084 - */
1085 801 private static function add_shortcodes_to_html( $field, array &$add_html ) {
1086 802 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
1087 803 return;
1088 804 }
@@ -1091,25 +807,13 @@
1091 807 unset( $field['shortcodes']['autocomplete'] );
1092 808 }
1093 809
1094 810 foreach ( $field['shortcodes'] as $k => $v ) {
1095 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
1096 - $subfield_name = $field['subfield_name'];
1097 -
1098 - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
1099 - continue;
1100 - }
1101 - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
1102 - $k = 'aria-invalid';
1103 - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
1104 - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
1105 - }
1106 -
1107 - if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
811 + if ( 'opt' === $k ) {
1108 812 continue;
1109 813 }
1110 814
1111 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
815 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1112 816 $add_html[] = $v;
1113 817 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1114 818 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1115 819 } else {
@@ -1116,128 +820,129 @@
1116 820 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1117 821 }
1118 822
1119 823 unset( $k, $v );
1120 - }//end foreach
1121 - }
1122 -
1123 - /**
1124 - * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
1125 - *
1126 - * @since 6.11.2
1127 - *
1128 - * @param string $key The option key.
1129 - *
1130 - * @return bool
1131 - */
1132 - private static function should_allow_input_attribute( $key ) {
1133 - if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
1134 - return true;
1135 824 }
1136 - return FrmAppHelper::input_key_is_safe( $key );
1137 825 }
1138 826
1139 827 /**
1140 - * Add pattern attribute.
828 + * Add pattern attribute
1141 829 *
1142 830 * @since 3.0
1143 831 *
1144 832 * @param array $field
1145 833 * @param array $add_html
1146 - *
1147 - * @return void
1148 834 */
1149 835 private static function add_pattern_attribute( $field, array &$add_html ) {
1150 - $format_value = FrmField::get_option( $field, 'format' );
1151 - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
836 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1152 837 $format_field = FrmField::is_field_type( $field, 'text' );
1153 838
1154 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1155 - return;
1156 - }
839 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
840 + $frm_settings = FrmAppHelper::get_settings();
1157 841
1158 - $format = FrmEntryValidate::phone_format( $field );
1159 - $format = substr( $format, 2, - 1 );
842 + if ( $frm_settings->use_html ) {
843 + $format = FrmEntryValidate::phone_format( $field );
844 + $format = substr( $format, 2, - 1 );
1160 845
1161 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
846 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
847 + }
848 + }
1162 849 }
1163 850
1164 - /**
1165 - * Add product attributes to fields in multi-paged forms.
1166 - *
1167 - * @param array $field
1168 - * @param array $add_html
1169 - *
1170 - * @return void
1171 - */
1172 - private static function add_currency_field_attributes( $field, &$add_html ) {
1173 - $type = $field['original_type'] ?? $field['type'];
1174 - $is_product_field = in_array( $type, array( 'total', 'quantity', 'product' ), true );
1175 -
1176 - if ( ! $is_product_field ) {
1177 - return;
851 + public static function check_value( $opt, $opt_key, $field ) {
852 + if ( is_array( $opt ) ) {
853 + if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
854 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
855 + } else {
856 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
857 + }
1178 858 }
1179 859
1180 - if ( $type === 'total' ) {
1181 - $add_html['data-frmtotal'] = 'data-frmtotal';
1182 - } elseif ( $type === 'quantity' ) {
1183 - $product_field = FrmField::get_option( $field, 'product_field' );
1184 - $add_html['data-frmproduct'] = 'data-frmproduct="' . esc_attr( json_encode( $product_field ) ) . '"';
1185 - } elseif ( $type === 'product' && 'hidden' === $field['type'] ) {
1186 - // We want to do this only for fields that are hidden because it's
1187 - // not their page, hence the check : 'hidden' === $field['type'].
1188 - $price = empty( $field['value'] ) ? 0 : self::get_product_price( $field );
860 + return $opt;
861 + }
1189 862
1190 - $add_html['data-frmprice'] = 'data-frmprice="' . esc_attr( $price ) . '"';
863 + public static function check_label( $opt ) {
864 + if ( is_array( $opt ) ) {
865 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1191 866 }
867 +
868 + return $opt;
1192 869 }
1193 870
1194 871 /**
1195 - * @param array $field
872 + * @deprecated 4.0
1196 873 */
1197 - private static function get_product_price( $field ) {
1198 - if ( is_array( $field['value'] ) ) {
1199 - // '' is unlikely though, let's just do it to prevent warnings
1200 - $value = isset( $field['opt_key'] ) && isset( $field['value'][ $field['opt_key'] ] )
1201 - ? $field['value'][ $field['opt_key'] ]
1202 - : '';
1203 - } else {
1204 - $value = $field['value'];
874 + public static function update_ajax_option() {
875 + _deprecated_function( __METHOD__, '4.0' );
876 + FrmAppHelper::permission_check( 'frm_edit_forms' );
877 + check_ajax_referer( 'frm_ajax', 'nonce' );
878 +
879 + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
880 + if ( ! $field_id ) {
881 + wp_die();
1205 882 }
1206 883
1207 - $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
884 + $field = FrmField::getOne( $field_id );
1208 885
1209 - if ( method_exists( $field_obj, 'get_posted_price' ) ) {
1210 - return $field_obj->get_posted_price( $value );
886 + if ( isset( $_POST['separate_value'] ) ) {
887 + $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
888 +
889 + $field->field_options['separate_value'] = $new_val;
890 + unset( $new_val );
1211 891 }
1212 892
1213 - return $value;
893 + FrmField::update(
894 + $field_id,
895 + array(
896 + 'field_options' => $field->field_options,
897 + 'form_id' => $field->form_id,
898 + )
899 + );
900 + wp_die();
1214 901 }
1215 902
1216 903 /**
1217 - * @param mixed $opt
1218 - * @param mixed $opt_key
1219 - * @param array|object $field
904 + * @deprecated 4.0
905 + */
906 + public static function import_choices() {
907 + _deprecated_function( __METHOD__, '4.0' );
908 + wp_die();
909 + }
910 +
911 + /**
912 + * Add Single Option or Other Option.
1220 913 *
1221 - * @return mixed
914 + * @deprecated 4.0 Moved to Pro for Other option only.
1222 915 */
1223 - public static function check_value( $opt, $opt_key, $field ) {
1224 - if ( is_array( $opt ) ) {
1225 - if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1226 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
1227 - } else {
1228 - $opt = $opt['label'] ?? reset( $opt );
1229 - }
1230 - }
916 + public static function add_option() {
917 + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
918 + }
1231 919
1232 - return $opt;
920 + /**
921 + * @deprecated 4.0
922 + */
923 + public static function update_order() {
924 + FrmDeprecated::update_order();
1233 925 }
1234 926
1235 927 /**
1236 - * @param mixed $opt
928 + * @deprecated 3.0
929 + * @codeCoverageIgnore
930 + */
931 + public static function edit_name( $field = 'name', $id = '' ) {
932 + FrmDeprecated::edit_name( $field, $id );
933 + }
934 +
935 + /**
936 + * @deprecated 3.0
937 + * @codeCoverageIgnore
1237 938 *
1238 - * @return mixed
939 + * @param int $field_id
940 + * @param array $values
941 + * @param int $form_id
942 + *
943 + * @return array
1239 944 */
1240 - public static function check_label( $opt ) {
1241 - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt;
945 + public static function include_single_field( $field_id, $values, $form_id = 0 ) {
946 + return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
1242 947 }
1243 948 }