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