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