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