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