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