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 +222 -537 6.346.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,14 +111,15 @@
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 - self::load_single_field( $new_field['field_id'], $new_field['values'], $form_id );
121 + self::load_single_field( $new_field['field_id'], $new_field['values'] );
138 122 }
139 123
140 124 wp_die();
141 125 }
@@ -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,63 +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 - // 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 - }
171 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
172 + }
193 173
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 );
174 + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
175 + $li_classes .= ' ui-state-default widgets-holder-wrap';
204 176
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';
177 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
178 + }
209 179 }
210 180
211 181 /**
212 182 * @since 3.0
213 - *
214 - * @param array $field
215 - * @param array $display
216 - * @param FrmFieldType $field_info
217 - *
218 - * @return string
219 183 */
220 184 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
221 185 $li_classes = $field_info->form_builder_classes( $display['type'] );
222 186 $li_classes .= ' frm_form_field frmstart ';
223 187
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 188 if ( isset( $field['classes'] ) ) {
231 189 $li_classes .= trim( $field['classes'] ) . ' ';
232 190 }
233 191
@@ -233,45 +191,14 @@
233 191
234 192 $li_classes .= 'frmend';
235 193
236 194 if ( $field ) {
237 - return apply_filters( 'frm_build_field_class', $li_classes, $field );
195 + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
238 196 }
239 197
240 198 return $li_classes;
241 199 }
242 200
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 201 public static function destroy() {
275 202 FrmAppHelper::permission_check( 'frm_edit_forms' );
276 203 check_ajax_referer( 'frm_ajax', 'nonce' );
277 204
@@ -290,40 +217,27 @@
290 217 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
291 218 return;
292 219 }
293 220
294 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
295 - $field = FrmField::getOne( $field_id );
296 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
221 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
222 + $field = FrmField::getOne( $field_id );
297 223
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 ) ) {
224 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
310 225 return;
311 226 }
312 227
313 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 );
314 232
315 - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
316 - $opts = explode( "\n", rtrim( $opts, "\n" ) );
317 - $opts = array_map( 'trim', $opts );
233 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
234 + $field['separate_value'] = ( $separate === 'true' );
318 235
319 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
320 - $field['separate_value'] = $separate === 'true';
321 -
322 236 if ( $field['separate_value'] ) {
323 237 foreach ( $opts as $opt_key => $opt ) {
324 - if ( str_contains( $opt, '|' ) ) {
325 - $vals = explode( '|', $opt );
238 + if ( strpos( $opt, '|' ) !== false ) {
239 + $vals = explode( '|', $opt );
326 240 $opts[ $opt_key ] = array(
327 241 'label' => trim( $vals[0] ),
328 242 'value' => trim( $vals[1] ),
329 243 );
@@ -333,11 +247,10 @@
333 247 }
334 248 }
335 249
336 250 // Keep other options after bulk update.
337 - if ( ! empty( $field['field_options']['other'] ) ) {
251 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
338 252 $other_array = array();
339 -
340 253 foreach ( $field['options'] as $opt_key => $opt ) {
341 254 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
342 255 $other_array[ $opt_key ] = $opt;
343 256 }
@@ -342,10 +255,9 @@
342 255 $other_array[ $opt_key ] = $opt;
343 256 }
344 257 unset( $opt_key, $opt );
345 258 }
346 -
347 - if ( $other_array ) {
259 + if ( ! empty( $other_array ) ) {
348 260 $opts = array_merge( $opts, $other_array );
349 261 }
350 262 }
351 263
@@ -359,10 +271,8 @@
359 271 /**
360 272 * @since 4.0
361 273 *
362 274 * @param array $atts - Includes field array, field_obj, display array, values array.
363 - *
364 - * @return void
365 275 */
366 276 public static function load_single_field_settings( $atts ) {
367 277 $field = $atts['field'];
368 278 $field_obj = $atts['field_obj'];
@@ -377,19 +287,19 @@
377 287 if ( ! isset( $field['read_only'] ) ) {
378 288 $field['read_only'] = false;
379 289 }
380 290
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'] );
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();
386 296
387 297 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
388 298 // Add fallback for an add-on field type that has been deactivated.
389 299 $all_field_types[ $field['type'] ] = array(
390 300 'name' => ucfirst( $field['type'] ),
391 - 'icon' => 'frmfont frm_pencil_icon',
301 + 'icon' => 'frm_icon_font frm_pencil_icon',
392 302 );
393 303 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
394 304 // Fallback for fields added in a more basic way.
395 305 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -395,9 +305,8 @@
395 305 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
396 306 }
397 307
398 308 $type_name = $all_field_types[ $field['type'] ]['name'];
399 -
400 309 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
401 310 $type_name = $all_field_types['divider|repeat']['name'];
402 311 }
403 312
@@ -408,147 +317,61 @@
408 317 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
409 318 $field['placeholder'] = implode( ', ', $field['placeholder'] );
410 319 }
411 320
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 321 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
484 322 }
485 323
486 324 /**
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 325 * Get the list of default value types that can be toggled in the builder.
500 326 *
501 327 * @since 4.0
502 - *
503 - * @param array $field
504 - * @param array $atts
505 - *
506 328 * @return array
507 329 */
508 330 private static function default_value_types( $field, $atts ) {
509 331 $types = array(
510 - 'default_value' => array(
332 + 'default_value' => array(
511 333 'class' => '',
512 - 'icon' => 'frmfont frm_text2_icon',
513 - 'title' => __( 'Default Value', 'formidable' ),
334 + 'icon' => 'frm_icon_font frm_text2_icon',
335 + 'title' => __( 'Default Value (Text)', 'formidable' ),
514 336 'data' => array(
515 337 'frmshow' => '#default-value-for-',
516 338 ),
517 339 ),
518 - 'calc' => array(
519 - 'class' => 'frm_show_upgrade frm_noallow',
520 - 'title' => __( 'Calculate Value', 'formidable' ),
521 - 'icon' => 'frmfont frm_calculator_icon',
522 - '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(
523 345 'medium' => 'calculations',
524 346 'upgrade' => __( 'Calculator forms', 'formidable' ),
525 347 ),
526 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
527 348 ),
528 349 'get_values_field' => array(
529 - 'class' => 'frm_show_upgrade frm_noallow',
530 - 'title' => __( 'Lookup', 'formidable' ),
531 - 'icon' => 'frmfont frm_search_icon',
532 - '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(
533 354 'medium' => 'lookup',
534 355 'upgrade' => __( 'Lookup fields', 'formidable' ),
535 356 ),
536 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
537 357 ),
538 358 );
539 359
540 360 $types = apply_filters( 'frm_default_value_types', $types, $atts );
541 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 +
542 367 // Set active class.
543 368 $settings = array_keys( $types );
544 369 $active = 'default_value';
545 370
546 - if ( FrmAppHelper::pro_is_connected() ) {
547 - foreach ( $settings as $type ) {
548 - if ( ! empty( $field[ $type ] ) ) {
549 - $active = $type;
550 - }
371 + foreach ( $settings as $type ) {
372 + if ( ! empty( $field[ $type ] ) ) {
373 + $active = $type;
551 374 }
552 375 }
553 376
554 377 $types[ $active ]['class'] .= ' current';
@@ -556,13 +379,8 @@
556 379
557 380 return $types;
558 381 }
559 382
560 - /**
561 - * @param string $type
562 - *
563 - * @return string
564 - */
565 383 public static function change_type( $type ) {
566 384 $type_switch = array(
567 385 'scale' => 'radio',
568 386 'star' => 'radio',
@@ -570,9 +388,8 @@
570 388 'rte' => 'textarea',
571 389 'website' => 'url',
572 390 'image' => 'url',
573 391 );
574 -
575 392 if ( isset( $type_switch[ $type ] ) ) {
576 393 $type = $type_switch[ $type ];
577 394 }
578 395
@@ -578,24 +395,26 @@
578 395
579 396 $pro_fields = FrmField::pro_field_selection();
580 397 // We want to keep credit_card types as credit card types for Stripe Lite.
581 398 // The credit_card key is set for backward compatibility.
582 - FrmField::remove_moved_field_types_from_pro( $pro_fields );
399 + unset( $pro_fields['credit_card'] );
583 400
584 - 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;
585 406 }
586 407
587 408 /**
588 - * @param array $settings
589 - * @param FrmFieldType|null $field_info
409 + * @param array $settings
410 + * @param object $field_info
590 411 *
591 412 * @return array
592 413 */
593 414 public static function display_field_options( $settings, $field_info = null ) {
594 415 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.
416 + $settings = $field_info->display_field_settings();
598 417 $settings['field_data'] = $field_info->field;
599 418 }
600 419
601 420 return apply_filters( 'frm_display_field_options', $settings );
@@ -605,32 +424,14 @@
605 424 * Display the format option
606 425 *
607 426 * @since 3.0
608 427 *
609 - * @param array $field Field data.
610 - * @param bool $is_hidden Whether the format option should be hidden.
611 - *
612 - * @return void
428 + * @param array $field
613 429 */
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';
430 + public static function show_format_option( $field ) {
431 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
625 432 }
626 433
627 - /**
628 - * @param array $field
629 - * @param bool $echo
630 - *
631 - * @return string
632 - */
633 434 public static function input_html( $field, $echo = true ) {
634 435 $class = array();
635 436 self::add_input_classes( $field, $class );
636 437
@@ -645,9 +446,8 @@
645 446 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
646 447
647 448 self::add_shortcodes_to_html( $field, $add_html );
648 449 self::add_pattern_attribute( $field, $add_html );
649 - self::add_currency_field_attributes( $field, $add_html );
650 450
651 451 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
652 452 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
653 453
@@ -657,20 +457,14 @@
657 457
658 458 return $add_html;
659 459 }
660 460
661 - /**
662 - * @param array $field
663 - * @param array $class
664 - *
665 - * @return void
666 - */
667 461 private static function add_input_classes( $field, array &$class ) {
668 - if ( ! empty( $field['input_class'] ) ) {
462 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
669 463 $class[] = $field['input_class'];
670 464 }
671 465
672 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
466 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
673 467 return;
674 468 }
675 469
676 470 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -677,14 +471,8 @@
677 471 $class[] = 'auto_width';
678 472 }
679 473 }
680 474
681 - /**
682 - * @param array $field
683 - * @param array $add_html
684 - *
685 - * @return void
686 - */
687 475 private static function add_html_size( $field, array &$add_html ) {
688 476 $size_fields = array(
689 477 'select',
690 478 'data',
@@ -693,9 +481,9 @@
693 481 'file',
694 482 'lookup',
695 483 );
696 484
697 - 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 ) ) {
698 486 return;
699 487 }
700 488
701 489 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -712,14 +500,8 @@
712 500
713 501 self::add_html_cols( $field, $add_html );
714 502 }
715 503
716 - /**
717 - * @param array $field
718 - * @param array $add_html
719 - *
720 - * @return void
721 - */
722 504 private static function add_html_cols( $field, array &$add_html ) {
723 505 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
724 506 return;
725 507 }
@@ -731,9 +513,9 @@
731 513 'rem' => 0.444,
732 514 'em' => 0.544,
733 515 );
734 516
735 - // Include "col" for valid html
517 + // include "col" for valid html
736 518 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
737 519
738 520 if ( ! isset( $calc[ $unit ] ) ) {
739 521 return;
@@ -738,18 +520,13 @@
738 520 if ( ! isset( $calc[ $unit ] ) ) {
739 521 return;
740 522 }
741 523
742 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
524 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
525 +
743 526 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
744 527 }
745 528
746 - /**
747 - * @param array $field
748 - * @param array $add_html
749 - *
750 - * @return void
751 - */
752 529 private static function add_html_length( $field, array &$add_html ) {
753 530 // Check for max setting and if this field accepts maxlength.
754 531 $fields = array(
755 532 'textarea',
@@ -757,9 +534,9 @@
757 534 'hidden',
758 535 'file',
759 536 );
760 537
761 - 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 ) ) {
762 539 return;
763 540 }
764 541
765 542 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -769,17 +546,9 @@
769 546
770 547 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
771 548 }
772 549
773 - /**
774 - * @param array $field
775 - * @param array $add_html
776 - * @param array $class
777 - *
778 - * @return void
779 - */
780 550 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
781 - // phpcs:ignore Universal.Operators.StrictComparisons
782 551 if ( $field['default_value'] != '' ) {
783 552 if ( is_array( $field['default_value'] ) ) {
784 553 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
785 554 } else {
@@ -787,16 +556,26 @@
787 556 }
788 557 }
789 558
790 559 $field['placeholder'] = self::prepare_placeholder( $field );
791 -
792 - // phpcs:ignore Universal.Operators.StrictComparisons
793 560 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
794 - // Don't include a json placeholder
561 + // don't include a json placeholder
795 562 return;
796 563 }
797 564
798 - 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 + }
799 578 }
800 579
801 580 /**
802 581 * Prepares field placeholder.
@@ -803,13 +582,14 @@
803 582 *
804 583 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
805 584 *
806 585 * @param array $field Field array.
807 - *
808 586 * @return string
809 587 */
810 588 private static function prepare_placeholder( $field ) {
811 - return $field['placeholder'] ?? '';
589 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
590 +
591 + return $placeholder;
812 592 }
813 593
814 594 /**
815 595 * If the label position is "inside",
@@ -830,39 +610,22 @@
830 610 * Maybe add a blank placeholder option before any options
831 611 * in a dropdown.
832 612 *
833 613 * @since 4.04
834 - *
835 - * @param array|object $field
836 - *
837 614 * @return bool True if placeholder was added.
838 615 */
839 616 public static function add_placeholder_to_select( $field ) {
840 617 $placeholder = FrmField::get_option( $field, 'placeholder' );
841 -
842 - if ( ! $placeholder ) {
618 + if ( empty( $placeholder ) ) {
843 619 $placeholder = self::get_default_value_from_name( $field );
844 620 }
845 621
846 - $use_placeholder = $placeholder;
847 - $autocomplete = FrmField::get_option( $field, 'autocom' );
848 -
849 - if ( $autocomplete ) {
850 - $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
851 -
852 - if ( $use_chosen ) {
853 - $use_placeholder = '';
854 - }
855 - }
856 -
857 622 if ( $placeholder !== '' ) {
858 - $placeholder_attributes = array(
859 - 'class' => 'frm-select-placeholder',
860 - 'value' => '',
861 - 'data-placeholder' => 'true',
862 - );
863 -
864 - 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
865 628 return true;
866 629 }
867 630
868 631 return false;
@@ -868,14 +631,12 @@
868 631 return false;
869 632 }
870 633
871 634 /**
872 - * Use HTML5 placeholder with js fallback.
635 + * Use HMTL5 placeholder with js fallback
873 636 *
874 637 * @param array $field
875 638 * @param array $add_html
876 - *
877 - * @return void
878 639 */
879 640 private static function add_placeholder_to_input( $field, &$add_html ) {
880 641 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
881 642 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -881,16 +642,9 @@
881 642 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
882 643 }
883 644 }
884 645
885 - /**
886 - * @param array $field
887 - * @param array $add_html
888 - *
889 - * @return void
890 - */
891 646 private static function add_frmval_to_input( $field, &$add_html ) {
892 - // phpcs:ignore Universal.Operators.StrictComparisons
893 647 if ( $field['placeholder'] != '' ) {
894 648 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
895 649
896 650 if ( 'select' === $field['type'] ) {
@@ -897,30 +651,21 @@
897 651 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
898 652 }
899 653 }
900 654
901 - // phpcs:ignore Universal.Operators.StrictComparisons
902 655 if ( $field['default_value'] != '' ) {
903 656 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
904 657 }
905 658 }
906 659
907 - /**
908 - * @param array $field
909 - * @param array $add_html
910 - *
911 - * @return void
912 - */
913 660 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'] ) ) {
661 + if ( FrmField::is_required( $field ) ) {
917 662 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
918 663 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
919 664 self::maybe_add_html_required( $field, $add_html );
920 665 }
921 666
922 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
667 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
923 668 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
924 669 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
925 670 }
926 671
@@ -929,63 +674,24 @@
929 674 }
930 675 }
931 676
932 677 /**
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 678 * @since 5.0.03
967 679 *
968 680 * @param array $field
969 681 * @param array $add_html
970 - *
971 - * @return void
972 682 */
973 683 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
974 684 $form = self::get_form_for_js_validation( $field );
975 -
976 685 if ( false === $form ) {
977 686 return;
978 687 }
979 688
980 689 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
981 -
982 - if ( false === $error_body ) {
983 - 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 ) . '"';
984 693 }
985 -
986 - $error_body = urlencode( $error_body );
987 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
988 694 }
989 695
990 696 /**
991 697 * @since 5.0.03
@@ -990,24 +696,20 @@
990 696 /**
991 697 * @since 5.0.03
992 698 *
993 699 * @param array $field
994 - *
995 - * @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.
996 701 */
997 702 private static function get_form_for_js_validation( $field ) {
998 703 global $frm_vars;
999 -
1000 704 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
1001 705 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
1002 706 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
1003 707 }
1004 -
1005 708 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
1006 709 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
1007 710 }
1008 711 }
1009 -
1010 712 return false;
1011 713 }
1012 714
1013 715 /**
@@ -1013,10 +715,9 @@
1013 715 /**
1014 716 * @param stdClass $form
1015 717 * @param array $field
1016 718 * @param array $errors
1017 - *
1018 - * @return false|string
719 + * @return string|false
1019 720 */
1020 721 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
1021 722 if ( empty( $field['custom_html'] ) ) {
1022 723 return false;
@@ -1023,16 +724,15 @@
1023 724 }
1024 725
1025 726 $custom_html = $field['custom_html'];
1026 727 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
1027 - $start = strpos( $custom_html, '[if error]' );
1028 728
729 + $start = strpos( $custom_html, '[if error]' );
1029 730 if ( false === $start ) {
1030 731 return false;
1031 732 }
1032 733
1033 734 $end = strpos( $custom_html, '[/if error]' );
1034 -
1035 735 if ( false === $end || $end < $start ) {
1036 736 return false;
1037 737 }
1038 738
@@ -1043,9 +743,13 @@
1043 743 '<div class="frm_error">[error]</div>',
1044 744 '<div class="frm_error" role="alert">[error]</div>',
1045 745 );
1046 746
1047 - 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;
1048 752 }
1049 753
1050 754 /**
1051 755 * If 'required' is added to a conditionally hidden field, the form won't
@@ -1052,16 +756,12 @@
1052 756 * submit in many browsers. Check to make sure the javascript to conditionally
1053 757 * remove it is present if needed.
1054 758 *
1055 759 * @since 3.06.01
1056 - *
1057 760 * @param array $field
1058 761 * @param array $add_html
1059 - *
1060 - * @return void
1061 762 */
1062 763 private static function maybe_add_html_required( $field, array &$add_html ) {
1063 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1064 764 $excluded_field_types =
1065 765 FrmField::is_radio( $field ) ||
1066 766 FrmField::is_checkbox( $field ) ||
1067 767 FrmField::is_field_type( $field, 'file' ) ||
@@ -1066,23 +766,19 @@
1066 766 FrmField::is_checkbox( $field ) ||
1067 767 FrmField::is_field_type( $field, 'file' ) ||
1068 768 FrmField::is_field_type( $field, 'nps' ) ||
1069 769 FrmField::is_field_type( $field, 'scale' );
1070 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1071 770
1072 771 if ( $excluded_field_types ) {
1073 772 return;
1074 773 }
1075 774
1076 - $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 + }
1077 779 }
1078 780
1079 - /**
1080 - * @param array $field
1081 - * @param array $add_html
1082 - *
1083 - * @return void
1084 - */
1085 781 private static function add_shortcodes_to_html( $field, array &$add_html ) {
1086 782 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
1087 783 return;
1088 784 }
@@ -1091,25 +787,13 @@
1091 787 unset( $field['shortcodes']['autocomplete'] );
1092 788 }
1093 789
1094 790 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 ) ) {
791 + if ( 'opt' === $k ) {
1108 792 continue;
1109 793 }
1110 794
1111 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
795 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1112 796 $add_html[] = $v;
1113 797 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1114 798 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1115 799 } else {
@@ -1116,128 +800,129 @@
1116 800 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1117 801 }
1118 802
1119 803 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 804 }
1136 - return FrmAppHelper::input_key_is_safe( $key );
1137 805 }
1138 806
1139 807 /**
1140 - * Add pattern attribute.
808 + * Add pattern attribute
1141 809 *
1142 810 * @since 3.0
1143 811 *
1144 812 * @param array $field
1145 813 * @param array $add_html
1146 - *
1147 - * @return void
1148 814 */
1149 815 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 );
816 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1152 817 $format_field = FrmField::is_field_type( $field, 'text' );
1153 818
1154 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1155 - return;
1156 - }
819 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
820 + $frm_settings = FrmAppHelper::get_settings();
1157 821
1158 - $format = FrmEntryValidate::phone_format( $field );
1159 - $format = substr( $format, 2, - 1 );
822 + if ( $frm_settings->use_html ) {
823 + $format = FrmEntryValidate::phone_format( $field );
824 + $format = substr( $format, 2, - 1 );
1160 825
1161 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
826 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
827 + }
828 + }
1162 829 }
1163 830
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;
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 + }
1178 838 }
1179 839
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 );
840 + return $opt;
841 + }
1189 842
1190 - $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 ) );
1191 846 }
847 +
848 + return $opt;
1192 849 }
1193 850
1194 851 /**
1195 - * @param array $field
852 + * @deprecated 4.0
1196 853 */
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'];
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();
1205 862 }
1206 863
1207 - $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
864 + $field = FrmField::getOne( $field_id );
1208 865
1209 - if ( method_exists( $field_obj, 'get_posted_price' ) ) {
1210 - 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 );
1211 871 }
1212 872
1213 - 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();
1214 881 }
1215 882
1216 883 /**
1217 - * @param mixed $opt
1218 - * @param mixed $opt_key
1219 - * @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.
1220 893 *
1221 - * @return mixed
894 + * @deprecated 4.0 Moved to Pro for Other option only.
1222 895 */
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 - }
896 + public static function add_option() {
897 + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
898 + }
1231 899
1232 - return $opt;
900 + /**
901 + * @deprecated 4.0
902 + */
903 + public static function update_order() {
904 + FrmDeprecated::update_order();
1233 905 }
1234 906
1235 907 /**
1236 - * @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
1237 918 *
1238 - * @return mixed
919 + * @param int $field_id
920 + * @param array $values
921 + * @param int $form_id
922 + *
923 + * @return array
1239 924 */
1240 - public static function check_label( $opt ) {
1241 - 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 );
1242 927 }
1243 928 }