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