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