PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmFieldsController.php +222 -498 6.316.7 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,23 +73,15 @@
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 );
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 }
@@ -239,11 +206,10 @@
239 206 FrmField::destroy( $field_id );
240 207 wp_die();
241 208 }
242 209
243 - /**
244 - * Field Options.
245 - */
210 + /* Field Options */
211 +
246 212 public static function import_options() {
247 213 FrmAppHelper::permission_check( 'frm_edit_forms' );
248 214 check_ajax_referer( 'frm_ajax', 'nonce' );
249 215
@@ -250,40 +216,27 @@
250 216 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
251 217 return;
252 218 }
253 219
254 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
255 - $field = FrmField::getOne( $field_id );
256 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
220 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
221 + $field = FrmField::getOne( $field_id );
257 222
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 ) ) {
223 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
270 224 return;
271 225 }
272 226
273 227 $field = FrmFieldsHelper::setup_edit_vars( $field );
228 + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
229 + $opts = explode( "\n", rtrim( $opts, "\n" ) );
230 + $opts = array_map( 'trim', $opts );
274 231
275 - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
276 - $opts = explode( "\n", rtrim( $opts, "\n" ) );
277 - $opts = array_map( 'trim', $opts );
232 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
233 + $field['separate_value'] = ( $separate === 'true' );
278 234
279 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
280 - $field['separate_value'] = $separate === 'true';
281 -
282 235 if ( $field['separate_value'] ) {
283 236 foreach ( $opts as $opt_key => $opt ) {
284 - if ( str_contains( $opt, '|' ) ) {
285 - $vals = explode( '|', $opt );
237 + if ( strpos( $opt, '|' ) !== false ) {
238 + $vals = explode( '|', $opt );
286 239 $opts[ $opt_key ] = array(
287 240 'label' => trim( $vals[0] ),
288 241 'value' => trim( $vals[1] ),
289 242 );
@@ -293,11 +246,10 @@
293 246 }
294 247 }
295 248
296 249 // Keep other options after bulk update.
297 - if ( ! empty( $field['field_options']['other'] ) ) {
250 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
298 251 $other_array = array();
299 -
300 252 foreach ( $field['options'] as $opt_key => $opt ) {
301 253 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
302 254 $other_array[ $opt_key ] = $opt;
303 255 }
@@ -302,10 +254,9 @@
302 254 $other_array[ $opt_key ] = $opt;
303 255 }
304 256 unset( $opt_key, $opt );
305 257 }
306 -
307 - if ( $other_array ) {
258 + if ( ! empty( $other_array ) ) {
308 259 $opts = array_merge( $opts, $other_array );
309 260 }
310 261 }
311 262
@@ -319,10 +270,8 @@
319 270 /**
320 271 * @since 4.0
321 272 *
322 273 * @param array $atts - Includes field array, field_obj, display array, values array.
323 - *
324 - * @return void
325 274 */
326 275 public static function load_single_field_settings( $atts ) {
327 276 $field = $atts['field'];
328 277 $field_obj = $atts['field_obj'];
@@ -337,19 +286,19 @@
337 286 if ( ! isset( $field['read_only'] ) ) {
338 287 $field['read_only'] = false;
339 288 }
340 289
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'] );
290 + $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
291 + $pro_field_selection = FrmField::pro_field_selection();
292 + $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
293 + $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
294 + $frm_settings = FrmAppHelper::get_settings();
346 295
347 296 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
348 297 // Add fallback for an add-on field type that has been deactivated.
349 298 $all_field_types[ $field['type'] ] = array(
350 299 'name' => ucfirst( $field['type'] ),
351 - 'icon' => 'frmfont frm_pencil_icon',
300 + 'icon' => 'frm_icon_font frm_pencil_icon',
352 301 );
353 302 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
354 303 // Fallback for fields added in a more basic way.
355 304 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -355,9 +304,8 @@
355 304 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
356 305 }
357 306
358 307 $type_name = $all_field_types[ $field['type'] ]['name'];
359 -
360 308 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
361 309 $type_name = $all_field_types['divider|repeat']['name'];
362 310 }
363 311
@@ -368,147 +316,61 @@
368 316 if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
369 317 $field['placeholder'] = implode( ', ', $field['placeholder'] );
370 318 }
371 319
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 320 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
444 321 }
445 322
446 323 /**
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 324 * Get the list of default value types that can be toggled in the builder.
460 325 *
461 326 * @since 4.0
462 - *
463 - * @param array $field
464 - * @param array $atts
465 - *
466 327 * @return array
467 328 */
468 329 private static function default_value_types( $field, $atts ) {
469 330 $types = array(
470 - 'default_value' => array(
331 + 'default_value' => array(
471 332 'class' => '',
472 - 'icon' => 'frmfont frm_text2_icon',
473 - 'title' => __( 'Default Value', 'formidable' ),
333 + 'icon' => 'frm_icon_font frm_text2_icon',
334 + 'title' => __( 'Default Value (Text)', 'formidable' ),
474 335 'data' => array(
475 336 'frmshow' => '#default-value-for-',
476 337 ),
477 338 ),
478 - 'calc' => array(
479 - 'class' => 'frm_show_upgrade frm_noallow',
480 - 'title' => __( 'Calculate Value', 'formidable' ),
481 - 'icon' => 'frmfont frm_calculator_icon',
482 - 'data' => array(
339 + 'calc' => array(
340 + 'class' => 'frm_show_upgrade frm_noallow',
341 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
342 + 'icon' => 'frm_icon_font frm_calculator_icon',
343 + 'data' => array(
483 344 'medium' => 'calculations',
484 345 'upgrade' => __( 'Calculator forms', 'formidable' ),
485 346 ),
486 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
487 347 ),
488 348 'get_values_field' => array(
489 - 'class' => 'frm_show_upgrade frm_noallow',
490 - 'title' => __( 'Lookup', 'formidable' ),
491 - 'icon' => 'frmfont frm_search_icon',
492 - 'data' => array(
349 + 'class' => 'frm_show_upgrade frm_noallow',
350 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
351 + 'icon' => 'frm_icon_font frm_search_icon',
352 + 'data' => array(
493 353 'medium' => 'lookup',
494 354 'upgrade' => __( 'Lookup fields', 'formidable' ),
495 355 ),
496 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
497 356 ),
498 357 );
499 358
500 359 $types = apply_filters( 'frm_default_value_types', $types, $atts );
501 360
361 + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
362 + // Prevent settings from showing in 2 spots.
363 + unset( $types['calc'], $types['get_values_field'] );
364 + }
365 +
502 366 // Set active class.
503 367 $settings = array_keys( $types );
504 368 $active = 'default_value';
505 369
506 - if ( FrmAppHelper::pro_is_connected() ) {
507 - foreach ( $settings as $type ) {
508 - if ( ! empty( $field[ $type ] ) ) {
509 - $active = $type;
510 - }
370 + foreach ( $settings as $type ) {
371 + if ( ! empty( $field[ $type ] ) ) {
372 + $active = $type;
511 373 }
512 374 }
513 375
514 376 $types[ $active ]['class'] .= ' current';
@@ -516,13 +378,8 @@
516 378
517 379 return $types;
518 380 }
519 381
520 - /**
521 - * @param string $type
522 - *
523 - * @return string
524 - */
525 382 public static function change_type( $type ) {
526 383 $type_switch = array(
527 384 'scale' => 'radio',
528 385 'star' => 'radio',
@@ -530,9 +387,8 @@
530 387 'rte' => 'textarea',
531 388 'website' => 'url',
532 389 'image' => 'url',
533 390 );
534 -
535 391 if ( isset( $type_switch[ $type ] ) ) {
536 392 $type = $type_switch[ $type ];
537 393 }
538 394
@@ -538,24 +394,26 @@
538 394
539 395 $pro_fields = FrmField::pro_field_selection();
540 396 // We want to keep credit_card types as credit card types for Stripe Lite.
541 397 // The credit_card key is set for backward compatibility.
542 - FrmField::remove_moved_field_types_from_pro( $pro_fields );
398 + unset( $pro_fields['credit_card'] );
543 399
544 - return array_key_exists( $type, $pro_fields ) ? 'text' : $type;
400 + if ( array_key_exists( $type, $pro_fields ) ) {
401 + $type = 'text';
402 + }
403 +
404 + return $type;
545 405 }
546 406
547 407 /**
548 - * @param array $settings
549 - * @param FrmFieldType|null $field_info
408 + * @param array $settings
409 + * @param object $field_info
550 410 *
551 411 * @return array
552 412 */
553 413 public static function display_field_options( $settings, $field_info = null ) {
554 414 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.
415 + $settings = $field_info->display_field_settings();
558 416 $settings['field_data'] = $field_info->field;
559 417 }
560 418
561 419 return apply_filters( 'frm_display_field_options', $settings );
@@ -565,32 +423,14 @@
565 423 * Display the format option
566 424 *
567 425 * @since 3.0
568 426 *
569 - * @param array $field Field data.
570 - * @param bool $is_hidden Whether the format option should be hidden.
571 - *
572 - * @return void
427 + * @param array $field
573 428 */
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';
429 + public static function show_format_option( $field ) {
430 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
585 431 }
586 432
587 - /**
588 - * @param array $field
589 - * @param bool $echo
590 - *
591 - * @return string
592 - */
593 433 public static function input_html( $field, $echo = true ) {
594 434 $class = array();
595 435 self::add_input_classes( $field, $class );
596 436
@@ -605,9 +445,8 @@
605 445 FrmFormsHelper::add_html_attr( $class, 'class', $add_html );
606 446
607 447 self::add_shortcodes_to_html( $field, $add_html );
608 448 self::add_pattern_attribute( $field, $add_html );
609 - self::add_currency_field_attributes( $field, $add_html );
610 449
611 450 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
612 451 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
613 452
@@ -617,20 +456,14 @@
617 456
618 457 return $add_html;
619 458 }
620 459
621 - /**
622 - * @param array $field
623 - * @param array $class
624 - *
625 - * @return void
626 - */
627 460 private static function add_input_classes( $field, array &$class ) {
628 - if ( ! empty( $field['input_class'] ) ) {
461 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
629 462 $class[] = $field['input_class'];
630 463 }
631 464
632 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
465 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
633 466 return;
634 467 }
635 468
636 469 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -637,14 +470,8 @@
637 470 $class[] = 'auto_width';
638 471 }
639 472 }
640 473
641 - /**
642 - * @param array $field
643 - * @param array $add_html
644 - *
645 - * @return void
646 - */
647 474 private static function add_html_size( $field, array &$add_html ) {
648 475 $size_fields = array(
649 476 'select',
650 477 'data',
@@ -653,9 +480,9 @@
653 480 'file',
654 481 'lookup',
655 482 );
656 483
657 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
484 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
658 485 return;
659 486 }
660 487
661 488 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -672,14 +499,8 @@
672 499
673 500 self::add_html_cols( $field, $add_html );
674 501 }
675 502
676 - /**
677 - * @param array $field
678 - * @param array $add_html
679 - *
680 - * @return void
681 - */
682 503 private static function add_html_cols( $field, array &$add_html ) {
683 504 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
684 505 return;
685 506 }
@@ -691,9 +512,9 @@
691 512 'rem' => 0.444,
692 513 'em' => 0.544,
693 514 );
694 515
695 - // Include "col" for valid html
516 + // include "col" for valid html
696 517 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
697 518
698 519 if ( ! isset( $calc[ $unit ] ) ) {
699 520 return;
@@ -698,18 +519,13 @@
698 519 if ( ! isset( $calc[ $unit ] ) ) {
699 520 return;
700 521 }
701 522
702 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
523 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
524 +
703 525 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
704 526 }
705 527
706 - /**
707 - * @param array $field
708 - * @param array $add_html
709 - *
710 - * @return void
711 - */
712 528 private static function add_html_length( $field, array &$add_html ) {
713 529 // Check for max setting and if this field accepts maxlength.
714 530 $fields = array(
715 531 'textarea',
@@ -717,9 +533,9 @@
717 533 'hidden',
718 534 'file',
719 535 );
720 536
721 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
537 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
722 538 return;
723 539 }
724 540
725 541 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -729,17 +545,9 @@
729 545
730 546 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
731 547 }
732 548
733 - /**
734 - * @param array $field
735 - * @param array $add_html
736 - * @param array $class
737 - *
738 - * @return void
739 - */
740 549 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
741 - // phpcs:ignore Universal.Operators.StrictComparisons
742 550 if ( $field['default_value'] != '' ) {
743 551 if ( is_array( $field['default_value'] ) ) {
744 552 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
745 553 } else {
@@ -747,16 +555,26 @@
747 555 }
748 556 }
749 557
750 558 $field['placeholder'] = self::prepare_placeholder( $field );
751 -
752 - // phpcs:ignore Universal.Operators.StrictComparisons
753 559 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
754 - // Don't include a json placeholder
560 + // don't include a json placeholder
755 561 return;
756 562 }
757 563
758 - self::add_placeholder_to_input( $field, $add_html );
564 + $frm_settings = FrmAppHelper::get_settings();
565 +
566 + if ( $frm_settings->use_html ) {
567 + self::add_placeholder_to_input( $field, $add_html );
568 + } else {
569 + self::add_frmval_to_input( $field, $add_html );
570 +
571 + $class[] = 'frm_toggle_default';
572 +
573 + if ( $field['value'] == $field['placeholder'] ) {
574 + $class[] = 'frm_default';
575 + }
576 + }
759 577 }
760 578
761 579 /**
762 580 * Prepares field placeholder.
@@ -763,13 +581,14 @@
763 581 *
764 582 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
765 583 *
766 584 * @param array $field Field array.
767 - *
768 585 * @return string
769 586 */
770 587 private static function prepare_placeholder( $field ) {
771 - return $field['placeholder'] ?? '';
588 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
589 +
590 + return $placeholder;
772 591 }
773 592
774 593 /**
775 594 * If the label position is "inside",
@@ -790,39 +609,22 @@
790 609 * Maybe add a blank placeholder option before any options
791 610 * in a dropdown.
792 611 *
793 612 * @since 4.04
794 - *
795 - * @param array|object $field
796 - *
797 613 * @return bool True if placeholder was added.
798 614 */
799 615 public static function add_placeholder_to_select( $field ) {
800 616 $placeholder = FrmField::get_option( $field, 'placeholder' );
801 -
802 - if ( ! $placeholder ) {
617 + if ( empty( $placeholder ) ) {
803 618 $placeholder = self::get_default_value_from_name( $field );
804 619 }
805 620
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 621 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 );
622 + ?>
623 + <option class="frm-select-placeholder" value="">
624 + <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
625 + </option>
626 + <?php
825 627 return true;
826 628 }
827 629
828 630 return false;
@@ -828,14 +630,12 @@
828 630 return false;
829 631 }
830 632
831 633 /**
832 - * Use HTML5 placeholder with js fallback.
634 + * Use HMTL5 placeholder with js fallback
833 635 *
834 636 * @param array $field
835 637 * @param array $add_html
836 - *
837 - * @return void
838 638 */
839 639 private static function add_placeholder_to_input( $field, &$add_html ) {
840 640 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
841 641 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -841,16 +641,9 @@
841 641 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
842 642 }
843 643 }
844 644
845 - /**
846 - * @param array $field
847 - * @param array $add_html
848 - *
849 - * @return void
850 - */
851 645 private static function add_frmval_to_input( $field, &$add_html ) {
852 - // phpcs:ignore Universal.Operators.StrictComparisons
853 646 if ( $field['placeholder'] != '' ) {
854 647 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
855 648
856 649 if ( 'select' === $field['type'] ) {
@@ -857,30 +650,21 @@
857 650 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
858 651 }
859 652 }
860 653
861 - // phpcs:ignore Universal.Operators.StrictComparisons
862 654 if ( $field['default_value'] != '' ) {
863 655 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
864 656 }
865 657 }
866 658
867 - /**
868 - * @param array $field
869 - * @param array $add_html
870 - *
871 - * @return void
872 - */
873 659 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'] ) ) {
660 + if ( FrmField::is_required( $field ) ) {
877 661 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
878 662 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
879 663 self::maybe_add_html_required( $field, $add_html );
880 664 }
881 665
882 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
666 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
883 667 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
884 668 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
885 669 }
886 670
@@ -889,63 +673,24 @@
889 673 }
890 674 }
891 675
892 676 /**
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 677 * @since 5.0.03
927 678 *
928 679 * @param array $field
929 680 * @param array $add_html
930 - *
931 - * @return void
932 681 */
933 682 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
934 683 $form = self::get_form_for_js_validation( $field );
935 -
936 684 if ( false === $form ) {
937 685 return;
938 686 }
939 687
940 688 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
941 -
942 - if ( false === $error_body ) {
943 - return;
689 + if ( false !== $error_body ) {
690 + $error_body = urlencode( $error_body );
691 + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
944 692 }
945 -
946 - $error_body = urlencode( $error_body );
947 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
948 693 }
949 694
950 695 /**
951 696 * @since 5.0.03
@@ -950,24 +695,20 @@
950 695 /**
951 696 * @since 5.0.03
952 697 *
953 698 * @param array $field
954 - *
955 - * @return false|stdClass false if there is no form object found with JS validation active.
699 + * @return stdClass|false false if there is no form object found with JS validation active.
956 700 */
957 701 private static function get_form_for_js_validation( $field ) {
958 702 global $frm_vars;
959 -
960 703 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
961 704 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
962 705 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
963 706 }
964 -
965 707 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
966 708 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
967 709 }
968 710 }
969 -
970 711 return false;
971 712 }
972 713
973 714 /**
@@ -973,10 +714,9 @@
973 714 /**
974 715 * @param stdClass $form
975 716 * @param array $field
976 717 * @param array $errors
977 - *
978 - * @return false|string
718 + * @return string|false
979 719 */
980 720 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
981 721 if ( empty( $field['custom_html'] ) ) {
982 722 return false;
@@ -983,16 +723,15 @@
983 723 }
984 724
985 725 $custom_html = $field['custom_html'];
986 726 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
987 - $start = strpos( $custom_html, '[if error]' );
988 727
728 + $start = strpos( $custom_html, '[if error]' );
989 729 if ( false === $start ) {
990 730 return false;
991 731 }
992 732
993 733 $end = strpos( $custom_html, '[/if error]' );
994 -
995 734 if ( false === $end || $end < $start ) {
996 735 return false;
997 736 }
998 737
@@ -1003,9 +742,13 @@
1003 742 '<div class="frm_error">[error]</div>',
1004 743 '<div class="frm_error" role="alert">[error]</div>',
1005 744 );
1006 745
1007 - return in_array( $error_body, $default_html, true ) ? false : $error_body;
746 + if ( in_array( $error_body, $default_html, true ) ) {
747 + return false;
748 + }
749 +
750 + return $error_body;
1008 751 }
1009 752
1010 753 /**
1011 754 * If 'required' is added to a conditionally hidden field, the form won't
@@ -1012,16 +755,12 @@
1012 755 * submit in many browsers. Check to make sure the javascript to conditionally
1013 756 * remove it is present if needed.
1014 757 *
1015 758 * @since 3.06.01
1016 - *
1017 759 * @param array $field
1018 760 * @param array $add_html
1019 - *
1020 - * @return void
1021 761 */
1022 762 private static function maybe_add_html_required( $field, array &$add_html ) {
1023 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1024 763 $excluded_field_types =
1025 764 FrmField::is_radio( $field ) ||
1026 765 FrmField::is_checkbox( $field ) ||
1027 766 FrmField::is_field_type( $field, 'file' ) ||
@@ -1026,23 +765,19 @@
1026 765 FrmField::is_checkbox( $field ) ||
1027 766 FrmField::is_field_type( $field, 'file' ) ||
1028 767 FrmField::is_field_type( $field, 'nps' ) ||
1029 768 FrmField::is_field_type( $field, 'scale' );
1030 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1031 769
1032 770 if ( $excluded_field_types ) {
1033 771 return;
1034 772 }
1035 773
1036 - $add_html['aria-required'] = 'aria-required="true"';
774 + $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
775 + if ( $include_html ) {
776 + $add_html['aria-required'] = 'aria-required="true"';
777 + }
1037 778 }
1038 779
1039 - /**
1040 - * @param array $field
1041 - * @param array $add_html
1042 - *
1043 - * @return void
1044 - */
1045 780 private static function add_shortcodes_to_html( $field, array &$add_html ) {
1046 781 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
1047 782 return;
1048 783 }
@@ -1051,25 +786,13 @@
1051 786 unset( $field['shortcodes']['autocomplete'] );
1052 787 }
1053 788
1054 789 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 ) ) {
790 + if ( 'opt' === $k ) {
1068 791 continue;
1069 792 }
1070 793
1071 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
794 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1072 795 $add_html[] = $v;
1073 796 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1074 797 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1075 798 } else {
@@ -1076,128 +799,129 @@
1076 799 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1077 800 }
1078 801
1079 802 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 803 }
1096 - return FrmAppHelper::input_key_is_safe( $key );
1097 804 }
1098 805
1099 806 /**
1100 - * Add pattern attribute.
807 + * Add pattern attribute
1101 808 *
1102 809 * @since 3.0
1103 810 *
1104 811 * @param array $field
1105 812 * @param array $add_html
1106 - *
1107 - * @return void
1108 813 */
1109 814 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 );
815 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1112 816 $format_field = FrmField::is_field_type( $field, 'text' );
1113 817
1114 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1115 - return;
1116 - }
818 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
819 + $frm_settings = FrmAppHelper::get_settings();
1117 820
1118 - $format = FrmEntryValidate::phone_format( $field );
1119 - $format = substr( $format, 2, - 1 );
821 + if ( $frm_settings->use_html ) {
822 + $format = FrmEntryValidate::phone_format( $field );
823 + $format = substr( $format, 2, - 1 );
1120 824
1121 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
825 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
826 + }
827 + }
1122 828 }
1123 829
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;
830 + public static function check_value( $opt, $opt_key, $field ) {
831 + if ( is_array( $opt ) ) {
832 + if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
833 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
834 + } else {
835 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
836 + }
1138 837 }
1139 838
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 );
839 + return $opt;
840 + }
1149 841
1150 - $add_html['data-frmprice'] = 'data-frmprice="' . esc_attr( $price ) . '"';
842 + public static function check_label( $opt ) {
843 + if ( is_array( $opt ) ) {
844 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1151 845 }
846 +
847 + return $opt;
1152 848 }
1153 849
1154 850 /**
1155 - * @param array $field
851 + * @deprecated 4.0
1156 852 */
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'];
853 + public static function update_ajax_option() {
854 + _deprecated_function( __METHOD__, '4.0' );
855 + FrmAppHelper::permission_check( 'frm_edit_forms' );
856 + check_ajax_referer( 'frm_ajax', 'nonce' );
857 +
858 + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
859 + if ( ! $field_id ) {
860 + wp_die();
1165 861 }
1166 862
1167 - $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
863 + $field = FrmField::getOne( $field_id );
1168 864
1169 - if ( method_exists( $field_obj, 'get_posted_price' ) ) {
1170 - return $field_obj->get_posted_price( $value );
865 + if ( isset( $_POST['separate_value'] ) ) {
866 + $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
867 +
868 + $field->field_options['separate_value'] = $new_val;
869 + unset( $new_val );
1171 870 }
1172 871
1173 - return $value;
872 + FrmField::update(
873 + $field_id,
874 + array(
875 + 'field_options' => $field->field_options,
876 + 'form_id' => $field->form_id,
877 + )
878 + );
879 + wp_die();
1174 880 }
1175 881
1176 882 /**
1177 - * @param mixed $opt
1178 - * @param mixed $opt_key
1179 - * @param array|object $field
883 + * @deprecated 4.0
884 + */
885 + public static function import_choices() {
886 + _deprecated_function( __METHOD__, '4.0' );
887 + wp_die();
888 + }
889 +
890 + /**
891 + * Add Single Option or Other Option.
1180 892 *
1181 - * @return mixed
893 + * @deprecated 4.0 Moved to Pro for Other option only.
1182 894 */
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 - }
895 + public static function add_option() {
896 + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
897 + }
1191 898
1192 - return $opt;
899 + /**
900 + * @deprecated 4.0
901 + */
902 + public static function update_order() {
903 + FrmDeprecated::update_order();
1193 904 }
1194 905
1195 906 /**
1196 - * @param mixed $opt
907 + * @deprecated 3.0
908 + * @codeCoverageIgnore
909 + */
910 + public static function edit_name( $field = 'name', $id = '' ) {
911 + FrmDeprecated::edit_name( $field, $id );
912 + }
913 +
914 + /**
915 + * @deprecated 3.0
916 + * @codeCoverageIgnore
1197 917 *
1198 - * @return mixed
918 + * @param int $field_id
919 + * @param array $values
920 + * @param int $form_id
921 + *
922 + * @return array
1199 923 */
1200 - public static function check_label( $opt ) {
1201 - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt;
924 + public static function include_single_field( $field_id, $values, $form_id = 0 ) {
925 + return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
1202 926 }
1203 927 }