PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7.2
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmFieldsController.php +221 -496 6.306.7.2 View file →
@@ -4,15 +4,8 @@
4 4 }
5 5
6 6 class FrmFieldsController {
7 7
8 - /**
9 - * This is stored statically so we can re-use this data for every field.
10 - *
11 - * @var FrmFieldSelectionData|null
12 - */
13 - private static $field_selection_data;
14 -
15 8 public static function load_field() {
16 9 FrmAppHelper::permission_check( 'frm_edit_forms' );
17 10 check_ajax_referer( 'frm_ajax', 'nonce' );
18 11
@@ -18,10 +11,9 @@
18 11
19 12 // Javascript may be included in some field settings.
20 13 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
21 14 $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array();
22 -
23 - if ( ! $fields ) {
15 + if ( empty( $fields ) ) {
24 16 wp_die();
25 17 }
26 18
27 19 $_GET['page'] = 'formidable';
@@ -34,11 +26,10 @@
34 26
35 27 foreach ( $fields as $field ) {
36 28 $field = htmlspecialchars_decode( nl2br( $field ) );
37 29 $field = json_decode( $field );
38 -
39 30 if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
40 - // This field may have already been loaded
31 + // this field may have already been loaded
41 32 continue;
42 33 }
43 34
44 35 if ( ! isset( $field->value ) ) {
@@ -49,10 +40,11 @@
49 40 $field->default_value = json_decode( json_encode( $field->default_value ), true );
50 41
51 42 ob_start();
52 43 self::load_single_field( $field, $values );
53 - $field_html[ absint( $field->id ) ] = ob_get_clean();
54 - }//end foreach
44 + $field_html[ absint( $field->id ) ] = ob_get_contents();
45 + ob_end_clean();
46 + }
55 47
56 48 echo json_encode( $field_html );
57 49
58 50 wp_die();
@@ -64,17 +56,16 @@
64 56 public static function create() {
65 57 FrmAppHelper::permission_check( 'frm_edit_forms' );
66 58 check_ajax_referer( 'frm_ajax', 'nonce' );
67 59
68 - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
69 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
70 - $field_options = FrmAppHelper::get_post_param( 'field_options', array(), 'wp_kses_post' );
60 + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
61 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
71 62
72 63 do_action( 'frm_before_create_field', $field_type, $form_id );
73 64
74 - $field = self::include_new_field( $field_type, $form_id, $field_options );
65 + $field = self::include_new_field( $field_type, $form_id );
75 66
76 - // This hook will allow for multiple fields to be added at once
67 + // this hook will allow for multiple fields to be added at once
77 68 do_action( 'frm_after_field_created', $field, $form_id );
78 69
79 70 wp_die();
80 71 }
@@ -81,24 +72,16 @@
81 72
82 73 /**
83 74 * Set up and create a new field
84 75 *
85 - * @param string $field_type
86 - * @param int $form_id
87 - * @param array $field_options
76 + * @param string $field_type
77 + * @param integer $form_id
88 78 *
89 - * @return array|false
79 + * @return array|bool
90 80 */
91 - public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
81 + public static function include_new_field( $field_type, $form_id ) {
92 82 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
93 83
94 - if ( $field_options ) {
95 - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
96 - }
97 -
98 - // When a new field is added to the form, flag it as draft and hide it from the front-end.
99 - $field_values['field_options']['draft'] = 1;
100 -
101 84 /**
102 85 * @param array $field_values
103 86 */
104 87 $field_values = apply_filters( 'frm_before_field_created', $field_values );
@@ -107,15 +90,15 @@
107 90 if ( ! $field_id ) {
108 91 return false;
109 92 }
110 93
111 - $field = self::get_field_array_from_id( $field_id );
94 + $field = self::get_field_array_from_id( $field_id );
95 +
112 96 $values = array();
113 -
114 97 if ( FrmAppHelper::pro_is_installed() ) {
115 98 $values['post_type'] = FrmProFormsHelper::post_type( $form_id );
116 - $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
117 99
100 + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
118 101 if ( $parent_form_id ) {
119 102 $field['parent_form_id'] = $parent_form_id;
120 103 }
121 104 }
@@ -128,10 +111,11 @@
128 111 public static function duplicate() {
129 112 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 113 check_ajax_referer( 'frm_ajax', 'nonce' );
131 114
132 - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
133 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
115 + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
116 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
117 +
134 118 $new_field = FrmField::duplicate_single_field( $field_id, $form_id );
135 119
136 120 if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) {
137 121 self::load_single_field( $new_field['field_id'], $new_field['values'] );
@@ -148,8 +132,9 @@
148 132 * @return array
149 133 */
150 134 public static function get_field_array_from_id( $field_id ) {
151 135 $field = FrmField::getOne( $field_id );
136 +
152 137 return FrmFieldsHelper::setup_edit_vars( $field );
153 138 }
154 139
155 140 /**
@@ -154,13 +139,11 @@
154 139
155 140 /**
156 141 * @since 3.0
157 142 *
158 - * @param array|int|object|string $field_object
159 - * @param array $values
160 - * @param int $form_id
161 - *
162 - * @return void
143 + * @param int|array|object $field_object
144 + * @param array $values
145 + * @param int $form_id
163 146 */
164 147 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
165 148 global $frm_vars;
166 149 $frm_vars['is_admin'] = true;
@@ -171,49 +154,33 @@
171 154 $field = $field_object;
172 155 $field_object = FrmField::getOne( $field['id'] );
173 156 }
174 157
175 - $field_obj = FrmFieldFactory::get_field_factory( $field_object );
176 - $display = self::display_field_options( array(), $field_obj );
177 - $ajax_loading = ! empty( $values['ajax_load'] );
178 - $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ), true );
158 + $field_obj = FrmFieldFactory::get_field_factory( $field_object );
159 + $display = self::display_field_options( array(), $field_obj );
179 160
161 + $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
162 + $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) );
163 +
180 164 if ( $ajax_loading && $ajax_this_field ) {
181 165 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
182 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php';
183 - return;
184 - }
166 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' );
167 + } else {
168 + if ( ! isset( $field ) && is_object( $field_object ) ) {
169 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
185 170
186 - if ( ! isset( $field ) && is_object( $field_object ) ) {
187 - $field_object->parent_form_id = $values['id'] ?? $field_object->form_id;
188 - $field = FrmFieldsHelper::setup_edit_vars( $field_object );
189 - }
171 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
172 + }
190 173
191 - /**
192 - * Filter for adding extra attributes to the field container.
193 - *
194 - * @since 6.23
195 - *
196 - * @param array $extra_field_attributes
197 - * @param array $field
198 - * @param array $display
199 - */
200 - $extra_field_attributes = apply_filters( 'frm_field_container_extra_attributes', array(), $field, $display );
174 + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
175 + $li_classes .= ' ui-state-default widgets-holder-wrap';
201 176
202 - $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
203 - $li_classes .= ' ui-state-default widgets-holder-wrap';
204 -
205 - require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
177 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
178 + }
206 179 }
207 180
208 181 /**
209 182 * @since 3.0
210 - *
211 - * @param array $field
212 - * @param array $display
213 - * @param FrmFieldType $field_info
214 - *
215 - * @return string
216 183 */
217 184 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
218 185 $li_classes = $field_info->form_builder_classes( $display['type'] );
219 186 $li_classes .= ' frm_form_field frmstart ';
@@ -224,9 +191,9 @@
224 191
225 192 $li_classes .= 'frmend';
226 193
227 194 if ( $field ) {
228 - return apply_filters( 'frm_build_field_class', $li_classes, $field );
195 + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
229 196 }
230 197
231 198 return $li_classes;
232 199 }
@@ -250,40 +217,27 @@
250 217 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
251 218 return;
252 219 }
253 220
254 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
255 - $field = FrmField::getOne( $field_id );
256 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
221 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
222 + $field = FrmField::getOne( $field_id );
257 223
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 ) ) {
224 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
270 225 return;
271 226 }
272 227
273 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 );
274 232
275 - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
276 - $opts = explode( "\n", rtrim( $opts, "\n" ) );
277 - $opts = array_map( 'trim', $opts );
233 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
234 + $field['separate_value'] = ( $separate === 'true' );
278 235
279 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
280 - $field['separate_value'] = $separate === 'true';
281 -
282 236 if ( $field['separate_value'] ) {
283 237 foreach ( $opts as $opt_key => $opt ) {
284 - if ( str_contains( $opt, '|' ) ) {
285 - $vals = explode( '|', $opt );
238 + if ( strpos( $opt, '|' ) !== false ) {
239 + $vals = explode( '|', $opt );
286 240 $opts[ $opt_key ] = array(
287 241 'label' => trim( $vals[0] ),
288 242 'value' => trim( $vals[1] ),
289 243 );
@@ -293,11 +247,10 @@
293 247 }
294 248 }
295 249
296 250 // Keep other options after bulk update.
297 - if ( ! empty( $field['field_options']['other'] ) ) {
251 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
298 252 $other_array = array();
299 -
300 253 foreach ( $field['options'] as $opt_key => $opt ) {
301 254 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
302 255 $other_array[ $opt_key ] = $opt;
303 256 }
@@ -302,10 +255,9 @@
302 255 $other_array[ $opt_key ] = $opt;
303 256 }
304 257 unset( $opt_key, $opt );
305 258 }
306 -
307 - if ( $other_array ) {
259 + if ( ! empty( $other_array ) ) {
308 260 $opts = array_merge( $opts, $other_array );
309 261 }
310 262 }
311 263
@@ -319,10 +271,8 @@
319 271 /**
320 272 * @since 4.0
321 273 *
322 274 * @param array $atts - Includes field array, field_obj, display array, values array.
323 - *
324 - * @return void
325 275 */
326 276 public static function load_single_field_settings( $atts ) {
327 277 $field = $atts['field'];
328 278 $field_obj = $atts['field_obj'];
@@ -337,19 +287,19 @@
337 287 if ( ! isset( $field['read_only'] ) ) {
338 288 $field['read_only'] = false;
339 289 }
340 290
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'] );
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();
346 296
347 297 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
348 298 // Add fallback for an add-on field type that has been deactivated.
349 299 $all_field_types[ $field['type'] ] = array(
350 300 'name' => ucfirst( $field['type'] ),
351 - 'icon' => 'frmfont frm_pencil_icon',
301 + 'icon' => 'frm_icon_font frm_pencil_icon',
352 302 );
353 303 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
354 304 // Fallback for fields added in a more basic way.
355 305 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -355,9 +305,8 @@
355 305 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
356 306 }
357 307
358 308 $type_name = $all_field_types[ $field['type'] ]['name'];
359 -
360 309 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
361 310 $type_name = $all_field_types['divider|repeat']['name'];
362 311 }
363 312
@@ -368,147 +317,61 @@
368 317 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
369 318 $field['placeholder'] = implode( ', ', $field['placeholder'] );
370 319 }
371 320
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 321 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
444 322 }
445 323
446 324 /**
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 325 * Get the list of default value types that can be toggled in the builder.
460 326 *
461 327 * @since 4.0
462 - *
463 - * @param array $field
464 - * @param array $atts
465 - *
466 328 * @return array
467 329 */
468 330 private static function default_value_types( $field, $atts ) {
469 331 $types = array(
470 - 'default_value' => array(
332 + 'default_value' => array(
471 333 'class' => '',
472 - 'icon' => 'frmfont frm_text2_icon',
473 - 'title' => __( 'Default Value', 'formidable' ),
334 + 'icon' => 'frm_icon_font frm_text2_icon',
335 + 'title' => __( 'Default Value (Text)', 'formidable' ),
474 336 'data' => array(
475 337 'frmshow' => '#default-value-for-',
476 338 ),
477 339 ),
478 - 'calc' => array(
479 - 'class' => 'frm_show_upgrade frm_noallow',
480 - 'title' => __( 'Calculate Value', 'formidable' ),
481 - 'icon' => 'frmfont frm_calculator_icon',
482 - '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(
483 345 'medium' => 'calculations',
484 346 'upgrade' => __( 'Calculator forms', 'formidable' ),
485 347 ),
486 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
487 348 ),
488 349 'get_values_field' => array(
489 - 'class' => 'frm_show_upgrade frm_noallow',
490 - 'title' => __( 'Lookup', 'formidable' ),
491 - 'icon' => 'frmfont frm_search_icon',
492 - '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(
493 354 'medium' => 'lookup',
494 355 'upgrade' => __( 'Lookup fields', 'formidable' ),
495 356 ),
496 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
497 357 ),
498 358 );
499 359
500 360 $types = apply_filters( 'frm_default_value_types', $types, $atts );
501 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 +
502 367 // Set active class.
503 368 $settings = array_keys( $types );
504 369 $active = 'default_value';
505 370
506 - if ( FrmAppHelper::pro_is_connected() ) {
507 - foreach ( $settings as $type ) {
508 - if ( ! empty( $field[ $type ] ) ) {
509 - $active = $type;
510 - }
371 + foreach ( $settings as $type ) {
372 + if ( ! empty( $field[ $type ] ) ) {
373 + $active = $type;
511 374 }
512 375 }
513 376
514 377 $types[ $active ]['class'] .= ' current';
@@ -516,13 +379,8 @@
516 379
517 380 return $types;
518 381 }
519 382
520 - /**
521 - * @param string $type
522 - *
523 - * @return string
524 - */
525 383 public static function change_type( $type ) {
526 384 $type_switch = array(
527 385 'scale' => 'radio',
528 386 'star' => 'radio',
@@ -530,9 +388,8 @@
530 388 'rte' => 'textarea',
531 389 'website' => 'url',
532 390 'image' => 'url',
533 391 );
534 -
535 392 if ( isset( $type_switch[ $type ] ) ) {
536 393 $type = $type_switch[ $type ];
537 394 }
538 395
@@ -538,24 +395,26 @@
538 395
539 396 $pro_fields = FrmField::pro_field_selection();
540 397 // We want to keep credit_card types as credit card types for Stripe Lite.
541 398 // The credit_card key is set for backward compatibility.
542 - FrmField::remove_moved_field_types_from_pro( $pro_fields );
399 + unset( $pro_fields['credit_card'] );
543 400
544 - 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;
545 406 }
546 407
547 408 /**
548 - * @param array $settings
549 - * @param FrmFieldType|null $field_info
409 + * @param array $settings
410 + * @param object $field_info
550 411 *
551 412 * @return array
552 413 */
553 414 public static function display_field_options( $settings, $field_info = null ) {
554 415 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.
416 + $settings = $field_info->display_field_settings();
558 417 $settings['field_data'] = $field_info->field;
559 418 }
560 419
561 420 return apply_filters( 'frm_display_field_options', $settings );
@@ -565,32 +424,14 @@
565 424 * Display the format option
566 425 *
567 426 * @since 3.0
568 427 *
569 - * @param array $field Field data.
570 - * @param bool $is_hidden Whether the format option should be hidden.
571 - *
572 - * @return void
428 + * @param array $field
573 429 */
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';
430 + public static function show_format_option( $field ) {
431 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
585 432 }
586 433
587 - /**
588 - * @param array $field
589 - * @param bool $echo
590 - *
591 - * @return string
592 - */
593 434 public static function input_html( $field, $echo = true ) {
594 435 $class = array();
595 436 self::add_input_classes( $field, $class );
596 437
@@ -605,9 +446,8 @@
605 446 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
606 447
607 448 self::add_shortcodes_to_html( $field, $add_html );
608 449 self::add_pattern_attribute( $field, $add_html );
609 - self::add_currency_field_attributes( $field, $add_html );
610 450
611 451 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
612 452 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
613 453
@@ -617,20 +457,14 @@
617 457
618 458 return $add_html;
619 459 }
620 460
621 - /**
622 - * @param array $field
623 - * @param array $class
624 - *
625 - * @return void
626 - */
627 461 private static function add_input_classes( $field, array &$class ) {
628 - if ( ! empty( $field['input_class'] ) ) {
462 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
629 463 $class[] = $field['input_class'];
630 464 }
631 465
632 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
466 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
633 467 return;
634 468 }
635 469
636 470 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -637,14 +471,8 @@
637 471 $class[] = 'auto_width';
638 472 }
639 473 }
640 474
641 - /**
642 - * @param array $field
643 - * @param array $add_html
644 - *
645 - * @return void
646 - */
647 475 private static function add_html_size( $field, array &$add_html ) {
648 476 $size_fields = array(
649 477 'select',
650 478 'data',
@@ -653,9 +481,9 @@
653 481 'file',
654 482 'lookup',
655 483 );
656 484
657 - 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 ) ) {
658 486 return;
659 487 }
660 488
661 489 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -672,14 +500,8 @@
672 500
673 501 self::add_html_cols( $field, $add_html );
674 502 }
675 503
676 - /**
677 - * @param array $field
678 - * @param array $add_html
679 - *
680 - * @return void
681 - */
682 504 private static function add_html_cols( $field, array &$add_html ) {
683 505 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
684 506 return;
685 507 }
@@ -691,9 +513,9 @@
691 513 'rem' => 0.444,
692 514 'em' => 0.544,
693 515 );
694 516
695 - // Include "col" for valid html
517 + // include "col" for valid html
696 518 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
697 519
698 520 if ( ! isset( $calc[ $unit ] ) ) {
699 521 return;
@@ -698,18 +520,13 @@
698 520 if ( ! isset( $calc[ $unit ] ) ) {
699 521 return;
700 522 }
701 523
702 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
524 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
525 +
703 526 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
704 527 }
705 528
706 - /**
707 - * @param array $field
708 - * @param array $add_html
709 - *
710 - * @return void
711 - */
712 529 private static function add_html_length( $field, array &$add_html ) {
713 530 // Check for max setting and if this field accepts maxlength.
714 531 $fields = array(
715 532 'textarea',
@@ -717,9 +534,9 @@
717 534 'hidden',
718 535 'file',
719 536 );
720 537
721 - 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 ) ) {
722 539 return;
723 540 }
724 541
725 542 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -729,17 +546,9 @@
729 546
730 547 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
731 548 }
732 549
733 - /**
734 - * @param array $field
735 - * @param array $add_html
736 - * @param array $class
737 - *
738 - * @return void
739 - */
740 550 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
741 - // phpcs:ignore Universal.Operators.StrictComparisons
742 551 if ( $field['default_value'] != '' ) {
743 552 if ( is_array( $field['default_value'] ) ) {
744 553 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
745 554 } else {
@@ -747,16 +556,26 @@
747 556 }
748 557 }
749 558
750 559 $field['placeholder'] = self::prepare_placeholder( $field );
751 -
752 - // phpcs:ignore Universal.Operators.StrictComparisons
753 560 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
754 - // Don't include a json placeholder
561 + // don't include a json placeholder
755 562 return;
756 563 }
757 564
758 - 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 + }
759 578 }
760 579
761 580 /**
762 581 * Prepares field placeholder.
@@ -763,13 +582,14 @@
763 582 *
764 583 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
765 584 *
766 585 * @param array $field Field array.
767 - *
768 586 * @return string
769 587 */
770 588 private static function prepare_placeholder( $field ) {
771 - return $field['placeholder'] ?? '';
589 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
590 +
591 + return $placeholder;
772 592 }
773 593
774 594 /**
775 595 * If the label position is "inside",
@@ -790,39 +610,22 @@
790 610 * Maybe add a blank placeholder option before any options
791 611 * in a dropdown.
792 612 *
793 613 * @since 4.04
794 - *
795 - * @param array|object $field
796 - *
797 614 * @return bool True if placeholder was added.
798 615 */
799 616 public static function add_placeholder_to_select( $field ) {
800 617 $placeholder = FrmField::get_option( $field, 'placeholder' );
801 -
802 - if ( ! $placeholder ) {
618 + if ( empty( $placeholder ) ) {
803 619 $placeholder = self::get_default_value_from_name( $field );
804 620 }
805 621
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 622 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 );
623 + ?>
624 + <option class="frm-select-placeholder" value="">
625 + <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
626 + </option>
627 + <?php
825 628 return true;
826 629 }
827 630
828 631 return false;
@@ -828,14 +631,12 @@
828 631 return false;
829 632 }
830 633
831 634 /**
832 - * Use HTML5 placeholder with js fallback.
635 + * Use HMTL5 placeholder with js fallback
833 636 *
834 637 * @param array $field
835 638 * @param array $add_html
836 - *
837 - * @return void
838 639 */
839 640 private static function add_placeholder_to_input( $field, &$add_html ) {
840 641 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
841 642 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -841,16 +642,9 @@
841 642 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
842 643 }
843 644 }
844 645
845 - /**
846 - * @param array $field
847 - * @param array $add_html
848 - *
849 - * @return void
850 - */
851 646 private static function add_frmval_to_input( $field, &$add_html ) {
852 - // phpcs:ignore Universal.Operators.StrictComparisons
853 647 if ( $field['placeholder'] != '' ) {
854 648 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
855 649
856 650 if ( 'select' === $field['type'] ) {
@@ -857,30 +651,21 @@
857 651 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
858 652 }
859 653 }
860 654
861 - // phpcs:ignore Universal.Operators.StrictComparisons
862 655 if ( $field['default_value'] != '' ) {
863 656 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
864 657 }
865 658 }
866 659
867 - /**
868 - * @param array $field
869 - * @param array $add_html
870 - *
871 - * @return void
872 - */
873 660 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'] ) ) {
661 + if ( FrmField::is_required( $field ) ) {
877 662 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
878 663 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
879 664 self::maybe_add_html_required( $field, $add_html );
880 665 }
881 666
882 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
667 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
883 668 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
884 669 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
885 670 }
886 671
@@ -889,63 +674,24 @@
889 674 }
890 675 }
891 676
892 677 /**
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 678 * @since 5.0.03
927 679 *
928 680 * @param array $field
929 681 * @param array $add_html
930 - *
931 - * @return void
932 682 */
933 683 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
934 684 $form = self::get_form_for_js_validation( $field );
935 -
936 685 if ( false === $form ) {
937 686 return;
938 687 }
939 688
940 689 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
941 -
942 - if ( false === $error_body ) {
943 - 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 ) . '"';
944 693 }
945 -
946 - $error_body = urlencode( $error_body );
947 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
948 694 }
949 695
950 696 /**
951 697 * @since 5.0.03
@@ -950,24 +696,20 @@
950 696 /**
951 697 * @since 5.0.03
952 698 *
953 699 * @param array $field
954 - *
955 - * @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.
956 701 */
957 702 private static function get_form_for_js_validation( $field ) {
958 703 global $frm_vars;
959 -
960 704 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
961 705 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
962 706 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
963 707 }
964 -
965 708 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
966 709 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
967 710 }
968 711 }
969 -
970 712 return false;
971 713 }
972 714
973 715 /**
@@ -973,10 +715,9 @@
973 715 /**
974 716 * @param stdClass $form
975 717 * @param array $field
976 718 * @param array $errors
977 - *
978 - * @return false|string
719 + * @return string|false
979 720 */
980 721 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
981 722 if ( empty( $field['custom_html'] ) ) {
982 723 return false;
@@ -983,16 +724,15 @@
983 724 }
984 725
985 726 $custom_html = $field['custom_html'];
986 727 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
987 - $start = strpos( $custom_html, '[if error]' );
988 728
729 + $start = strpos( $custom_html, '[if error]' );
989 730 if ( false === $start ) {
990 731 return false;
991 732 }
992 733
993 734 $end = strpos( $custom_html, '[/if error]' );
994 -
995 735 if ( false === $end || $end < $start ) {
996 736 return false;
997 737 }
998 738
@@ -1003,9 +743,13 @@
1003 743 '<div class="frm_error">[error]</div>',
1004 744 '<div class="frm_error" role="alert">[error]</div>',
1005 745 );
1006 746
1007 - 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;
1008 752 }
1009 753
1010 754 /**
1011 755 * If 'required' is added to a conditionally hidden field, the form won't
@@ -1012,16 +756,12 @@
1012 756 * submit in many browsers. Check to make sure the javascript to conditionally
1013 757 * remove it is present if needed.
1014 758 *
1015 759 * @since 3.06.01
1016 - *
1017 760 * @param array $field
1018 761 * @param array $add_html
1019 - *
1020 - * @return void
1021 762 */
1022 763 private static function maybe_add_html_required( $field, array &$add_html ) {
1023 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1024 764 $excluded_field_types =
1025 765 FrmField::is_radio( $field ) ||
1026 766 FrmField::is_checkbox( $field ) ||
1027 767 FrmField::is_field_type( $field, 'file' ) ||
@@ -1026,23 +766,19 @@
1026 766 FrmField::is_checkbox( $field ) ||
1027 767 FrmField::is_field_type( $field, 'file' ) ||
1028 768 FrmField::is_field_type( $field, 'nps' ) ||
1029 769 FrmField::is_field_type( $field, 'scale' );
1030 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1031 770
1032 771 if ( $excluded_field_types ) {
1033 772 return;
1034 773 }
1035 774
1036 - $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 + }
1037 779 }
1038 780
1039 - /**
1040 - * @param array $field
1041 - * @param array $add_html
1042 - *
1043 - * @return void
1044 - */
1045 781 private static function add_shortcodes_to_html( $field, array &$add_html ) {
1046 782 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
1047 783 return;
1048 784 }
@@ -1051,25 +787,13 @@
1051 787 unset( $field['shortcodes']['autocomplete'] );
1052 788 }
1053 789
1054 790 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 ) ) {
791 + if ( 'opt' === $k ) {
1068 792 continue;
1069 793 }
1070 794
1071 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
795 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1072 796 $add_html[] = $v;
1073 797 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1074 798 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1075 799 } else {
@@ -1076,128 +800,129 @@
1076 800 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1077 801 }
1078 802
1079 803 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 804 }
1096 - return FrmAppHelper::input_key_is_safe( $key );
1097 805 }
1098 806
1099 807 /**
1100 - * Add pattern attribute.
808 + * Add pattern attribute
1101 809 *
1102 810 * @since 3.0
1103 811 *
1104 812 * @param array $field
1105 813 * @param array $add_html
1106 - *
1107 - * @return void
1108 814 */
1109 815 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 );
816 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1112 817 $format_field = FrmField::is_field_type( $field, 'text' );
1113 818
1114 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1115 - return;
1116 - }
819 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
820 + $frm_settings = FrmAppHelper::get_settings();
1117 821
1118 - $format = FrmEntryValidate::phone_format( $field );
1119 - $format = substr( $format, 2, - 1 );
822 + if ( $frm_settings->use_html ) {
823 + $format = FrmEntryValidate::phone_format( $field );
824 + $format = substr( $format, 2, - 1 );
1120 825
1121 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
826 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
827 + }
828 + }
1122 829 }
1123 830
1124 - /**
1125 - * Add product attributes to fields in multi-paged forms.
1126 - *
1127 - * @param array $field
1128 - * @param array $add_html
1129 - *
1130 - * @return void
1131 - */
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 );
1135 -
1136 - if ( ! $is_product_field ) {
1137 - 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 + }
1138 838 }
1139 839
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 );
840 + return $opt;
841 + }
1149 842
1150 - $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 ) );
1151 846 }
847 +
848 + return $opt;
1152 849 }
1153 850
1154 851 /**
1155 - * @param array $field
852 + * @deprecated 4.0
1156 853 */
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'];
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();
1165 862 }
1166 863
1167 - $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
864 + $field = FrmField::getOne( $field_id );
1168 865
1169 - if ( method_exists( $field_obj, 'get_posted_price' ) ) {
1170 - 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 );
1171 871 }
1172 872
1173 - 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();
1174 881 }
1175 882
1176 883 /**
1177 - * @param mixed $opt
1178 - * @param mixed $opt_key
1179 - * @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.
1180 893 *
1181 - * @return mixed
894 + * @deprecated 4.0 Moved to Pro for Other option only.
1182 895 */
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 - }
896 + public static function add_option() {
897 + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
898 + }
1191 899
1192 - return $opt;
900 + /**
901 + * @deprecated 4.0
902 + */
903 + public static function update_order() {
904 + FrmDeprecated::update_order();
1193 905 }
1194 906
1195 907 /**
1196 - * @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
1197 918 *
1198 - * @return mixed
919 + * @param int $field_id
920 + * @param array $values
921 + * @param int $form_id
922 + *
923 + * @return array
1199 924 */
1200 - public static function check_label( $opt ) {
1201 - 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 );
1202 927 }
1203 928 }