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 +340 -497 6.43.06.06 View file →
@@ -1,31 +1,27 @@
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 - public static function load_field() {
5 + public static function load_field() {
9 6 FrmAppHelper::permission_check( 'frm_edit_forms' );
10 - check_ajax_referer( 'frm_ajax', 'nonce' );
7 + check_ajax_referer( 'frm_ajax', 'nonce' );
11 8
12 - // Javascript may be included in some field settings.
13 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
14 - $fields = isset( $_POST['field'] ) ? wp_unslash( $_POST['field'] ) : array();
15 - if ( empty( $fields ) ) {
16 - wp_die();
17 - }
9 + $fields = $_POST['field'];
10 + if ( empty( $fields ) ) {
11 + wp_die();
12 + }
18 13
19 - $_GET['page'] = 'formidable';
14 + $_GET['page'] = 'formidable';
15 + $fields = stripslashes_deep( $fields );
20 16
21 - $values = array(
22 - 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
17 + $values = array(
18 + 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
23 19 'doing_ajax' => true,
24 20 );
25 - $field_html = array();
21 + $field_html = array();
26 22
27 - foreach ( $fields as $field ) {
23 + foreach ( $fields as $field ) {
28 24 $field = htmlspecialchars_decode( nl2br( $field ) );
29 25 $field = json_decode( $field );
30 26 if ( ! isset( $field->id ) || ! is_numeric( $field->id ) ) {
31 27 // this field may have already been loaded
@@ -35,9 +31,9 @@
35 31 if ( ! isset( $field->value ) ) {
36 32 $field->value = '';
37 33 }
38 34 $field->field_options = json_decode( json_encode( $field->field_options ), true );
39 - $field->options = json_decode( json_encode( $field->options ), true );
35 + $field->options = json_decode( json_encode( $field->options ), true );
40 36 $field->default_value = json_decode( json_encode( $field->default_value ), true );
41 37
42 38 ob_start();
43 39 self::load_single_field( $field, $values );
@@ -42,52 +38,49 @@
42 38 ob_start();
43 39 self::load_single_field( $field, $values );
44 40 $field_html[ absint( $field->id ) ] = ob_get_contents();
45 41 ob_end_clean();
46 - }
42 + }
47 43
48 44 echo json_encode( $field_html );
49 45
50 - wp_die();
51 - }
46 + wp_die();
47 + }
52 48
53 49 /**
54 50 * Create a new field with ajax
55 51 */
56 - public static function create() {
52 + public static function create() {
57 53 FrmAppHelper::permission_check( 'frm_edit_forms' );
58 - check_ajax_referer( 'frm_ajax', 'nonce' );
54 + check_ajax_referer( 'frm_ajax', 'nonce' );
59 55
60 56 $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' );
61 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
57 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
62 58
63 - do_action( 'frm_before_create_field', $field_type, $form_id );
64 -
65 59 $field = self::include_new_field( $field_type, $form_id );
66 60
67 61 // this hook will allow for multiple fields to be added at once
68 62 do_action( 'frm_after_field_created', $field, $form_id );
69 63
70 - wp_die();
71 - }
64 + wp_die();
65 + }
72 66
73 - /**
74 - * Set up and create a new field
75 - *
76 - * @param string $field_type
77 - * @param integer $form_id
78 - *
79 - * @return array|bool
80 - */
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 + */
81 74 public static function include_new_field( $field_type, $form_id ) {
82 75 $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
83 - $field_values = apply_filters( 'frm_before_field_created', $field_values );
76 + $field_values = apply_filters( 'frm_before_field_created', $field_values );
84 77
85 - $field_id = FrmField::create( $field_values );
78 + $field_id = FrmField::create( $field_values );
86 79
87 - if ( ! $field_id ) {
88 - return false;
89 - }
80 + if ( ! $field_id ) {
81 + return false;
82 + }
90 83
91 84 $field = self::get_field_array_from_id( $field_id );
92 85
93 86 $values = array();
@@ -101,26 +94,66 @@
101 94 }
102 95
103 96 self::load_single_field( $field, $values, $form_id );
104 97
105 - return $field;
106 - }
98 + return $field;
99 + }
107 100
108 - public static function duplicate() {
101 + public static function update_ajax_option() {
109 102 FrmAppHelper::permission_check( 'frm_edit_forms' );
110 - check_ajax_referer( 'frm_ajax', 'nonce' );
103 + check_ajax_referer( 'frm_ajax', 'nonce' );
111 104
105 + $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
106 + if ( ! $field_id ) {
107 + wp_die();
108 + }
109 +
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 );
116 + }
117 +
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 + }
127 +
128 + public static function duplicate() {
129 + FrmAppHelper::permission_check( 'frm_edit_forms' );
130 + check_ajax_referer( 'frm_ajax', 'nonce' );
131 +
112 132 $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
113 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
133 + $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
114 134
115 - $new_field = FrmField::duplicate_single_field( $field_id, $form_id );
135 + $copy_field = FrmField::getOne( $field_id );
136 + if ( ! $copy_field ) {
137 + wp_die();
138 + }
116 139
117 - if ( is_array( $new_field ) && ! empty( $new_field['field_id'] ) ) {
118 - self::load_single_field( $new_field['field_id'], $new_field['values'] );
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 );
119 152 }
120 153
121 - wp_die();
122 - }
154 + wp_die();
155 + }
123 156
124 157 /**
125 158 * @since 3.0
126 159 *
@@ -129,9 +162,8 @@
129 162 * @return array
130 163 */
131 164 public static function get_field_array_from_id( $field_id ) {
132 165 $field = FrmField::getOne( $field_id );
133 -
134 166 return FrmFieldsHelper::setup_edit_vars( $field );
135 167 }
136 168
137 169 /**
@@ -147,16 +179,16 @@
147 179
148 180 if ( is_numeric( $field_object ) ) {
149 181 $field_object = FrmField::getOne( $field_object );
150 182 } elseif ( is_array( $field_object ) ) {
151 - $field = $field_object;
183 + $field = $field_object;
152 184 $field_object = FrmField::getOne( $field['id'] );
153 185 }
154 186
155 187 $field_obj = FrmFieldFactory::get_field_factory( $field_object );
156 - $display = self::display_field_options( array(), $field_obj );
188 + $display = self::display_field_options( array(), $field_obj );
157 189
158 - $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
190 + $ajax_loading = isset( $values['ajax_load'] ) && $values['ajax_load'];
159 191 $ajax_this_field = isset( $values['count'] ) && $values['count'] > 10 && ! in_array( $field_object->type, array( 'divider', 'end_divider' ) );
160 192
161 193 if ( $ajax_loading && $ajax_this_field ) {
162 194 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
@@ -161,11 +193,16 @@
161 193 if ( $ajax_loading && $ajax_this_field ) {
162 194 $li_classes = self::get_classes_for_builder_field( array(), $display, $field_obj );
163 195 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/ajax-field-placeholder.php' );
164 196 } else {
197 + $frm_settings = FrmAppHelper::get_settings();
198 +
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;
202 +
165 203 if ( ! isset( $field ) && is_object( $field_object ) ) {
166 204 $field_object->parent_form_id = isset( $values['id'] ) ? $values['id'] : $field_object->form_id;
167 -
168 205 $field = FrmFieldsHelper::setup_edit_vars( $field_object );
169 206 }
170 207
171 208 $li_classes = self::get_classes_for_builder_field( $field, $display, $field_obj );
@@ -178,35 +215,102 @@
178 215 /**
179 216 * @since 3.0
180 217 */
181 218 private static function get_classes_for_builder_field( $field, $display, $field_info ) {
182 - $li_classes = $field_info->form_builder_classes( $display['type'] );
183 - $li_classes .= ' frm_form_field frmstart ';
184 -
185 - if ( isset( $field['classes'] ) ) {
186 - $li_classes .= trim( $field['classes'] ) . ' ';
187 - }
188 -
189 - $li_classes .= 'frmend';
190 -
191 - if ( $field ) {
219 + $li_classes = $field_info->form_builder_classes( $display['type'] );
220 + if ( ! empty( $field ) ) {
192 221 $li_classes = apply_filters( 'frm_build_field_class', $li_classes, $field );
193 222 }
194 -
195 223 return $li_classes;
196 224 }
197 225
198 - public static function destroy() {
226 + public static function destroy() {
199 227 FrmAppHelper::permission_check( 'frm_edit_forms' );
200 - check_ajax_referer( 'frm_ajax', 'nonce' );
228 + check_ajax_referer( 'frm_ajax', 'nonce' );
201 229
202 230 $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' );
203 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 +
204 264 wp_die();
205 - }
265 + }
206 266
207 - /* Field Options */
267 + public static function import_choices() {
268 + FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' );
208 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 +
209 313 public static function import_options() {
210 314 FrmAppHelper::permission_check( 'frm_edit_forms' );
211 315 check_ajax_referer( 'frm_ajax', 'nonce' );
212 316
@@ -213,31 +317,30 @@
213 317 if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
214 318 return;
215 319 }
216 320
217 - $field_id = FrmAppHelper::get_param( 'field_id', '', 'post', 'absint' );
218 - $field = FrmField::getOne( $field_id );
321 + $field_id = absint( $_POST['field_id'] );
322 + $field = FrmField::getOne( $field_id );
219 323
220 324 if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) {
221 - return;
222 - }
325 + return;
326 + }
223 327
224 328 $field = FrmFieldsHelper::setup_edit_vars( $field );
225 - $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
226 - $opts = explode( "\n", rtrim( $opts, "\n" ) );
227 - $opts = array_map( 'trim', $opts );
329 + $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' );
330 + $opts = explode( "\n", rtrim( $opts, "\n" ) );
331 + $opts = array_map( 'trim', $opts );
228 332
229 - $separate = FrmAppHelper::get_param( 'separate', '', 'post', 'sanitize_text_field' );
230 - $field['separate_value'] = ( $separate === 'true' );
231 -
232 333 if ( $field['separate_value'] ) {
233 334 foreach ( $opts as $opt_key => $opt ) {
234 335 if ( strpos( $opt, '|' ) !== false ) {
235 336 $vals = explode( '|', $opt );
236 - $opts[ $opt_key ] = array(
237 - 'label' => trim( $vals[0] ),
238 - 'value' => trim( $vals[1] ),
239 - );
337 + if ( $vals[0] != $vals[1] ) {
338 + $opts[ $opt_key ] = array(
339 + 'label' => trim( $vals[0] ),
340 + 'value' => trim( $vals[1] ),
341 + );
342 + }
240 343 unset( $vals );
241 344 }
242 345 unset( $opt_key, $opt );
243 346 }
@@ -242,12 +345,12 @@
242 345 unset( $opt_key, $opt );
243 346 }
244 347 }
245 348
246 - // Keep other options after bulk update.
247 - if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) {
248 - $other_array = array();
249 - 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 ) {
250 353 if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) {
251 354 $other_array[ $opt_key ] = $opt;
252 355 }
253 356 unset( $opt_key, $opt );
@@ -256,147 +359,47 @@
256 359 $opts = array_merge( $opts, $other_array );
257 360 }
258 361 }
259 362
260 - $field['options'] = $opts;
363 + $field['options'] = $opts;
261 364
262 365 FrmFieldsHelper::show_single_option( $field );
263 366
264 - wp_die();
265 - }
367 + wp_die();
368 + }
266 369
267 - /**
268 - * @since 4.0
269 - *
270 - * @param array $atts - Includes field array, field_obj, display array, values array.
271 - */
272 - public static function load_single_field_settings( $atts ) {
273 - $field = $atts['field'];
274 - $field_obj = $atts['field_obj'];
275 - $values = $atts['values'];
276 - $display = $atts['display'];
277 - unset( $atts );
370 + public static function update_order() {
371 + FrmAppHelper::permission_check( 'frm_edit_forms' );
372 + check_ajax_referer( 'frm_ajax', 'nonce' );
278 373
279 - if ( ! isset( $field['unique'] ) ) {
280 - $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 ) ) );
281 377 }
378 + wp_die();
379 + }
282 380
283 - if ( ! isset( $field['read_only'] ) ) {
284 - $field['read_only'] = false;
285 - }
286 -
287 - $field_types = FrmFieldsHelper::get_field_types( $field['type'] );
288 - $pro_field_selection = FrmField::pro_field_selection();
289 - $all_field_types = array_merge( $pro_field_selection, FrmField::field_selection() );
290 - $disabled_fields = FrmAppHelper::pro_is_installed() ? array() : $pro_field_selection;
291 - $frm_settings = FrmAppHelper::get_settings();
292 -
293 - if ( ! isset( $all_field_types[ $field['type'] ] ) ) {
294 - // Add fallback for an add-on field type that has been deactivated.
295 - $all_field_types[ $field['type'] ] = array(
296 - 'name' => ucfirst( $field['type'] ),
297 - 'icon' => 'frm_icon_font frm_pencil_icon',
298 - );
299 - } elseif ( ! is_array( $all_field_types[ $field['type'] ] ) ) {
300 - // Fallback for fields added in a more basic way.
301 - FrmFormsHelper::prepare_field_type( $all_field_types[ $field['type'] ] );
302 - }
303 -
304 - $type_name = $all_field_types[ $field['type'] ]['name'];
305 - if ( $field['type'] === 'divider' && FrmField::is_option_true( $field, 'repeat' ) ) {
306 - $type_name = $all_field_types['divider|repeat']['name'];
307 - }
308 -
309 - if ( $display['default'] ) {
310 - $default_value_types = self::default_value_types( $field, compact( 'display' ) );
311 - }
312 -
313 - if ( $display['clear_on_focus'] && is_array( $field['placeholder'] ) ) {
314 - $field['placeholder'] = implode( ', ', $field['placeholder'] );
315 - }
316 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/settings.php' );
317 - }
318 -
319 - /**
320 - * Get the list of default value types that can be toggled in the builder.
321 - *
322 - * @since 4.0
323 - * @return array
324 - */
325 - private static function default_value_types( $field, $atts ) {
326 - $types = array(
327 - 'default_value' => array(
328 - 'class' => '',
329 - 'icon' => 'frm_icon_font frm_text2_icon',
330 - 'title' => __( 'Default Value (Text)', 'formidable' ),
331 - 'data' => array(
332 - 'frmshow' => '#default-value-for-',
333 - ),
334 - ),
335 - 'calc' => array(
336 - 'class' => 'frm_show_upgrade frm_noallow',
337 - 'title' => __( 'Default Value (Calculation)', 'formidable' ),
338 - 'icon' => 'frm_icon_font frm_calculator_icon',
339 - 'data' => array(
340 - 'medium' => 'calculations',
341 - 'upgrade' => __( 'Calculator forms', 'formidable' ),
342 - ),
343 - ),
344 - 'get_values_field' => array(
345 - 'class' => 'frm_show_upgrade frm_noallow',
346 - 'title' => __( 'Default Value (Lookup)', 'formidable' ),
347 - 'icon' => 'frm_icon_font frm_search_icon',
348 - 'data' => array(
349 - 'medium' => 'lookup',
350 - 'upgrade' => __( 'Lookup fields', 'formidable' ),
351 - ),
352 - ),
353 - );
354 -
355 - $types = apply_filters( 'frm_default_value_types', $types, $atts );
356 -
357 - if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
358 - // Prevent settings from showing in 2 spots.
359 - unset( $types['calc'], $types['get_values_field'] );
360 - }
361 -
362 - // Set active class.
363 - $settings = array_keys( $types );
364 - $active = 'default_value';
365 -
366 - foreach ( $settings as $type ) {
367 - if ( ! empty( $field[ $type ] ) ) {
368 - $active = $type;
369 - }
370 - }
371 -
372 - $types[ $active ]['class'] .= ' current';
373 - $types[ $active ]['current'] = true;
374 -
375 - return $types;
376 - }
377 -
378 381 public static function change_type( $type ) {
379 - $type_switch = array(
380 - 'scale' => 'radio',
381 - 'star' => 'radio',
382 - '10radio' => 'radio',
383 - 'rte' => 'textarea',
384 - 'website' => 'url',
385 - 'image' => 'url',
386 - );
387 - if ( isset( $type_switch[ $type ] ) ) {
388 - $type = $type_switch[ $type ];
389 - }
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 + }
390 393
391 394 $pro_fields = FrmField::pro_field_selection();
392 - $types = array_keys( $pro_fields );
395 + $types = array_keys( $pro_fields );
393 396 if ( in_array( $type, $types ) ) {
394 397 $type = 'text';
395 398 }
396 399
397 - return $type;
398 - }
400 + return $type;
401 + }
399 402
400 403 /**
401 404 * @param array $settings
402 405 * @param object $field_info
@@ -404,20 +407,19 @@
404 407 * @return array
405 408 */
406 409 public static function display_field_options( $settings, $field_info = null ) {
407 410 if ( $field_info ) {
408 - $settings = $field_info->display_field_settings();
411 + $settings = $field_info->display_field_settings();
409 412 $settings['field_data'] = $field_info->field;
410 413 }
411 414
412 415 return apply_filters( 'frm_display_field_options', $settings );
413 - }
416 + }
414 417
415 418 /**
416 419 * Display the format option
417 420 *
418 421 * @since 3.0
419 - *
420 422 * @param array $field
421 423 */
422 424 public static function show_format_option( $field ) {
423 425 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
@@ -422,10 +424,10 @@
422 424 public static function show_format_option( $field ) {
423 425 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/value-format.php' );
424 426 }
425 427
426 - public static function input_html( $field, $echo = true ) {
427 - $class = array();
428 + public static function input_html( $field, $echo = true ) {
429 + $class = array(); //$field['type'];
428 430 self::add_input_classes( $field, $class );
429 431
430 432 $add_html = array();
431 433 self::add_html_size( $field, $add_html );
@@ -442,14 +444,14 @@
442 444
443 445 $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field );
444 446 $add_html = ' ' . implode( ' ', $add_html ) . ' ';
445 447
446 - if ( $echo ) {
447 - echo $add_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
448 - }
448 + if ( $echo ) {
449 + echo $add_html; // WPCS: XSS ok.
450 + }
449 451
450 - return $add_html;
451 - }
452 + return $add_html;
453 + }
452 454
453 455 private static function add_input_classes( $field, array &$class ) {
454 456 if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
455 457 $class[] = $field['input_class'];
@@ -454,34 +456,25 @@
454 456 if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) {
455 457 $class[] = $field['input_class'];
456 458 }
457 459
458 - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
459 - return;
460 - }
460 + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) {
461 + return;
462 + }
461 463
462 464 if ( isset( $field['size'] ) && $field['size'] > 0 ) {
463 465 $class[] = 'auto_width';
464 466 }
465 - }
467 + }
466 468
467 469 private static function add_html_size( $field, array &$add_html ) {
468 - $size_fields = array(
469 - 'select',
470 - 'data',
471 - 'time',
472 - 'hidden',
473 - 'file',
474 - 'lookup',
475 - );
470 + if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden', 'file', 'lookup' ) ) ) {
471 + return;
472 + }
476 473
477 - if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], $size_fields ) ) {
478 - return;
479 - }
480 -
481 474 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
482 - return;
483 - }
475 + return;
476 + }
484 477
485 478 if ( is_numeric( $field['size'] ) ) {
486 479 $field['size'] .= 'px';
487 480 }
@@ -486,71 +479,70 @@
486 479 $field['size'] .= 'px';
487 480 }
488 481
489 482 $important = apply_filters( 'frm_use_important_width', 1, $field );
490 - // 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
491 484 $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"';
492 485
493 486 self::add_html_cols( $field, $add_html );
494 - }
487 + }
495 488
496 489 private static function add_html_cols( $field, array &$add_html ) {
497 490 if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) {
498 - return;
499 - }
491 + return;
492 + }
500 493
501 - // Convert to cols for textareas.
502 - $calc = array(
503 - '' => 9,
504 - 'px' => 9,
505 - 'rem' => 0.444,
506 - 'em' => 0.544,
507 - );
494 + // convert to cols for textareas
495 + $calc = array(
496 + '' => 9,
497 + 'px' => 9,
498 + 'rem' => 0.444,
499 + 'em' => 0.544,
500 + );
508 501
509 502 // include "col" for valid html
510 503 $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) );
511 504
512 - if ( ! isset( $calc[ $unit ] ) ) {
513 - return;
514 - }
505 + if ( ! isset( $calc[ $unit ] ) ) {
506 + return;
507 + }
515 508
516 - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
509 + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ];
517 510
518 511 $add_html['cols'] = 'cols="' . absint( $size ) . '"';
519 - }
512 + }
520 513
521 514 private static function add_html_length( $field, array &$add_html ) {
522 - // Check for max setting and if this field accepts maxlength.
523 - $fields = array(
524 - 'textarea',
525 - 'rte',
526 - 'hidden',
527 - 'file',
528 - );
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 + }
529 519
530 - if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], $fields ) ) {
531 - return;
532 - }
520 + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
521 + // don't load on form builder page
522 + return;
523 + }
533 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 ) {
534 529 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
535 - // Don't load on form builder page.
536 530 return;
537 531 }
538 532
539 - $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"';
540 - }
541 -
542 - private static function add_html_placeholder( $field, array &$add_html, array &$class ) {
543 - if ( $field['default_value'] != '' ) {
533 + if ( $field['default_value'] != '' && ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) {
544 534 if ( is_array( $field['default_value'] ) ) {
545 - $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'] ) . '"';
546 537 } else {
547 538 self::add_frmval_to_input( $field, $add_html );
548 539 }
540 + $field['default_value'] = '';
549 541 }
550 542
551 - $field['placeholder'] = self::prepare_placeholder( $field );
552 - if ( $field['placeholder'] == '' || is_array( $field['placeholder'] ) ) {
543 + $field['default_value'] = self::prepare_default_value( $field );
544 + if ( $field['default_value'] == '' || is_array( $field['default_value'] ) ) {
553 545 // don't include a json placeholder
554 546 return;
555 547 }
556 548
@@ -562,26 +554,26 @@
562 554 self::add_frmval_to_input( $field, $add_html );
563 555
564 556 $class[] = 'frm_toggle_default';
565 557
566 - if ( $field['value'] == $field['placeholder'] ) {
558 + if ( $field['value'] == $field['default_value'] ) {
567 559 $class[] = 'frm_default';
568 560 }
569 561 }
570 562 }
571 563
572 - /**
573 - * Prepares field placeholder.
574 - *
575 - * @since 5.4 This doesn't call `FrmFieldsController::get_default_value_from_name()` anymore.
576 - *
577 - * @param array $field Field array.
578 - * @return string
579 - */
580 - private static function prepare_placeholder( $field ) {
581 - $placeholder = isset( $field['placeholder'] ) ? $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' ) );
582 567
583 - return $placeholder;
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;
584 576 }
585 577
586 578 /**
587 579 * If the label position is "inside",
@@ -587,9 +579,8 @@
587 579 * If the label position is "inside",
588 580 * get the label to use as the placeholder
589 581 *
590 582 * @since 2.05
591 - * @since 5.4 Remove the logic code for "inside" label position.
592 583 *
593 584 * @param array $field
594 585 *
595 586 * @return string
@@ -594,34 +585,15 @@
594 585 *
595 586 * @return string
596 587 */
597 588 public static function get_default_value_from_name( $field ) {
598 - return '';
599 - }
600 -
601 - /**
602 - * Maybe add a blank placeholder option before any options
603 - * in a dropdown.
604 - *
605 - * @since 4.04
606 - * @return bool True if placeholder was added.
607 - */
608 - public static function add_placeholder_to_select( $field ) {
609 - $placeholder = FrmField::get_option( $field, 'placeholder' );
610 - if ( empty( $placeholder ) ) {
611 - $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 = '';
612 594 }
613 -
614 - if ( $placeholder !== '' ) {
615 - ?>
616 - <option value="">
617 - <?php echo esc_html( FrmField::get_option( $field, 'autocom' ) ? '' : $placeholder ); ?>
618 - </option>
619 - <?php
620 - return true;
621 - }
622 -
623 - return false;
595 + return $default_value;
624 596 }
625 597
626 598 /**
627 599 * Use HMTL5 placeholder with js fallback
@@ -630,122 +602,40 @@
630 602 * @param array $add_html
631 603 */
632 604 private static function add_placeholder_to_input( $field, &$add_html ) {
633 605 if ( FrmFieldsHelper::is_placeholder_field_type( $field['type'] ) ) {
634 - $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['placeholder'] ) . '"';
606 + $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"';
635 607 }
636 608 }
637 609
638 610 private static function add_frmval_to_input( $field, &$add_html ) {
639 - if ( $field['placeholder'] != '' ) {
640 - $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'] ) . '"';
641 613
642 614 if ( 'select' === $field['type'] ) {
643 - $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 + }
644 619 }
645 620 }
646 -
647 - if ( $field['default_value'] != '' ) {
648 - $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"';
649 - }
650 621 }
651 622
652 623 private static function add_validation_messages( $field, array &$add_html ) {
653 624 if ( FrmField::is_required( $field ) ) {
654 - $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
625 + $required_message = FrmFieldsHelper::get_error_msg( $field, 'blank' );
655 626 $add_html['data-reqmsg'] = 'data-reqmsg="' . esc_attr( $required_message ) . '"';
656 627 self::maybe_add_html_required( $field, $add_html );
657 628 }
658 629
659 630 if ( ! FrmField::is_option_empty( $field, 'invalid' ) ) {
660 - $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
631 + $invalid_message = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
661 632 $add_html['data-invmsg'] = 'data-invmsg="' . esc_attr( $invalid_message ) . '"';
662 633 }
663 -
664 - if ( ! empty( $add_html['data-reqmsg'] ) || ! empty( $add_html['data-invmsg'] ) ) {
665 - self::maybe_add_error_html_for_js_validation( $field, $add_html );
666 - }
667 634 }
668 635
669 636 /**
670 - * @since 5.0.03
671 - *
672 - * @param array $field
673 - * @param array $add_html
674 - */
675 - private static function maybe_add_error_html_for_js_validation( $field, array &$add_html ) {
676 - $form = self::get_form_for_js_validation( $field );
677 - if ( false === $form ) {
678 - return;
679 - }
680 -
681 - $error_body = self::pull_custom_error_body_from_custom_html( $form, $field );
682 - if ( false !== $error_body ) {
683 - $error_body = urlencode( $error_body );
684 - $add_html['data-error-html'] = 'data-error-html="' . esc_attr( $error_body ) . '"';
685 - }
686 - }
687 -
688 - /**
689 - * @since 5.0.03
690 - *
691 - * @param array $field
692 - * @return stdClass|false false if there is no form object found with JS validation active.
693 - */
694 - private static function get_form_for_js_validation( $field ) {
695 - global $frm_vars;
696 - if ( ! empty( $frm_vars['js_validate_forms'] ) ) {
697 - if ( isset( $frm_vars['js_validate_forms'][ $field['form_id'] ] ) ) {
698 - return $frm_vars['js_validate_forms'][ $field['form_id'] ];
699 - }
700 - if ( ! empty( $field['parent_form_id'] ) && isset( $frm_vars['js_validate_forms'][ $field['parent_form_id'] ] ) ) {
701 - return $frm_vars['js_validate_forms'][ $field['parent_form_id'] ];
702 - }
703 - }
704 - return false;
705 - }
706 -
707 - /**
708 - * @param stdClass $form
709 - * @param array $field
710 - * @param array $errors
711 - * @return string|false
712 - */
713 - public static function pull_custom_error_body_from_custom_html( $form, $field, $errors = array() ) {
714 - if ( empty( $field['custom_html'] ) ) {
715 - return false;
716 - }
717 -
718 - $custom_html = $field['custom_html'];
719 - $custom_html = apply_filters( 'frm_before_replace_shortcodes', $custom_html, $field, $errors, $form );
720 -
721 - $start = strpos( $custom_html, '[if error]' );
722 - if ( false === $start ) {
723 - return false;
724 - }
725 -
726 - $end = strpos( $custom_html, '[/if error]' );
727 - if ( false === $end || $end < $start ) {
728 - return false;
729 - }
730 -
731 - $error_body = substr( $custom_html, $start + 10, $end - $start - 10 );
732 - $default_html = array(
733 - '<div class="frm_error" id="frm_error_field_[key]">[error]</div>',
734 - '<div class="frm_error" role="alert" id="frm_error_field_[key]">[error]</div>',
735 - '<div class="frm_error">[error]</div>',
736 - '<div class="frm_error" role="alert">[error]</div>',
737 - );
738 -
739 - if ( in_array( $error_body, $default_html, true ) ) {
740 - return false;
741 - }
742 -
743 - return $error_body;
744 - }
745 -
746 - /**
747 - * 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
748 638 * submit in many browsers. Check to make sure the javascript to conditionally
749 639 * remove it is present if needed.
750 640 *
751 641 * @since 3.06.01
@@ -752,54 +642,49 @@
752 642 * @param array $field
753 643 * @param array $add_html
754 644 */
755 645 private static function maybe_add_html_required( $field, array &$add_html ) {
756 - if ( in_array( $field['type'], array( 'file', 'data', 'lookup' ), true ) ) {
646 + if ( in_array( $field['type'], array( 'radio', 'checkbox', 'file', 'data', 'lookup' ) ) ) {
757 647 return;
758 648 }
759 649
760 - $include_html = FrmAppHelper::meets_min_pro_version( '3.06.01' );
650 + $include_html = ! class_exists( 'FrmProDb' ) || version_compare( FrmProDb::$plug_version, '3.06', '>' );
761 651 if ( $include_html ) {
762 652 $add_html['aria-required'] = 'aria-required="true"';
763 653 }
764 654 }
765 655
766 - private static function add_shortcodes_to_html( $field, array &$add_html ) {
767 - if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
768 - return;
769 - }
656 + private static function add_shortcodes_to_html( $field, array &$add_html ) {
657 + if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) {
658 + return;
659 + }
770 660
771 - if ( ! empty( $field['autocomplete'] ) ) {
772 - unset( $field['shortcodes']['autocomplete'] );
773 - }
661 + foreach ( $field['shortcodes'] as $k => $v ) {
662 + if ( 'opt' === $k ) {
663 + continue;
664 + }
774 665
775 - foreach ( $field['shortcodes'] as $k => $v ) {
776 - if ( 'opt' === $k ) {
777 - continue;
778 - }
779 -
780 666 if ( is_numeric( $k ) && strpos( $v, '=' ) ) {
781 - $add_html[] = $v;
782 - } elseif ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
667 + $add_html[] = $v;
668 + } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) {
783 669 $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] );
784 - } else {
670 + } else {
785 671 $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"';
786 - }
672 + }
787 673
788 674 unset( $k, $v );
789 - }
790 - }
675 + }
676 + }
791 677
792 678 /**
793 679 * Add pattern attribute
794 680 *
795 681 * @since 3.0
796 - *
797 682 * @param array $field
798 683 * @param array $add_html
799 684 */
800 685 private static function add_pattern_attribute( $field, array &$add_html ) {
801 - $has_format = FrmField::is_option_true_in_array( $field, 'format' );
686 + $has_format = FrmField::is_option_true_in_array( $field, 'format' );
802 687 $format_field = FrmField::is_field_type( $field, 'text' );
803 688
804 689 if ( $field['type'] == 'phone' || ( $has_format && $format_field ) ) {
805 690 $frm_settings = FrmAppHelper::get_settings();
@@ -805,27 +690,25 @@
805 690 $frm_settings = FrmAppHelper::get_settings();
806 691
807 692 if ( $frm_settings->use_html ) {
808 693 $format = FrmEntryValidate::phone_format( $field );
809 - $format = substr( $format, 2, - 1 );
810 -
694 + $format = substr( $format, 2, -1 );
811 695 $add_html['pattern'] = 'pattern="' . esc_attr( $format ) . '"';
812 696 }
813 697 }
814 698 }
815 699
816 - public static function check_value( $opt, $opt_key, $field ) {
817 - if ( is_array( $opt ) ) {
818 - if ( FrmField::is_option_true( $field, 'separate_value' ) ) {
819 - $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
820 - } else {
821 - $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt );
822 - }
823 - }
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 + }
824 710
825 - return $opt;
826 - }
827 -
828 711 public static function check_label( $opt ) {
829 712 if ( is_array( $opt ) ) {
830 713 $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) );
831 714 }
@@ -833,64 +716,8 @@
833 716 return $opt;
834 717 }
835 718
836 719 /**
837 - * @deprecated 4.0
838 - */
839 - public static function update_ajax_option() {
840 - _deprecated_function( __METHOD__, '4.0' );
841 - FrmAppHelper::permission_check( 'frm_edit_forms' );
842 - check_ajax_referer( 'frm_ajax', 'nonce' );
843 -
844 - $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' );
845 - if ( ! $field_id ) {
846 - wp_die();
847 - }
848 -
849 - $field = FrmField::getOne( $field_id );
850 -
851 - if ( isset( $_POST['separate_value'] ) ) {
852 - $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1;
853 -
854 - $field->field_options['separate_value'] = $new_val;
855 - unset( $new_val );
856 - }
857 -
858 - FrmField::update(
859 - $field_id,
860 - array(
861 - 'field_options' => $field->field_options,
862 - 'form_id' => $field->form_id,
863 - )
864 - );
865 - wp_die();
866 - }
867 -
868 - /**
869 - * @deprecated 4.0
870 - */
871 - public static function import_choices() {
872 - _deprecated_function( __METHOD__, '4.0' );
873 - wp_die();
874 - }
875 -
876 - /**
877 - * Add Single Option or Other Option.
878 - *
879 - * @deprecated 4.0 Moved to Pro for Other option only.
880 - */
881 - public static function add_option() {
882 - _deprecated_function( __METHOD__, '4.0', 'FrmProFieldsController::add_other_option' );
883 - }
884 -
885 - /**
886 - * @deprecated 4.0
887 - */
888 - public static function update_order() {
889 - FrmDeprecated::update_order();
890 - }
891 -
892 - /**
893 720 * @deprecated 3.0
894 721 * @codeCoverageIgnore
895 722 */
896 723 public static function edit_name( $field = 'name', $id = '' ) {
@@ -908,6 +735,22 @@
908 735 * @return array
909 736 */
910 737 public static function include_single_field( $field_id, $values, $form_id = 0 ) {
911 738 return FrmDeprecated::include_single_field( $field_id, $values, $form_id );
739 + }
740 +
741 + /**
742 + * @deprecated 2.3
743 + * @codeCoverageIgnore
744 + */
745 + public static function edit_option() {
746 + FrmDeprecated::deprecated( __METHOD__, '2.3' );
747 + }
748 +
749 + /**
750 + * @deprecated 2.3
751 + * @codeCoverageIgnore
752 + */
753 + public static function delete_option() {
754 + FrmDeprecated::deprecated( __METHOD__, '2.3' );
912 755 }
913 756 }