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