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