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