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