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