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 +231 -382 6.296.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,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,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|string $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 ';
@@ -224,9 +191,9 @@
224 191
225 192 $li_classes .= 'frmend';
226 193
227 194 if ( $field ) {
228 - return apply_filters( 'frm_build_field_class', $li_classes, $field );
195 + $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
229 196 }
230 197
231 198 return $li_classes;
232 199 }
@@ -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,11 +247,10 @@
293 247 }
294 248 }
295 249
296 250 // Keep other options after bulk update.
297 - if ( ! empty( $field['field_options']['other'] ) ) {
251 + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
298 252 $other_array = array();
299 -
300 253 foreach ( $field['options'] as $opt_key => $opt ) {
301 254 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
302 255 $other_array[ $opt_key ] = $opt;
303 256 }
@@ -302,10 +255,9 @@
302 255 $other_array[ $opt_key ] = $opt;
303 256 }
304 257 unset( $opt_key, $opt );
305 258 }
306 -
307 - if ( $other_array ) {
259 + if ( ! empty( $other_array ) ) {
308 260 $opts = array_merge( $opts, $other_array );
309 261 }
310 262 }
311 263
@@ -319,10 +271,8 @@
319 271 /**
320 272 * @since 4.0
321 273 *
322 274 * @param array $atts - Includes field array, field_obj, display array, values array.
323 - *
324 - * @return void
325 275 */
326 276 public static function load_single_field_settings( $atts ) {
327 277 $field = $atts['field'];
328 278 $field_obj = $atts['field_obj'];
@@ -337,19 +287,19 @@
337 287 if ( ! isset( $field['read_only'] ) ) {
338 288 $field['read_only'] = false;
339 289 }
340 290
341 - $field_selection_data = self::maybe_define_field_selection_data();
342 - $all_field_types = $field_selection_data->all_field_types;
343 - $disabled_fields = $field_selection_data->disabled_fields;
344 - $frm_settings = FrmAppHelper::get_settings();
345 - $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();
346 296
347 297 if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
348 298 // Add fallback for an add-on field type that has been deactivated.
349 299 $all_field_types[ $field['type'] ] = array(
350 300 'name' => ucfirst( $field['type'] ),
351 - 'icon' => 'frmfont frm_pencil_icon',
301 + 'icon' => 'frm_icon_font frm_pencil_icon',
352 302 );
353 303 } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
354 304 // Fallback for fields added in a more basic way.
355 305 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
@@ -355,9 +305,8 @@
355 305 FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
356 306 }
357 307
358 308 $type_name = $all_field_types[ $field['type'] ]['name'];
359 -
360 309 if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
361 310 $type_name = $all_field_types['divider|repeat']['name'];
362 311 }
363 312
@@ -372,72 +321,57 @@
372 321 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php';
373 322 }
374 323
375 324 /**
376 - * @since 6.9.1
377 - *
378 - * @return FrmFieldSelectionData
379 - */
380 - private static function maybe_define_field_selection_data() {
381 - if ( ! isset( self::$field_selection_data ) ) {
382 - self::$field_selection_data = new FrmFieldSelectionData();
383 - }
384 - return self::$field_selection_data;
385 - }
386 -
387 - /**
388 325 * Get the list of default value types that can be toggled in the builder.
389 326 *
390 327 * @since 4.0
391 - *
392 - * @param array $field
393 - * @param array $atts
394 - *
395 328 * @return array
396 329 */
397 330 private static function default_value_types( $field, $atts ) {
398 331 $types = array(
399 - 'default_value' => array(
332 + 'default_value' => array(
400 333 'class' => '',
401 - 'icon' => 'frmfont frm_text2_icon',
402 - 'title' => __( 'Default Value', 'formidable' ),
334 + 'icon' => 'frm_icon_font frm_text2_icon',
335 + 'title' => __( 'Default Value (Text)', 'formidable' ),
403 336 'data' => array(
404 337 'frmshow' => '#default-value-for-',
405 338 ),
406 339 ),
407 - 'calc' => array(
408 - 'class' => 'frm_show_upgrade frm_noallow',
409 - 'title' => __( 'Calculate Value', 'formidable' ),
410 - 'icon' => 'frmfont frm_calculator_icon',
411 - '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(
412 345 'medium' => 'calculations',
413 346 'upgrade' => __( 'Calculator forms', 'formidable' ),
414 347 ),
415 - 'tooltip' => __( 'Automatically calculate the value of this field based on values from other fields.', 'formidable' ),
416 348 ),
417 349 'get_values_field' => array(
418 - 'class' => 'frm_show_upgrade frm_noallow',
419 - 'title' => __( 'Lookup', 'formidable' ),
420 - 'icon' => 'frmfont frm_search_icon',
421 - '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(
422 354 'medium' => 'lookup',
423 355 'upgrade' => __( 'Lookup fields', 'formidable' ),
424 356 ),
425 - 'tooltip' => __( 'Dynamically retrieve the value of this field from a lookup field.', 'formidable' ),
426 357 ),
427 358 );
428 359
429 360 $types = apply_filters( 'frm_default_value_types', $types, $atts );
430 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 +
431 367 // Set active class.
432 368 $settings = array_keys( $types );
433 369 $active = 'default_value';
434 370
435 - if ( FrmAppHelper::pro_is_connected() ) {
436 - foreach ( $settings as $type ) {
437 - if ( ! empty( $field[ $type ] ) ) {
438 - $active = $type;
439 - }
371 + foreach ( $settings as $type ) {
372 + if ( ! empty( $field[ $type ] ) ) {
373 + $active = $type;
440 374 }
441 375 }
442 376
443 377 $types[ $active ]['class'] .= ' current';
@@ -445,13 +379,8 @@
445 379
446 380 return $types;
447 381 }
448 382
449 - /**
450 - * @param string $type
451 - *
452 - * @return string
453 - */
454 383 public static function change_type( $type ) {
455 384 $type_switch = array(
456 385 'scale' => 'radio',
457 386 'star' => 'radio',
@@ -459,9 +388,8 @@
459 388 'rte' => 'textarea',
460 389 'website' => 'url',
461 390 'image' => 'url',
462 391 );
463 -
464 392 if ( isset( $type_switch[ $type ] ) ) {
465 393 $type = $type_switch[ $type ];
466 394 }
467 395
@@ -469,22 +397,24 @@
469 397 // We want to keep credit_card types as credit card types for Stripe Lite.
470 398 // The credit_card key is set for backward compatibility.
471 399 unset( $pro_fields['credit_card'] );
472 400
473 - return array_key_exists( $type, $pro_fields ) ? 'text' : $type;
401 + if ( array_key_exists( $type, $pro_fields ) ) {
402 + $type = 'text';
403 + }
404 +
405 + return $type;
474 406 }
475 407
476 408 /**
477 - * @param array $settings
478 - * @param FrmFieldType|null $field_info
409 + * @param array $settings
410 + * @param object $field_info
479 411 *
480 412 * @return array
481 413 */
482 414 public static function display_field_options( $settings, $field_info = null ) {
483 415 if ( $field_info ) {
484 - $settings = $field_info->display_field_settings();
485 -
486 - // Field appears to be protected but there is a __get function in FrmFieldType that makes this public.
416 + $settings = $field_info->display_field_settings();
487 417 $settings['field_data'] = $field_info->field;
488 418 }
489 419
490 420 return apply_filters( 'frm_display_field_options', $settings );
@@ -494,32 +424,14 @@
494 424 * Display the format option
495 425 *
496 426 * @since 3.0
497 427 *
498 - * @param array $field Field data.
499 - * @param bool $is_hidden Whether the format option should be hidden.
500 - *
501 - * @return void
428 + * @param array $field
502 429 */
503 - public static function show_format_option( $field, $is_hidden = false ) {
504 - $attributes = array(
505 - 'class' => 'frm-has-modal',
506 - 'id' => 'frm-field-format-custom-' . $field['id'],
507 - );
508 -
509 - if ( $is_hidden ) {
510 - $attributes['class'] .= ' frm_hidden';
511 - }
512 -
513 - 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' );
514 432 }
515 433
516 - /**
517 - * @param array $field
518 - * @param bool $echo
519 - *
520 - * @return string
521 - */
522 434 public static function input_html( $field, $echo = true ) {
523 435 $class = array();
524 436 self::add_input_classes( $field, $class );
525 437
@@ -545,20 +457,14 @@
545 457
546 458 return $add_html;
547 459 }
548 460
549 - /**
550 - * @param array $field
551 - * @param array $class
552 - *
553 - * @return void
554 - */
555 461 private static function add_input_classes( $field, array &$class ) {
556 - if ( ! empty( $field['input_class'] ) ) {
462 + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
557 463 $class[] = $field['input_class'];
558 464 }
559 465
560 - if ( $field['type'] === 'hidden' || $field['type'] === 'user_id' ) {
466 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
561 467 return;
562 468 }
563 469
564 470 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
@@ -565,14 +471,8 @@
565 471 $class[] = 'auto_width';
566 472 }
567 473 }
568 474
569 - /**
570 - * @param array $field
571 - * @param array $add_html
572 - *
573 - * @return void
574 - */
575 475 private static function add_html_size( $field, array &$add_html ) {
576 476 $size_fields = array(
577 477 'select',
578 478 'data',
@@ -581,9 +481,9 @@
581 481 'file',
582 482 'lookup',
583 483 );
584 484
585 - 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 ) ) {
586 486 return;
587 487 }
588 488
589 489 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -600,14 +500,8 @@
600 500
601 501 self::add_html_cols( $field, $add_html );
602 502 }
603 503
604 - /**
605 - * @param array $field
606 - * @param array $add_html
607 - *
608 - * @return void
609 - */
610 504 private static function add_html_cols( $field, array &$add_html ) {
611 505 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ), true ) ) {
612 506 return;
613 507 }
@@ -619,9 +513,9 @@
619 513 'rem' => 0.444,
620 514 'em' => 0.544,
621 515 );
622 516
623 - // Include "col" for valid html
517 + // include "col" for valid html
624 518 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
625 519
626 520 if ( ! isset( $calc[ $unit ] ) ) {
627 521 return;
@@ -626,18 +520,13 @@
626 520 if ( ! isset( $calc[ $unit ] ) ) {
627 521 return;
628 522 }
629 523
630 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
524 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
525 +
631 526 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
632 527 }
633 528
634 - /**
635 - * @param array $field
636 - * @param array $add_html
637 - *
638 - * @return void
639 - */
640 529 private static function add_html_length( $field, array &$add_html ) {
641 530 // Check for max setting and if this field accepts maxlength.
642 531 $fields = array(
643 532 'textarea',
@@ -645,9 +534,9 @@
645 534 'hidden',
646 535 'file',
647 536 );
648 537
649 - 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 ) ) {
650 539 return;
651 540 }
652 541
653 542 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
@@ -657,17 +546,9 @@
657 546
658 547 $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
659 548 }
660 549
661 - /**
662 - * @param array $field
663 - * @param array $add_html
664 - * @param array $class
665 - *
666 - * @return void
667 - */
668 550 private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
669 - // phpcs:ignore Universal.Operators.StrictComparisons
670 551 if ( $field['default_value'] != '' ) {
671 552 if ( is_array( $field['default_value'] ) ) {
672 553 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( json_encode( $field['default_value'] ) ) . '"';
673 554 } else {
@@ -675,16 +556,26 @@
675 556 }
676 557 }
677 558
678 559 $field['placeholder'] = self::prepare_placeholder( $field );
679 -
680 - // phpcs:ignore Universal.Operators.StrictComparisons
681 560 if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
682 - // Don't include a json placeholder
561 + // don't include a json placeholder
683 562 return;
684 563 }
685 564
686 - 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 + }
687 578 }
688 579
689 580 /**
690 581 * Prepares field placeholder.
@@ -691,13 +582,14 @@
691 582 *
692 583 * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
693 584 *
694 585 * @param array $field Field array.
695 - *
696 586 * @return string
697 587 */
698 588 private static function prepare_placeholder( $field ) {
699 - return $field['placeholder'] ?? '';
589 + $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
590 +
591 + return $placeholder;
700 592 }
701 593
702 594 /**
703 595 * If the label position is "inside",
@@ -718,39 +610,22 @@
718 610 * Maybe add a blank placeholder option before any options
719 611 * in a dropdown.
720 612 *
721 613 * @since 4.04
722 - *
723 - * @param array|object $field
724 - *
725 614 * @return bool True if placeholder was added.
726 615 */
727 616 public static function add_placeholder_to_select( $field ) {
728 617 $placeholder = FrmField::get_option( $field, 'placeholder' );
729 -
730 - if ( ! $placeholder ) {
618 + if ( empty( $placeholder ) ) {
731 619 $placeholder = self::get_default_value_from_name( $field );
732 620 }
733 621
734 - $use_placeholder = $placeholder;
735 - $autocomplete = FrmField::get_option( $field, 'autocom' );
736 -
737 - if ( $autocomplete ) {
738 - $use_chosen = ! is_callable( 'FrmProAppHelper::use_chosen_js' ) || FrmProAppHelper::use_chosen_js();
739 -
740 - if ( $use_chosen ) {
741 - $use_placeholder = '';
742 - }
743 - }
744 -
745 622 if ( $placeholder !== '' ) {
746 - $placeholder_attributes = array(
747 - 'class' => 'frm-select-placeholder',
748 - 'value' => '',
749 - 'data-placeholder' => 'true',
750 - );
751 -
752 - 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
753 628 return true;
754 629 }
755 630
756 631 return false;
@@ -756,14 +631,12 @@
756 631 return false;
757 632 }
758 633
759 634 /**
760 - * Use HTML5 placeholder with js fallback.
635 + * Use HMTL5 placeholder with js fallback
761 636 *
762 637 * @param array $field
763 638 * @param array $add_html
764 - *
765 - * @return void
766 639 */
767 640 private static function add_placeholder_to_input( $field, &$add_html ) {
768 641 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
769 642 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
@@ -769,16 +642,9 @@
769 642 $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
770 643 }
771 644 }
772 645
773 - /**
774 - * @param array $field
775 - * @param array $add_html
776 - *
777 - * @return void
778 - */
779 646 private static function add_frmval_to_input( $field, &$add_html ) {
780 - // phpcs:ignore Universal.Operators.StrictComparisons
781 647 if ( $field['placeholder'] != '' ) {
782 648 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['placeholder'] ) . '"';
783 649
784 650 if ( 'select' === $field['type'] ) {
@@ -785,30 +651,21 @@
785 651 $add_html['data-frmplaceholder'] = 'data-frmplaceholder="' . esc_attr( $field['placeholder'] ) . '"';
786 652 }
787 653 }
788 654
789 - // phpcs:ignore Universal.Operators.StrictComparisons
790 655 if ( $field['default_value'] != '' ) {
791 656 $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
792 657 }
793 658 }
794 659
795 - /**
796 - * @param array $field
797 - * @param array $add_html
798 - *
799 - * @return void
800 - */
801 660 private static function add_validation_messages( $field, array &$add_html ) {
802 - $field_validation_messages_status = self::get_validation_data_attribute_visibility_info( $field );
803 -
804 - if ( FrmField::is_required( $field ) && ! empty( $field_validation_messages_status['data-reqmsg'] ) ) {
661 + if ( FrmField::is_required( $field ) ) {
805 662 $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
806 663 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
807 664 self::maybe_add_html_required( $field, $add_html );
808 665 }
809 666
810 - if ( ! FrmField::is_option_empty( $field, 'invalid' ) && ! empty( $field_validation_messages_status['data-invmsg'] ) ) {
667 + if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
811 668 $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
812 669 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
813 670 }
814 671
@@ -817,63 +674,24 @@
817 674 }
818 675 }
819 676
820 677 /**
821 - * Returns an array that contains field validation messages status.
822 - *
823 - * @since 6.9
824 - *
825 - * @param array|object $field
826 - *
827 - * @return array
828 - */
829 - private static function get_validation_data_attribute_visibility_info( $field ) {
830 - if ( FrmField::get_field_type( $field ) === 'hidden' ) {
831 - $field_validation_data_attributes = array(
832 - 'data-invmsg' => false,
833 - 'data-reqmsg' => false,
834 - );
835 - } else {
836 - $field_validation_data_attributes = array(
837 - 'data-invmsg' => true,
838 - 'data-reqmsg' => true,
839 - );
840 - }
841 -
842 - /**
843 - * Allows controlling which field validation messages would be included in the field html.
844 - *
845 - * @since 6.9
846 - *
847 - * @param array $field_validation_messages_status
848 - * @param array|object $field
849 - */
850 - return apply_filters( 'frm_field_validation_include_data_attributes', $field_validation_data_attributes, $field );
851 - }
852 -
853 - /**
854 678 * @since 5.0.03
855 679 *
856 680 * @param array $field
857 681 * @param array $add_html
858 - *
859 - * @return void
860 682 */
861 683 private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
862 684 $form = self::get_form_for_js_validation( $field );
863 -
864 685 if ( false === $form ) {
865 686 return;
866 687 }
867 688
868 689 $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
869 -
870 - if ( false === $error_body ) {
871 - return;
690 + if ( false !== $error_body ) {
691 + $error_body = urlencode( $error_body );
692 + $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
872 693 }
873 -
874 - $error_body = urlencode( $error_body );
875 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
876 694 }
877 695
878 696 /**
879 697 * @since 5.0.03
@@ -878,24 +696,20 @@
878 696 /**
879 697 * @since 5.0.03
880 698 *
881 699 * @param array $field
882 - *
883 - * @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.
884 701 */
885 702 private static function get_form_for_js_validation( $field ) {
886 703 global $frm_vars;
887 -
888 704 if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
889 705 if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
890 706 return $frm_vars['js_validate_forms'][ $field['form_id'] ];
891 707 }
892 -
893 708 if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
894 709 return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
895 710 }
896 711 }
897 -
898 712 return false;
899 713 }
900 714
901 715 /**
@@ -901,10 +715,9 @@
901 715 /**
902 716 * @param stdClass $form
903 717 * @param array $field
904 718 * @param array $errors
905 - *
906 - * @return false|string
719 + * @return string|false
907 720 */
908 721 public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
909 722 if ( empty( $field['custom_html'] ) ) {
910 723 return false;
@@ -911,16 +724,15 @@
911 724 }
912 725
913 726 $custom_html = $field['custom_html'];
914 727 $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
915 - $start = strpos( $custom_html, '[if error]' );
916 728
729 + $start = strpos( $custom_html, '[if error]' );
917 730 if ( false === $start ) {
918 731 return false;
919 732 }
920 733
921 734 $end = strpos( $custom_html, '[/if error]' );
922 -
923 735 if ( false === $end || $end < $start ) {
924 736 return false;
925 737 }
926 738
@@ -931,9 +743,13 @@
931 743 '<div class="frm_error">[error]</div>',
932 744 '<div class="frm_error" role="alert">[error]</div>',
933 745 );
934 746
935 - 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;
936 752 }
937 753
938 754 /**
939 755 * If 'required' is added to a conditionally hidden field, the form won't
@@ -940,16 +756,12 @@
940 756 * submit in many browsers. Check to make sure the javascript to conditionally
941 757 * remove it is present if needed.
942 758 *
943 759 * @since 3.06.01
944 - *
945 760 * @param array $field
946 761 * @param array $add_html
947 - *
948 - * @return void
949 762 */
950 763 private static function maybe_add_html_required( $field, array &$add_html ) {
951 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
952 764 $excluded_field_types =
953 765 FrmField::is_radio( $field ) ||
954 766 FrmField::is_checkbox( $field ) ||
955 767 FrmField::is_field_type( $field, 'file' ) ||
@@ -954,23 +766,19 @@
954 766 FrmField::is_checkbox( $field ) ||
955 767 FrmField::is_field_type( $field, 'file' ) ||
956 768 FrmField::is_field_type( $field, 'nps' ) ||
957 769 FrmField::is_field_type( $field, 'scale' );
958 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
959 770
960 771 if ( $excluded_field_types ) {
961 772 return;
962 773 }
963 774
964 - $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 + }
965 779 }
966 780
967 - /**
968 - * @param array $field
969 - * @param array $add_html
970 - *
971 - * @return void
972 - */
973 781 private static function add_shortcodes_to_html( $field, array &$add_html ) {
974 782 if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
975 783 return;
976 784 }
@@ -979,25 +787,13 @@
979 787 unset( $field['shortcodes']['autocomplete'] );
980 788 }
981 789
982 790 foreach ( $field['shortcodes'] as $k => $v ) {
983 - if ( isset( $field['subfield_name'] ) && str_starts_with( $k, 'aria-invalid' ) ) {
984 - $subfield_name = $field['subfield_name'];
985 -
986 - if ( ! isset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] ) ) {
987 - continue;
988 - }
989 - // Change the key to the correct aria-invalid value so that $add_html is set correctly for the current subfield of a combo field.
990 - $k = 'aria-invalid';
991 - $v = $field['shortcodes'][ 'aria-invalid-' . $subfield_name ];
992 - unset( $field['shortcodes'][ 'aria-invalid-' . $subfield_name ] );
993 - }
994 -
995 - if ( 'opt' === $k || ! self::should_allow_input_attribute( $k ) ) {
791 + if ( 'opt' === $k ) {
996 792 continue;
997 793 }
998 794
999 - if ( is_numeric( $k ) && str_contains( $v, '=' ) ) {
795 + if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
1000 796 $add_html[] = $v;
1001 797 } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
1002 798 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
1003 799 } else {
@@ -1004,65 +800,41 @@
1004 800 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
1005 801 }
1006 802
1007 803 unset( $k, $v );
1008 - }//end foreach
1009 - }
1010 -
1011 - /**
1012 - * Disallow possibly unsafe attributees (that trigger JavaScript) when unasfe HTML is not allowed.
1013 - *
1014 - * @since 6.11.2
1015 - *
1016 - * @param string $key The option key.
1017 - *
1018 - * @return bool
1019 - */
1020 - private static function should_allow_input_attribute( $key ) {
1021 - if ( ! FrmAppHelper::should_never_allow_unfiltered_html() ) {
1022 - return true;
1023 804 }
1024 - return FrmAppHelper::input_key_is_safe( $key );
1025 805 }
1026 806
1027 807 /**
1028 - * Add pattern attribute.
808 + * Add pattern attribute
1029 809 *
1030 810 * @since 3.0
1031 811 *
1032 812 * @param array $field
1033 813 * @param array $add_html
1034 - *
1035 - * @return void
1036 814 */
1037 815 private static function add_pattern_attribute( $field, array &$add_html ) {
1038 - $format_value = FrmField::get_option( $field, 'format' );
1039 - $has_format = $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value );
816 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
1040 817 $format_field = FrmField::is_field_type( $field, 'text' );
1041 818
1042 - if ( $field['type'] !== 'phone' && ( ! $has_format || ! $format_field ) ) {
1043 - return;
1044 - }
819 + if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
820 + $frm_settings = FrmAppHelper::get_settings();
1045 821
1046 - $format = FrmEntryValidate::phone_format( $field );
1047 - $format = substr( $format, 2, - 1 );
822 + if ( $frm_settings->use_html ) {
823 + $format = FrmEntryValidate::phone_format( $field );
824 + $format = substr( $format, 2, - 1 );
1048 825
1049 - $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
826 + $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
827 + }
828 + }
1050 829 }
1051 830
1052 - /**
1053 - * @param mixed $opt
1054 - * @param mixed $opt_key
1055 - * @param array|object $field
1056 - *
1057 - * @return mixed
1058 - */
1059 831 public static function check_value( $opt, $opt_key, $field ) {
1060 832 if ( is_array( $opt ) ) {
1061 833 if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
1062 - $opt = $opt['value'] ?? $opt['label'] ?? reset( $opt );
834 + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
1063 835 } else {
1064 - $opt = $opt['label'] ?? reset( $opt );
836 + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
1065 837 }
1066 838 }
1067 839
1068 840 return $opt;
@@ -1067,13 +839,90 @@
1067 839
1068 840 return $opt;
1069 841 }
1070 842
843 + public static function check_label( $opt ) {
844 + if ( is_array( $opt ) ) {
845 + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
846 + }
847 +
848 + return $opt;
849 + }
850 +
1071 851 /**
1072 - * @param mixed $opt
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.
1073 893 *
1074 - * @return mixed
894 + * @deprecated 4.0 Moved to Pro for Other option only.
1075 895 */
1076 - public static function check_label( $opt ) {
1077 - return is_array( $opt ) ? ( $opt['label'] ?? reset( $opt ) ) : $opt;
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 );
1078 927 }
1079 928 }