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