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