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