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