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