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