PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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 +214 -348 6.276.8 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,9 +26,8 @@
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 31 // this field may have already been loaded
41 32 continue;
42 33 }
@@ -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,15 +56,14 @@
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 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
@@ -81,21 +72,16 @@
81 72
82 73 /**
83 74 * Set up and create a new field
84 75 *
85 - * @param string $field_type
86 - * @param int $form_id
87 - * @param array $field_options
76 + * @param string $field_type
77 + * @param integer $form_id
88 78 *
89 - * @return array|false
79 + * @return array|bool
90 80 */
91 - public static function include_new_field( $field_type, $form_id, $field_options = array() ) {
81 + public static function include_new_field( $field_type, $form_id ) {
92 82 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
93 83
94 - if ( $field_options ) {
95 - $field_values['field_options'] = array_merge( $field_values['field_options'], $field_options );
96 - }
97 -
98 84 // When a new field is added to the form, flag it as draft and hide it from the front-end.
99 85 $field_values['field_options']['draft'] = 1;
100 86
101 87 /**
@@ -107,15 +93,15 @@
107 93 if ( ! $field_id ) {
108 94 return false;
109 95 }
110 96
111 - $field = self::get_field_array_from_id( $field_id );
97 + $field = self::get_field_array_from_id( $field_id );
98 +
112 99 $values = array();
113 -
114 100 if ( FrmAppHelper::pro_is_installed() ) {
115 101 $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 102
103 + $parent_form_id = FrmDb::get_var( 'frm_forms', array( 'id' => $form_id ), 'parent_form_id' );
118 104 if ( $parent_form_id ) {
119 105 $field['parent_form_id'] = $parent_form_id;
120 106 }
121 107 }
@@ -128,10 +114,11 @@
128 114 public static function duplicate() {
129 115 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 116 check_ajax_referer( 'frm_ajax', 'nonce' );
131 117
132 - $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
133 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
118 + $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
119 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
120 +
134 121 $new_field = FrmField::duplicate_single_field( $field_id, $form_id );
135 122
136 123 if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) {
137 124 self::load_single_field( $new_field['field_id'], $new_field['values'] );
@@ -148,8 +135,9 @@
148 135 * @return array
149 136 */
150 137 public static function get_field_array_from_id( $field_id ) {
151 138 $field = FrmField::getOne( $field_id );
139 +
152 140 return FrmFieldsHelper::setup_edit_vars( $field );
153 141 }
154 142
155 143 /**
@@ -154,13 +142,11 @@
154 142
155 143 /**
156 144 * @since 3.0
157 145 *
158 - * @param array|int|object $field_object
146 + * @param int|array|object $field_object
159 147 * @param array $values
160 148 * @param int $form_id
161 - *
162 - * @return void
163 149 */
164 150 public static function load_single_field( $field_object, $values, $form_id = 0 ) {
165 151 global $frm_vars;
166 152 $frm_vars['is_admin'] = true;
@@ -171,49 +157,33 @@
171 157 $field = $field_object;
172 158 $field_object = FrmField::getOne( $field['id'] );
173 159 }
174 160
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 );
161 + $field_obj = FrmFieldFactory::get_field_factory( $field_object );
162 + $display = self::display_field_options( array(), $field_obj );
179 163
164 + $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
165 + $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) );
166 +
180 167 if ( $ajax_loading && $ajax_this_field ) {
181 168 $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 - }
169 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' );
170 + } else {
171 + if ( ! isset( $field ) && is_object( $field_object ) ) {
172 + $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
185 173
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 - }
174 + $field = FrmFieldsHelper::setup_edit_vars( $field_object );
175 + }
190 176
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 );
177 + $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
178 + $li_classes .= ' ui-state-default widgets-holder-wrap';
201 179
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';
180 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' );
181 + }
206 182 }
207 183
208 184 /**
209 185 * @since 3.0
210 - *
211 - * @param array $field
212 - * @param array $display
213 - * @param FrmFieldType $field_info
214 - *
215 - * @return string
216 186 */
217 187 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
218 188 $li_classes = $field_info->form_builder_classes( $display['type'] );
219 189 $li_classes .= ' frm_form_field frmstart ';
@@ -250,40 +220,27 @@
250 220 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
251 221 return;
252 222 }
253 223
254 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
255 - $field = FrmField::getOne( $field_id );
256 - $bulk_edit_types = array( 'radio', 'checkbox', 'select' );
224 + $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
225 + $field = FrmField::getOne( $field_id );
257 226
258 - /**
259 - * Filter to add new fields that will support import_options/Bulk Edit Options.
260 - *
261 - * @since 6.8.4
262 - *
263 - * @param array $bulk_edit_types
264 - *
265 - * @return array
266 - */
267 - $bulk_edit_types = apply_filters( 'frm_bulk_edit_field_types', $bulk_edit_types );
268 -
269 - if ( ! in_array( $field->type, $bulk_edit_types, true ) ) {
227 + if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
270 228 return;
271 229 }
272 230
273 231 $field = FrmFieldsHelper::setup_edit_vars( $field );
232 + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
233 + $opts = explode( "\n", rtrim( $opts, "\n" ) );
234 + $opts = array_map( 'trim', $opts );
274 235
275 - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
276 - $opts = explode( "\n", rtrim( $opts, "\n" ) );
277 - $opts = array_map( 'trim', $opts );
236 + $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
237 + $field['separate_value'] = ( $separate === 'true' );
278 238
279 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
280 - $field['separate_value'] = $separate === 'true';
281 -
282 239 if ( $field['separate_value'] ) {
283 240 foreach ( $opts as $opt_key => $opt ) {
284 - if ( str_contains( $opt, '|' ) ) {
285 - $vals = explode( '|', $opt );
241 + if ( strpos( $opt, '|' ) !== false ) {
242 + $vals = explode( '|', $opt );
286 243 $opts[ $opt_key ] = array(
287 244 'label' => trim( $vals[0] ),
288 245 'value' => trim( $vals[1] ),
289 246 );
@@ -293,12 +250,10 @@
293 250 }
294 251 }
295 252
296 253 // Keep other options after bulk update.
297 - // phpcs:ignore Universal.Operators.StrictComparisons
298 - if ( ! empty( $field['field_options']['other'] ) ) {
254 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
299 255 $other_array = array();
300 -
301 256 foreach ( $field['options'] as $opt_key => $opt ) {
302 257 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
303 258 $other_array[ $opt_key ] = $opt;
304 259 }
@@ -303,10 +258,9 @@
303 258 $other_array[ $opt_key ] = $opt;
304 259 }
305 260 unset( $opt_key, $opt );
306 261 }
307 -
308 - if ( $other_array ) {
262 + if ( ! empty( $other_array ) ) {
309 263 $opts = array_merge( $opts, $other_array );
310 264 }
311 265 }
312 266
@@ -320,10 +274,8 @@
320 274 /**
321 275 * @since 4.0
322 276 *
323 277 * @param array $atts - Includes field array, field_obj, display array, values array.
324 - *
325 - * @return void
326 278 */
327 279 public static function load_single_field_settings( $atts ) {
328 280 $field = $atts['field'];
329 281 $field_obj = $atts['field_obj'];
@@ -338,19 +290,19 @@
338 290 if ( ! isset( $field['read_only'] ) ) {
339 291 $field['read_only'] = false;
340 292 }
341 293
342 - $field_selection_data = self::maybe_define_field_selection_data();
343 - $all_field_types = $field_selection_data->all_field_types;
344 - $disabled_fields = $field_selection_data->disabled_fields;
345 - $frm_settings = FrmAppHelper::get_settings();
346 - $field_types = FrmFieldTypeOptionData::get_field_types( $field['type'] );
294 + $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
295 + $pro_field_selection = FrmField::pro_field_selection();
296 + $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
297 + $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
298 + $frm_settings = FrmAppHelper::get_settings();
347 299
348 300 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
349 301 // Add fallback for an add-on field type that has been deactivated.
350 302 $all_field_types[ $field['type'] ] = array(
351 303 'name' => ucfirst( $field['type'] ),
352 - 'icon' => 'frmfont frm_pencil_icon',
304 + 'icon' => 'frm_icon_font frm_pencil_icon',
353 305 );
354 306 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
355 307 // Fallback for fields added in a more basic way.
356 308 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -356,9 +308,8 @@
356 308 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
357 309 }
358 310
359 311 $type_name = $all_field_types[ $field['type'] ]['name'];
360 -
361 312 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
362 313 $type_name = $all_field_types['divider|repeat']['name'];
363 314 }
364 315
@@ -373,72 +324,57 @@
373 324 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
374 325 }
375 326
376 327 /**
377 - * @since 6.9.1
378 - *
379 - * @return FrmFieldSelectionData
380 - */
381 - private static function maybe_define_field_selection_data() {
382 - if ( ! isset( self::$field_selection_data ) ) {
383 - self::$field_selection_data = new FrmFieldSelectionData();
384 - }
385 - return self::$field_selection_data;
386 - }
387 -
388 - /**
389 328 * Get the list of default value types that can be toggled in the builder.
390 329 *
391 330 * @since 4.0
392 - *
393 - * @param array $field
394 - * @param array $atts
395 - *
396 331 * @return array
397 332 */
398 333 private static function default_value_types( $field, $atts ) {
399 334 $types = array(
400 - 'default_value' => array(
335 + 'default_value' => array(
401 336 'class' => '',
402 - 'icon' => 'frmfont frm_text2_icon',
403 - 'title' => __( 'Default Value', 'formidable' ),
337 + 'icon' => 'frm_icon_font frm_text2_icon',
338 + 'title' => __( 'Default Value (Text)', 'formidable' ),
404 339 'data' => array(
405 340 'frmshow' => '#default-value-for-',
406 341 ),
407 342 ),
408 - 'calc' => array(
409 - 'class' => 'frm_show_upgrade frm_noallow',
410 - 'title' => __( 'Calculate Value', 'formidable' ),
411 - 'icon' => 'frmfont frm_calculator_icon',
412 - 'data' => array(
343 + 'calc' => array(
344 + 'class' => 'frm_show_upgrade frm_noallow',
345 + 'title' => __( 'Default Value (Calculation)', 'formidable' ),
346 + 'icon' => 'frm_icon_font frm_calculator_icon',
347 + 'data' => array(
413 348 'medium' => 'calculations',
414 349 'upgrade' => __( 'Calculator forms', 'formidable' ),
415 350 ),
416 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
417 351 ),
418 352 'get_values_field' => array(
419 - 'class' => 'frm_show_upgrade frm_noallow',
420 - 'title' => __( 'Lookup', 'formidable' ),
421 - 'icon' => 'frmfont frm_search_icon',
422 - 'data' => array(
353 + 'class' => 'frm_show_upgrade frm_noallow',
354 + 'title' => __( 'Default Value (Lookup)', 'formidable' ),
355 + 'icon' => 'frm_icon_font frm_search_icon',
356 + 'data' => array(
423 357 'medium' => 'lookup',
424 358 'upgrade' => __( 'Lookup fields', 'formidable' ),
425 359 ),
426 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
427 360 ),
428 361 );
429 362
430 363 $types = apply_filters( 'frm_default_value_types', $types, $atts );
431 364
365 + if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
366 + // Prevent settings from showing in 2 spots.
367 + unset( $types['calc'], $types['get_values_field'] );
368 + }
369 +
432 370 // Set active class.
433 371 $settings = array_keys( $types );
434 372 $active = 'default_value';
435 373
436 - if ( FrmAppHelper::pro_is_connected() ) {
437 - foreach ( $settings as $type ) {
438 - if ( ! empty( $field[ $type ] ) ) {
439 - $active = $type;
440 - }
374 + foreach ( $settings as $type ) {
375 + if ( ! empty( $field[ $type ] ) ) {
376 + $active = $type;
441 377 }
442 378 }
443 379
444 380 $types[ $active ]['class'] .= ' current';
@@ -446,13 +382,8 @@
446 382
447 383 return $types;
448 384 }
449 385
450 - /**
451 - * @param string $type
452 - *
453 - * @return string
454 - */
455 386 public static function change_type( $type ) {
456 387 $type_switch = array(
457 388 'scale' => 'radio',
458 389 'star' => 'radio',
@@ -460,9 +391,8 @@
460 391 'rte' => 'textarea',
461 392 'website' => 'url',
462 393 'image' => 'url',
463 394 );
464 -
465 395 if ( isset( $type_switch[ $type ] ) ) {
466 396 $type = $type_switch[ $type ];
467 397 }
468 398
@@ -478,18 +408,16 @@
478 408 return $type;
479 409 }
480 410
481 411 /**
482 - * @param array $settings
483 - * @param FrmFieldType|null $field_info
412 + * @param array $settings
413 + * @param object $field_info
484 414 *
485 415 * @return array
486 416 */
487 417 public static function display_field_options( $settings, $field_info = null ) {
488 418 if ( $field_info ) {
489 - $settings = $field_info->display_field_settings();
490 -
491 - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
419 + $settings = $field_info->display_field_settings();
492 420 $settings['field_data'] = $field_info->field;
493 421 }
494 422
495 423 return apply_filters( 'frm_display_field_options', $settings );
@@ -499,32 +427,14 @@
499 427 * Display the format option
500 428 *
501 429 * @since 3.0
502 430 *
503 - * @param array $field Field data.
504 - * @param bool $is_hidden Whether the format option should be hidden.
505 - *
506 - * @return void
431 + * @param array $field
507 432 */
508 - public static function show_format_option( $field, $is_hidden = false ) {
509 - $attributes = array(
510 - 'class' => 'frm-has-modal',
511 - 'id' => 'frm-field-format-custom-' . $field['id'],
512 - );
513 -
514 - if ( $is_hidden ) {
515 - $attributes['class'] .= ' frm_hidden';
516 - }
517 -
518 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php';
433 + public static function show_format_option( $field ) {
434 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
519 435 }
520 436
521 - /**
522 - * @param array $field
523 - * @param bool $echo
524 - *
525 - * @return string
526 - */
527 437 public static function input_html( $field, $echo = true ) {
528 438 $class = array();
529 439 self::add_input_classes( $field, $class );
530 440
@@ -550,20 +460,14 @@
550 460
551 461 return $add_html;
552 462 }
553 463
554 - /**
555 - * @param array $field
556 - * @param array $class
557 - *
558 - * @return void
559 - */
560 464 private static function add_input_classes( $field, array &$class ) {
561 - if ( ! empty( $field['input_class'] ) ) {
465 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
562 466 $class[] = $field['input_class'];
563 467 }
564 468
565 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
469 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
566 470 return;
567 471 }
568 472
569 473 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -570,14 +474,8 @@
570 474 $class[] = 'auto_width';
571 475 }
572 476 }
573 477
574 - /**
575 - * @param array $field
576 - * @param array $add_html
577 - *
578 - * @return void
579 - */
580 478 private static function add_html_size( $field, array &$add_html ) {
581 479 $size_fields = array(
582 480 'select',
583 481 'data',
@@ -586,9 +484,9 @@
586 484 'file',
587 485 'lookup',
588 486 );
589 487
590 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields, true ) ) {
488 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
591 489 return;
592 490 }
593 491
594 492 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -605,14 +503,8 @@
605 503
606 504 self::add_html_cols( $field, $add_html );
607 505 }
608 506
609 - /**
610 - * @param array $field
611 - * @param array $add_html
612 - *
613 - * @return void
614 - */
615 507 private static function add_html_cols( $field, array &$add_html ) {
616 508 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
617 509 return;
618 510 }
@@ -631,18 +523,13 @@
631 523 if ( ! isset( $calc[ $unit ] ) ) {
632 524 return;
633 525 }
634 526
635 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
527 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
528 +
636 529 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
637 530 }
638 531
639 - /**
640 - * @param array $field
641 - * @param array $add_html
642 - *
643 - * @return void
644 - */
645 532 private static function add_html_length( $field, array &$add_html ) {
646 533 // Check for max setting and if this field accepts maxlength.
647 534 $fields = array(
648 535 'textarea',
@@ -650,9 +537,9 @@
650 537 'hidden',
651 538 'file',
652 539 );
653 540
654 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields, true ) ) {
541 + if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
655 542 return;
656 543 }
657 544
658 545 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -662,17 +549,9 @@
662 549
663 550 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
664 551 }
665 552
666 - /**
667 - * @param array $field
668 - * @param array $add_html
669 - * @param array $class
670 - *
671 - * @return void
672 - */
673 553 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
674 - // phpcs:ignore Universal.Operators.StrictComparisons
675 554 if ( $field['default_value'] != '' ) {
676 555 if ( is_array( $field['default_value'] ) ) {
677 556 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
678 557 } else {
@@ -680,16 +559,26 @@
680 559 }
681 560 }
682 561
683 562 $field['placeholder'] = self::prepare_placeholder( $field );
684 -
685 - // phpcs:ignore Universal.Operators.StrictComparisons
686 563 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
687 564 // don't include a json placeholder
688 565 return;
689 566 }
690 567
691 - self::add_placeholder_to_input( $field, $add_html );
568 + $frm_settings = FrmAppHelper::get_settings();
569 +
570 + if ( $frm_settings->use_html ) {
571 + self::add_placeholder_to_input( $field, $add_html );
572 + } else {
573 + self::add_frmval_to_input( $field, $add_html );
574 +
575 + $class[] = 'frm_toggle_default';
576 +
577 + if ( $field['value'] == $field['placeholder'] ) {
578 + $class[] = 'frm_default';
579 + }
580 + }
692 581 }
693 582
694 583 /**
695 584 * Prepares field placeholder.
@@ -696,13 +585,14 @@
696 585 *
697 586 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
698 587 *
699 588 * @param array $field Field array.
700 - *
701 589 * @return string
702 590 */
703 591 private static function prepare_placeholder( $field ) {
704 - return $field['placeholder'] ?? '';
592 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
593 +
594 + return $placeholder;
705 595 }
706 596
707 597 /**
708 598 * If the label position is "inside",
@@ -723,17 +613,13 @@
723 613 * Maybe add a blank placeholder option before any options
724 614 * in a dropdown.
725 615 *
726 616 * @since 4.04
727 - *
728 - * @param array|object $field
729 - *
730 617 * @return bool True if placeholder was added.
731 618 */
732 619 public static function add_placeholder_to_select( $field ) {
733 620 $placeholder = FrmField::get_option( $field, 'placeholder' );
734 -
735 - if ( ! $placeholder ) {
621 + if ( empty( $placeholder ) ) {
736 622 $placeholder = self::get_default_value_from_name( $field );
737 623 }
738 624
739 625 $use_placeholder = $placeholder;
@@ -740,9 +626,8 @@
740 626 $autocomplete = FrmField::get_option( $field, 'autocom' );
741 627
742 628 if ( $autocomplete ) {
743 629 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
744 -
745 630 if ( $use_chosen ) {
746 631 $use_placeholder = '';
747 632 }
748 633 }
@@ -753,8 +638,13 @@
753 638 'value' => '',
754 639 'data-placeholder' => 'true',
755 640 );
756 641
642 + if ( $autocomplete && empty( $use_chosen ) ) {
643 + // This is required for Slim Select.
644 + $placeholder_attributes['data-placeholder'] = 'true';
645 + }
646 +
757 647 FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
758 648 return true;
759 649 }
760 650
@@ -761,14 +651,12 @@
761 651 return false;
762 652 }
763 653
764 654 /**
765 - * Use HTML5 placeholder with js fallback.
655 + * Use HMTL5 placeholder with js fallback
766 656 *
767 657 * @param array $field
768 658 * @param array $add_html
769 - *
770 - * @return void
771 659 */
772 660 private static function add_placeholder_to_input( $field, &$add_html ) {
773 661 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
774 662 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -774,16 +662,9 @@
774 662 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
775 663 }
776 664 }
777 665
778 - /**
779 - * @param array $field
780 - * @param array $add_html
781 - *
782 - * @return void
783 - */
784 666 private static function add_frmval_to_input( $field, &$add_html ) {
785 - // phpcs:ignore Universal.Operators.StrictComparisons
786 667 if ( $field['placeholder'] != '' ) {
787 668 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
788 669
789 670 if ( 'select' === $field['type'] ) {
@@ -790,30 +671,21 @@
790 671 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
791 672 }
792 673 }
793 674
794 - // phpcs:ignore Universal.Operators.StrictComparisons
795 675 if ( $field['default_value'] != '' ) {
796 676 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
797 677 }
798 678 }
799 679
800 - /**
801 - * @param array $field
802 - * @param array $add_html
803 - *
804 - * @return void
805 - */
806 680 private static function add_validation_messages( $field, array &$add_html ) {
807 - $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
808 -
809 - if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
681 + if ( FrmField::is_required( $field ) ) {
810 682 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
811 683 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
812 684 self::maybe_add_html_required( $field, $add_html );
813 685 }
814 686
815 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
687 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
816 688 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
817 689 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
818 690 }
819 691
@@ -822,57 +694,20 @@
822 694 }
823 695 }
824 696
825 697 /**
826 - * Returns an array that contains field validation messages status.
827 - *
828 - * @since 6.9
829 - *
830 - * @param array|object $field
831 - *
832 - * @return array
833 - */
834 - private static function get_validation_data_attribute_visibility_info( $field ) {
835 - if ( FrmField::get_field_type( $field ) === 'hidden' ) {
836 - $field_validation_data_attributes = array(
837 - 'data-invmsg' => false,
838 - 'data-reqmsg' => false,
839 - );
840 - } else {
841 - $field_validation_data_attributes = array(
842 - 'data-invmsg' => true,
843 - 'data-reqmsg' => true,
844 - );
845 - }
846 -
847 - /**
848 - * Allows controlling which field validation messages would be included in the field html.
849 - *
850 - * @since 6.9
851 - *
852 - * @param array $field_validation_messages_status
853 - * @param array|object $field
854 - */
855 - return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
856 - }
857 -
858 - /**
859 698 * @since 5.0.03
860 699 *
861 700 * @param array $field
862 701 * @param array $add_html
863 - *
864 - * @return void
865 702 */
866 703 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
867 704 $form = self::get_form_for_js_validation( $field );
868 -
869 705 if ( false === $form ) {
870 706 return;
871 707 }
872 708
873 709 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
874 -
875 710 if ( false !== $error_body ) {
876 711 $error_body = urlencode( $error_body );
877 712 $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
878 713 }
@@ -881,24 +716,20 @@
881 716 /**
882 717 * @since 5.0.03
883 718 *
884 719 * @param array $field
885 - *
886 - * @return false|stdClass false if there is no form object found with JS validation active.
720 + * @return stdClass|false false if there is no form object found with JS validation active.
887 721 */
888 722 private static function get_form_for_js_validation( $field ) {
889 723 global $frm_vars;
890 -
891 724 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
892 725 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
893 726 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
894 727 }
895 -
896 728 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
897 729 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
898 730 }
899 731 }
900 -
901 732 return false;
902 733 }
903 734
904 735 /**
@@ -904,10 +735,9 @@
904 735 /**
905 736 * @param stdClass $form
906 737 * @param array $field
907 738 * @param array $errors
908 - *
909 - * @return false|string
739 + * @return string|false
910 740 */
911 741 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
912 742 if ( empty( $field['custom_html'] ) ) {
913 743 return false;
@@ -914,16 +744,15 @@
914 744 }
915 745
916 746 $custom_html = $field['custom_html'];
917 747 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
918 - $start = strpos( $custom_html, '[if error]' );
919 748
749 + $start = strpos( $custom_html, '[if error]' );
920 750 if ( false === $start ) {
921 751 return false;
922 752 }
923 753
924 754 $end = strpos( $custom_html, '[/if error]' );
925 -
926 755 if ( false === $end || $end < $start ) {
927 756 return false;
928 757 }
929 758
@@ -934,9 +763,13 @@
934 763 '<div class="frm_error">[error]</div>',
935 764 '<div class="frm_error" role="alert">[error]</div>',
936 765 );
937 766
938 - return in_array( $error_body, $default_html, true ) ? false : $error_body;
767 + if ( in_array( $error_body, $default_html, true ) ) {
768 + return false;
769 + }
770 +
771 + return $error_body;
939 772 }
940 773
941 774 /**
942 775 * If 'required' is added to a conditionally hidden field, the form won't
@@ -943,13 +776,10 @@
943 776 * submit in many browsers. Check to make sure the javascript to conditionally
944 777 * remove it is present if needed.
945 778 *
946 779 * @since 3.06.01
947 - *
948 780 * @param array $field
949 781 * @param array $add_html
950 - *
951 - * @return void
952 782 */
953 783 private static function maybe_add_html_required( $field, array &$add_html ) {
954 784 $excluded_field_types =
955 785 FrmField::is_radio( $field ) ||
@@ -961,17 +791,14 @@
961 791 if ( $excluded_field_types ) {
962 792 return;
963 793 }
964 794
965 - $add_html['aria-required'] = 'aria-required="true"';
795 + $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
796 + if ( $include_html ) {
797 + $add_html['aria-required'] = 'aria-required="true"';
798 + }
966 799 }
967 800
968 - /**
969 - * @param array $field
970 - * @param array $add_html
971 - *
972 - * @return void
973 - */
974 801 private static function add_shortcodes_to_html( $field, array &$add_html ) {
975 802 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
976 803 return;
977 804 }
@@ -980,25 +807,13 @@
980 807 unset( $field['shortcodes']['autocomplete'] );
981 808 }
982 809
983 810 foreach ( $field['shortcodes'] as $k => $v ) {
984 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
985 - $subfield_name = $field['subfield_name'];
986 -
987 - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
988 - continue;
989 - }
990 - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
991 - $k = 'aria-invalid';
992 - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
993 - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
994 - }
995 -
996 - if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
811 + if ( 'opt' === $k ) {
997 812 continue;
998 813 }
999 814
1000 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
815 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1001 816 $add_html[] = $v;
1002 817 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1003 818 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1004 819 } else {
@@ -1005,63 +820,41 @@
1005 820 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1006 821 }
1007 822
1008 823 unset( $k, $v );
1009 - }//end foreach
1010 - }
1011 -
1012 - /**
1013 - * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
1014 - *
1015 - * @since 6.11.2
1016 - *
1017 - * @param string $key The option key.
1018 - *
1019 - * @return bool
1020 - */
1021 - private static function should_allow_input_attribute( $key ) {
1022 - if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
1023 - return true;
1024 824 }
1025 - return FrmAppHelper::input_key_is_safe( $key );
1026 825 }
1027 826
1028 827 /**
1029 - * Add pattern attribute.
828 + * Add pattern attribute
1030 829 *
1031 830 * @since 3.0
1032 831 *
1033 832 * @param array $field
1034 833 * @param array $add_html
1035 - *
1036 - * @return void
1037 834 */
1038 835 private static function add_pattern_attribute( $field, array &$add_html ) {
1039 - $format_value = FrmField::get_option( $field, 'format' );
1040 - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
836 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1041 837 $format_field = FrmField::is_field_type( $field, 'text' );
1042 838
1043 - if ( $field['type'] === 'phone' || ( $has_format && $format_field ) ) {
1044 - $format = FrmEntryValidate::phone_format( $field );
1045 - $format = substr( $format, 2, - 1 );
839 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
840 + $frm_settings = FrmAppHelper::get_settings();
1046 841
1047 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
842 + if ( $frm_settings->use_html ) {
843 + $format = FrmEntryValidate::phone_format( $field );
844 + $format = substr( $format, 2, - 1 );
845 +
846 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
847 + }
1048 848 }
1049 849 }
1050 850
1051 - /**
1052 - * @param mixed $opt
1053 - * @param mixed $opt_key
1054 - * @param array|object $field
1055 - *
1056 - * @return mixed
1057 - */
1058 851 public static function check_value( $opt, $opt_key, $field ) {
1059 852 if ( is_array( $opt ) ) {
1060 853 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1061 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
854 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1062 855 } else {
1063 - $opt = $opt['label'] ?? reset( $opt );
856 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1064 857 }
1065 858 }
1066 859
1067 860 return $opt;
@@ -1066,17 +859,90 @@
1066 859
1067 860 return $opt;
1068 861 }
1069 862
1070 - /**
1071 - * @param mixed $opt
1072 - *
1073 - * @return mixed
1074 - */
1075 863 public static function check_label( $opt ) {
1076 864 if ( is_array( $opt ) ) {
1077 - $opt = $opt['label'] ?? reset( $opt );
865 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1078 866 }
1079 867
1080 868 return $opt;
869 + }
870 +
871 + /**
872 + * @deprecated 4.0
873 + */
874 + public static function update_ajax_option() {
875 + _deprecated_function( __METHOD__, '4.0' );
876 + FrmAppHelper::permission_check( 'frm_edit_forms' );
877 + check_ajax_referer( 'frm_ajax', 'nonce' );
878 +
879 + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
880 + if ( ! $field_id ) {
881 + wp_die();
882 + }
883 +
884 + $field = FrmField::getOne( $field_id );
885 +
886 + if ( isset( $_POST['separate_value'] ) ) {
887 + $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
888 +
889 + $field->field_options['separate_value'] = $new_val;
890 + unset( $new_val );
891 + }
892 +
893 + FrmField::update(
894 + $field_id,
895 + array(
896 + 'field_options' => $field->field_options,
897 + 'form_id' => $field->form_id,
898 + )
899 + );
900 + wp_die();
901 + }
902 +
903 + /**
904 + * @deprecated 4.0
905 + */
906 + public static function import_choices() {
907 + _deprecated_function( __METHOD__, '4.0' );
908 + wp_die();
909 + }
910 +
911 + /**
912 + * Add Single Option or Other Option.
913 + *
914 + * @deprecated 4.0 Moved to Pro for Other option only.
915 + */
916 + public static function add_option() {
917 + _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
918 + }
919 +
920 + /**
921 + * @deprecated 4.0
922 + */
923 + public static function update_order() {
924 + FrmDeprecated::update_order();
925 + }
926 +
927 + /**
928 + * @deprecated 3.0
929 + * @codeCoverageIgnore
930 + */
931 + public static function edit_name( $field = 'name', $id = '' ) {
932 + FrmDeprecated::edit_name( $field, $id );
933 + }
934 +
935 + /**
936 + * @deprecated 3.0
937 + * @codeCoverageIgnore
938 + *
939 + * @param int $field_id
940 + * @param array $values
941 + * @param int $form_id
942 + *
943 + * @return array
944 + */
945 + public static function include_single_field( $field_id, $values, $form_id = 0 ) {
946 + return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
1081 947 }
1082 948 }