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