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 +231 -363 6.286.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,11 +26,10 @@
34 26
35 27 foreach ( $fields as $field ) {
36 28 $field = htmlspecialchars_decode( nl2br( $field ) );
37 29 $field = json_decode( $field );
38 -
39 30 if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
40 - // This field may have already been loaded
31 + // this field may have already been loaded
41 32 continue;
42 33 }
43 34
44 35 if ( ! isset( $field->value ) ) {
@@ -49,10 +40,11 @@
49 40 $field->default_value = json_decode( json_encode( $field->default_value ), true );
50 41
51 42 ob_start();
52 43 self::load_single_field( $field, $values );
53 - $field_html[ absint( $field->id ) ] = ob_get_clean();
54 - }//end foreach
44 + $field_html[ absint( $field->id ) ] = ob_get_contents();
45 + ob_end_clean();
46 + }
55 47
56 48 echo json_encode( $field_html );
57 49
58 50 wp_die();
@@ -64,17 +56,16 @@
64 56 public static function create() {
65 57 FrmAppHelper::permission_check( 'frm_edit_forms' );
66 58 check_ajax_referer( 'frm_ajax', 'nonce' );
67 59
68 - $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
69 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
70 - $field_options = FrmAppHelper::get_post_param( 'field_options', array(), 'wp_kses_post' );
60 + $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
61 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
71 62
72 63 do_action( 'frm_before_create_field', $field_type, $form_id );
73 64
74 - $field = self::include_new_field( $field_type, $form_id, $field_options );
65 + $field = self::include_new_field( $field_type, $form_id );
75 66
76 - // This hook will allow for multiple fields to be added at once
67 + // this hook will allow for multiple fields to be added at once
77 68 do_action( 'frm_after_field_created', $field, $form_id );
78 69
79 70 wp_die();
80 71 }
@@ -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|string $field_object
159 - * @param array $values
160 - * @param int $form_id
161 - *
162 - * @return void
146 + * @param int|array|object $field_object
147 + * @param array $values
148 + * @param int $form_id
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 ';
@@ -224,9 +194,9 @@
224 194
225 195 $li_classes .= 'frmend';
226 196
227 197 if ( $field ) {
228 - return apply_filters( 'frm_build_field_class', $li_classes, $field );
198 + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
229 199 }
230 200
231 201 return $li_classes;
232 202 }
@@ -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
@@ -470,22 +400,24 @@
470 400 // We want to keep credit_card types as credit card types for Stripe Lite.
471 401 // The credit_card key is set for backward compatibility.
472 402 unset( $pro_fields['credit_card'] );
473 403
474 - return array_key_exists( $type, $pro_fields ) ? 'text' : $type;
404 + if ( array_key_exists( $type, $pro_fields ) ) {
405 + $type = 'text';
406 + }
407 +
408 + return $type;
475 409 }
476 410
477 411 /**
478 - * @param array $settings
479 - * @param FrmFieldType|null $field_info
412 + * @param array $settings
413 + * @param object $field_info
480 414 *
481 415 * @return array
482 416 */
483 417 public static function display_field_options( $settings, $field_info = null ) {
484 418 if ( $field_info ) {
485 - $settings = $field_info->display_field_settings();
486 -
487 - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
419 + $settings = $field_info->display_field_settings();
488 420 $settings['field_data'] = $field_info->field;
489 421 }
490 422
491 423 return apply_filters( 'frm_display_field_options', $settings );
@@ -495,32 +427,14 @@
495 427 * Display the format option
496 428 *
497 429 * @since 3.0
498 430 *
499 - * @param array $field Field data.
500 - * @param bool $is_hidden Whether the format option should be hidden.
501 - *
502 - * @return void
431 + * @param array $field
503 432 */
504 - public static function show_format_option( $field, $is_hidden = false ) {
505 - $attributes = array(
506 - 'class' => 'frm-has-modal',
507 - 'id' => 'frm-field-format-custom-' . $field['id'],
508 - );
509 -
510 - if ( $is_hidden ) {
511 - $attributes['class'] .= ' frm_hidden';
512 - }
513 -
514 - 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' );
515 435 }
516 436
517 - /**
518 - * @param array $field
519 - * @param bool $echo
520 - *
521 - * @return string
522 - */
523 437 public static function input_html( $field, $echo = true ) {
524 438 $class = array();
525 439 self::add_input_classes( $field, $class );
526 440
@@ -546,20 +460,14 @@
546 460
547 461 return $add_html;
548 462 }
549 463
550 - /**
551 - * @param array $field
552 - * @param array $class
553 - *
554 - * @return void
555 - */
556 464 private static function add_input_classes( $field, array &$class ) {
557 - if ( ! empty( $field['input_class'] ) ) {
465 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
558 466 $class[] = $field['input_class'];
559 467 }
560 468
561 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
469 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
562 470 return;
563 471 }
564 472
565 473 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -566,14 +474,8 @@
566 474 $class[] = 'auto_width';
567 475 }
568 476 }
569 477
570 - /**
571 - * @param array $field
572 - * @param array $add_html
573 - *
574 - * @return void
575 - */
576 478 private static function add_html_size( $field, array &$add_html ) {
577 479 $size_fields = array(
578 480 'select',
579 481 'data',
@@ -582,9 +484,9 @@
582 484 'file',
583 485 'lookup',
584 486 );
585 487
586 - 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 ) ) {
587 489 return;
588 490 }
589 491
590 492 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -601,14 +503,8 @@
601 503
602 504 self::add_html_cols( $field, $add_html );
603 505 }
604 506
605 - /**
606 - * @param array $field
607 - * @param array $add_html
608 - *
609 - * @return void
610 - */
611 507 private static function add_html_cols( $field, array &$add_html ) {
612 508 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
613 509 return;
614 510 }
@@ -620,9 +516,9 @@
620 516 'rem' => 0.444,
621 517 'em' => 0.544,
622 518 );
623 519
624 - // Include "col" for valid html
520 + // include "col" for valid html
625 521 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
626 522
627 523 if ( ! isset( $calc[ $unit ] ) ) {
628 524 return;
@@ -627,18 +523,13 @@
627 523 if ( ! isset( $calc[ $unit ] ) ) {
628 524 return;
629 525 }
630 526
631 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
527 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
528 +
632 529 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
633 530 }
634 531
635 - /**
636 - * @param array $field
637 - * @param array $add_html
638 - *
639 - * @return void
640 - */
641 532 private static function add_html_length( $field, array &$add_html ) {
642 533 // Check for max setting and if this field accepts maxlength.
643 534 $fields = array(
644 535 'textarea',
@@ -646,9 +537,9 @@
646 537 'hidden',
647 538 'file',
648 539 );
649 540
650 - 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 ) ) {
651 542 return;
652 543 }
653 544
654 545 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -658,17 +549,9 @@
658 549
659 550 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
660 551 }
661 552
662 - /**
663 - * @param array $field
664 - * @param array $add_html
665 - * @param array $class
666 - *
667 - * @return void
668 - */
669 553 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
670 - // phpcs:ignore Universal.Operators.StrictComparisons
671 554 if ( $field['default_value'] != '' ) {
672 555 if ( is_array( $field['default_value'] ) ) {
673 556 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
674 557 } else {
@@ -676,16 +559,26 @@
676 559 }
677 560 }
678 561
679 562 $field['placeholder'] = self::prepare_placeholder( $field );
680 -
681 - // phpcs:ignore Universal.Operators.StrictComparisons
682 563 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
683 - // Don't include a json placeholder
564 + // don't include a json placeholder
684 565 return;
685 566 }
686 567
687 - 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 + }
688 581 }
689 582
690 583 /**
691 584 * Prepares field placeholder.
@@ -692,13 +585,14 @@
692 585 *
693 586 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
694 587 *
695 588 * @param array $field Field array.
696 - *
697 589 * @return string
698 590 */
699 591 private static function prepare_placeholder( $field ) {
700 - return $field['placeholder'] ?? '';
592 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
593 +
594 + return $placeholder;
701 595 }
702 596
703 597 /**
704 598 * If the label position is "inside",
@@ -719,17 +613,13 @@
719 613 * Maybe add a blank placeholder option before any options
720 614 * in a dropdown.
721 615 *
722 616 * @since 4.04
723 - *
724 - * @param array|object $field
725 - *
726 617 * @return bool True if placeholder was added.
727 618 */
728 619 public static function add_placeholder_to_select( $field ) {
729 620 $placeholder = FrmField::get_option( $field, 'placeholder' );
730 -
731 - if ( ! $placeholder ) {
621 + if ( empty( $placeholder ) ) {
732 622 $placeholder = self::get_default_value_from_name( $field );
733 623 }
734 624
735 625 $use_placeholder = $placeholder;
@@ -736,9 +626,8 @@
736 626 $autocomplete = FrmField::get_option( $field, 'autocom' );
737 627
738 628 if ( $autocomplete ) {
739 629 $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
740 -
741 630 if ( $use_chosen ) {
742 631 $use_placeholder = '';
743 632 }
744 633 }
@@ -749,8 +638,13 @@
749 638 'value' => '',
750 639 'data-placeholder' => 'true',
751 640 );
752 641
642 + if ( $autocomplete && empty( $use_chosen ) ) {
643 + // This is required for Slim Select.
644 + $placeholder_attributes['data-placeholder'] = 'true';
645 + }
646 +
753 647 FrmHtmlHelper::echo_dropdown_option( $use_placeholder, false, $placeholder_attributes );
754 648 return true;
755 649 }
756 650
@@ -757,14 +651,12 @@
757 651 return false;
758 652 }
759 653
760 654 /**
761 - * Use HTML5 placeholder with js fallback.
655 + * Use HMTL5 placeholder with js fallback
762 656 *
763 657 * @param array $field
764 658 * @param array $add_html
765 - *
766 - * @return void
767 659 */
768 660 private static function add_placeholder_to_input( $field, &$add_html ) {
769 661 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
770 662 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -770,16 +662,9 @@
770 662 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
771 663 }
772 664 }
773 665
774 - /**
775 - * @param array $field
776 - * @param array $add_html
777 - *
778 - * @return void
779 - */
780 666 private static function add_frmval_to_input( $field, &$add_html ) {
781 - // phpcs:ignore Universal.Operators.StrictComparisons
782 667 if ( $field['placeholder'] != '' ) {
783 668 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
784 669
785 670 if ( 'select' === $field['type'] ) {
@@ -786,30 +671,21 @@
786 671 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
787 672 }
788 673 }
789 674
790 - // phpcs:ignore Universal.Operators.StrictComparisons
791 675 if ( $field['default_value'] != '' ) {
792 676 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
793 677 }
794 678 }
795 679
796 - /**
797 - * @param array $field
798 - * @param array $add_html
799 - *
800 - * @return void
801 - */
802 680 private static function add_validation_messages( $field, array &$add_html ) {
803 - $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
804 -
805 - if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
681 + if ( FrmField::is_required( $field ) ) {
806 682 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
807 683 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
808 684 self::maybe_add_html_required( $field, $add_html );
809 685 }
810 686
811 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
687 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
812 688 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
813 689 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
814 690 }
815 691
@@ -818,63 +694,24 @@
818 694 }
819 695 }
820 696
821 697 /**
822 - * Returns an array that contains field validation messages status.
823 - *
824 - * @since 6.9
825 - *
826 - * @param array|object $field
827 - *
828 - * @return array
829 - */
830 - private static function get_validation_data_attribute_visibility_info( $field ) {
831 - if ( FrmField::get_field_type( $field ) === 'hidden' ) {
832 - $field_validation_data_attributes = array(
833 - 'data-invmsg' => false,
834 - 'data-reqmsg' => false,
835 - );
836 - } else {
837 - $field_validation_data_attributes = array(
838 - 'data-invmsg' => true,
839 - 'data-reqmsg' => true,
840 - );
841 - }
842 -
843 - /**
844 - * Allows controlling which field validation messages would be included in the field html.
845 - *
846 - * @since 6.9
847 - *
848 - * @param array $field_validation_messages_status
849 - * @param array|object $field
850 - */
851 - return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
852 - }
853 -
854 - /**
855 698 * @since 5.0.03
856 699 *
857 700 * @param array $field
858 701 * @param array $add_html
859 - *
860 - * @return void
861 702 */
862 703 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
863 704 $form = self::get_form_for_js_validation( $field );
864 -
865 705 if ( false === $form ) {
866 706 return;
867 707 }
868 708
869 709 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
870 -
871 - if ( false === $error_body ) {
872 - return;
710 + if ( false !== $error_body ) {
711 + $error_body = urlencode( $error_body );
712 + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
873 713 }
874 -
875 - $error_body = urlencode( $error_body );
876 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
877 714 }
878 715
879 716 /**
880 717 * @since 5.0.03
@@ -879,24 +716,20 @@
879 716 /**
880 717 * @since 5.0.03
881 718 *
882 719 * @param array $field
883 - *
884 - * @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.
885 721 */
886 722 private static function get_form_for_js_validation( $field ) {
887 723 global $frm_vars;
888 -
889 724 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
890 725 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
891 726 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
892 727 }
893 -
894 728 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
895 729 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
896 730 }
897 731 }
898 -
899 732 return false;
900 733 }
901 734
902 735 /**
@@ -902,10 +735,9 @@
902 735 /**
903 736 * @param stdClass $form
904 737 * @param array $field
905 738 * @param array $errors
906 - *
907 - * @return false|string
739 + * @return string|false
908 740 */
909 741 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
910 742 if ( empty( $field['custom_html'] ) ) {
911 743 return false;
@@ -912,16 +744,15 @@
912 744 }
913 745
914 746 $custom_html = $field['custom_html'];
915 747 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
916 - $start = strpos( $custom_html, '[if error]' );
917 748
749 + $start = strpos( $custom_html, '[if error]' );
918 750 if ( false === $start ) {
919 751 return false;
920 752 }
921 753
922 754 $end = strpos( $custom_html, '[/if error]' );
923 -
924 755 if ( false === $end || $end < $start ) {
925 756 return false;
926 757 }
927 758
@@ -932,9 +763,13 @@
932 763 '<div class="frm_error">[error]</div>',
933 764 '<div class="frm_error" role="alert">[error]</div>',
934 765 );
935 766
936 - 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;
937 772 }
938 773
939 774 /**
940 775 * If 'required' is added to a conditionally hidden field, the form won't
@@ -941,16 +776,12 @@
941 776 * submit in many browsers. Check to make sure the javascript to conditionally
942 777 * remove it is present if needed.
943 778 *
944 779 * @since 3.06.01
945 - *
946 780 * @param array $field
947 781 * @param array $add_html
948 - *
949 - * @return void
950 782 */
951 783 private static function maybe_add_html_required( $field, array &$add_html ) {
952 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
953 784 $excluded_field_types =
954 785 FrmField::is_radio( $field ) ||
955 786 FrmField::is_checkbox( $field ) ||
956 787 FrmField::is_field_type( $field, 'file' ) ||
@@ -955,23 +786,19 @@
955 786 FrmField::is_checkbox( $field ) ||
956 787 FrmField::is_field_type( $field, 'file' ) ||
957 788 FrmField::is_field_type( $field, 'nps' ) ||
958 789 FrmField::is_field_type( $field, 'scale' );
959 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
960 790
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,65 +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 - return;
1045 - }
839 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
840 + $frm_settings = FrmAppHelper::get_settings();
1046 841
1047 - $format = FrmEntryValidate::phone_format( $field );
1048 - $format = substr( $format, 2, - 1 );
842 + if ( $frm_settings->use_html ) {
843 + $format = FrmEntryValidate::phone_format( $field );
844 + $format = substr( $format, 2, - 1 );
1049 845
1050 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
846 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
847 + }
848 + }
1051 849 }
1052 850
1053 - /**
1054 - * @param mixed $opt
1055 - * @param mixed $opt_key
1056 - * @param array|object $field
1057 - *
1058 - * @return mixed
1059 - */
1060 851 public static function check_value( $opt, $opt_key, $field ) {
1061 852 if ( is_array( $opt ) ) {
1062 853 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1063 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
854 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1064 855 } else {
1065 - $opt = $opt['label'] ?? reset( $opt );
856 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1066 857 }
1067 858 }
1068 859
1069 860 return $opt;
@@ -1068,13 +859,90 @@
1068 859
1069 860 return $opt;
1070 861 }
1071 862
863 + public static function check_label( $opt ) {
864 + if ( is_array( $opt ) ) {
865 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
866 + }
867 +
868 + return $opt;
869 + }
870 +
1072 871 /**
1073 - * @param mixed $opt
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.
1074 913 *
1075 - * @return mixed
914 + * @deprecated 4.0 Moved to Pro for Other option only.
1076 915 */
1077 - public static function check_label( $opt ) {
1078 - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt;
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 );
1079 947 }
1080 948 }