@@ -2,59 +2,59 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmFieldsController { |
4 | 4 | |
5 | - public static function load_field() { |
|
5 | + public static function load_field() { |
|
6 | 6 | FrmAppHelper::permission_check('frm_edit_forms'); |
7 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
7 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
8 | 8 | |
9 | - $fields = $_POST['field']; |
|
10 | - if ( empty( $fields ) ) { |
|
11 | - wp_die(); |
|
12 | - } |
|
9 | + $fields = $_POST['field']; |
|
10 | + if ( empty( $fields ) ) { |
|
11 | + wp_die(); |
|
12 | + } |
|
13 | 13 | |
14 | - $_GET['page'] = 'formidable'; |
|
15 | - $fields = stripslashes_deep( $fields ); |
|
14 | + $_GET['page'] = 'formidable'; |
|
15 | + $fields = stripslashes_deep( $fields ); |
|
16 | 16 | |
17 | - $ajax = true; |
|
17 | + $ajax = true; |
|
18 | 18 | $values = array( 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ) ); |
19 | - $path = FrmAppHelper::plugin_path(); |
|
20 | - $field_html = array(); |
|
21 | - |
|
22 | - foreach ( $fields as $field ) { |
|
23 | - $field = htmlspecialchars_decode( nl2br( $field ) ); |
|
24 | - $field = json_decode( $field, true ); |
|
25 | - if ( ! isset( $field['id'] ) ) { |
|
26 | - // this field may have already been loaded |
|
27 | - continue; |
|
28 | - } |
|
19 | + $path = FrmAppHelper::plugin_path(); |
|
20 | + $field_html = array(); |
|
21 | + |
|
22 | + foreach ( $fields as $field ) { |
|
23 | + $field = htmlspecialchars_decode( nl2br( $field ) ); |
|
24 | + $field = json_decode( $field, true ); |
|
25 | + if ( ! isset( $field['id'] ) ) { |
|
26 | + // this field may have already been loaded |
|
27 | + continue; |
|
28 | + } |
|
29 | 29 | |
30 | - $field_id = absint( $field['id'] ); |
|
30 | + $field_id = absint( $field['id'] ); |
|
31 | 31 | |
32 | - if ( ! isset( $field['value'] ) ) { |
|
33 | - $field['value'] = ''; |
|
34 | - } |
|
32 | + if ( ! isset( $field['value'] ) ) { |
|
33 | + $field['value'] = ''; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | $field_name = 'item_meta[' . $field_id . ']'; |
37 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
37 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
38 | 38 | |
39 | - ob_start(); |
|
39 | + ob_start(); |
|
40 | 40 | include( $path . '/classes/views/frm-forms/add_field.php' ); |
41 | - $field_html[ $field_id ] = ob_get_contents(); |
|
42 | - ob_end_clean(); |
|
43 | - } |
|
41 | + $field_html[ $field_id ] = ob_get_contents(); |
|
42 | + ob_end_clean(); |
|
43 | + } |
|
44 | 44 | |
45 | - unset($path); |
|
45 | + unset($path); |
|
46 | 46 | |
47 | - echo json_encode($field_html); |
|
47 | + echo json_encode($field_html); |
|
48 | 48 | |
49 | - wp_die(); |
|
50 | - } |
|
49 | + wp_die(); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Create a new field with ajax |
54 | 54 | */ |
55 | - public static function create() { |
|
55 | + public static function create() { |
|
56 | 56 | FrmAppHelper::permission_check('frm_edit_forms'); |
57 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
57 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
58 | 58 | |
59 | 59 | $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); |
60 | 60 | $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); |
@@ -62,72 +62,72 @@ discard block |
||
62 | 62 | |
63 | 63 | $field = self::include_new_field( $field_type, $form_id, $section_id ); |
64 | 64 | |
65 | - // this hook will allow for multiple fields to be added at once |
|
66 | - do_action('frm_after_field_created', $field, $form_id); |
|
65 | + // this hook will allow for multiple fields to be added at once |
|
66 | + do_action('frm_after_field_created', $field, $form_id); |
|
67 | 67 | |
68 | - wp_die(); |
|
69 | - } |
|
68 | + wp_die(); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Set up and create a new field |
|
73 | - * |
|
74 | - * @param string $field_type |
|
75 | - * @param integer $form_id |
|
76 | - * @param int $section_id |
|
77 | - * @return array|bool |
|
78 | - */ |
|
71 | + /** |
|
72 | + * Set up and create a new field |
|
73 | + * |
|
74 | + * @param string $field_type |
|
75 | + * @param integer $form_id |
|
76 | + * @param int $section_id |
|
77 | + * @return array|bool |
|
78 | + */ |
|
79 | 79 | public static function include_new_field( $field_type, $form_id, $section_id = 0 ) { |
80 | - $values = array(); |
|
81 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
82 | - $values['post_type'] = FrmProFormsHelper::post_type($form_id); |
|
83 | - } |
|
80 | + $values = array(); |
|
81 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
82 | + $values['post_type'] = FrmProFormsHelper::post_type($form_id); |
|
83 | + } |
|
84 | 84 | |
85 | 85 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
86 | 86 | $field_values['field_options']['in_section'] = $section_id; |
87 | - $field_values = apply_filters( 'frm_before_field_created', $field_values ); |
|
87 | + $field_values = apply_filters( 'frm_before_field_created', $field_values ); |
|
88 | 88 | |
89 | - $field_id = FrmField::create( $field_values ); |
|
89 | + $field_id = FrmField::create( $field_values ); |
|
90 | 90 | |
91 | - if ( ! $field_id ) { |
|
92 | - return false; |
|
93 | - } |
|
91 | + if ( ! $field_id ) { |
|
92 | + return false; |
|
93 | + } |
|
94 | 94 | |
95 | - $field = self::include_single_field($field_id, $values, $form_id); |
|
95 | + $field = self::include_single_field($field_id, $values, $form_id); |
|
96 | 96 | |
97 | - return $field; |
|
98 | - } |
|
97 | + return $field; |
|
98 | + } |
|
99 | 99 | |
100 | 100 | public static function edit_name( $field = 'name', $id = '' ) { |
101 | 101 | FrmAppHelper::permission_check('frm_edit_forms'); |
102 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
102 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
103 | 103 | |
104 | - if ( empty($field) ) { |
|
105 | - $field = 'name'; |
|
106 | - } |
|
104 | + if ( empty($field) ) { |
|
105 | + $field = 'name'; |
|
106 | + } |
|
107 | 107 | |
108 | - if ( empty($id) ) { |
|
108 | + if ( empty($id) ) { |
|
109 | 109 | $id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' ); |
110 | 110 | $id = str_replace( 'field_label_', '', $id ); |
111 | - } |
|
111 | + } |
|
112 | 112 | |
113 | 113 | $value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' ); |
114 | 114 | $value = trim( $value ); |
115 | - if ( trim(strip_tags($value)) == '' ) { |
|
116 | - // set blank value if there is no content |
|
117 | - $value = ''; |
|
118 | - } |
|
115 | + if ( trim(strip_tags($value)) == '' ) { |
|
116 | + // set blank value if there is no content |
|
117 | + $value = ''; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | FrmField::update( $id, array( $field => $value ) ); |
121 | 121 | |
122 | 122 | do_action( 'frm_after_update_field_' . $field, compact( 'id', 'value' ) ); |
123 | 123 | |
124 | 124 | echo stripslashes( wp_kses_post( $value ) ); |
125 | - wp_die(); |
|
126 | - } |
|
125 | + wp_die(); |
|
126 | + } |
|
127 | 127 | |
128 | - public static function update_ajax_option() { |
|
128 | + public static function update_ajax_option() { |
|
129 | 129 | FrmAppHelper::permission_check('frm_edit_forms'); |
130 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
130 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
131 | 131 | |
132 | 132 | $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' ); |
133 | 133 | if ( ! $field_id ) { |
@@ -142,141 +142,141 @@ discard block |
||
142 | 142 | unset($new_val); |
143 | 143 | } |
144 | 144 | |
145 | - FrmField::update( $field_id, array( |
|
146 | - 'field_options' => $field->field_options, |
|
145 | + FrmField::update( $field_id, array( |
|
146 | + 'field_options' => $field->field_options, |
|
147 | 147 | 'form_id' => $field->form_id, |
148 | - ) ); |
|
149 | - wp_die(); |
|
150 | - } |
|
148 | + ) ); |
|
149 | + wp_die(); |
|
150 | + } |
|
151 | 151 | |
152 | - public static function duplicate() { |
|
152 | + public static function duplicate() { |
|
153 | 153 | FrmAppHelper::permission_check('frm_edit_forms'); |
154 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
154 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
155 | 155 | |
156 | - global $wpdb; |
|
156 | + global $wpdb; |
|
157 | 157 | |
158 | 158 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
159 | 159 | $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); |
160 | 160 | |
161 | 161 | $copy_field = FrmField::getOne( $field_id ); |
162 | - if ( ! $copy_field ) { |
|
163 | - wp_die(); |
|
164 | - } |
|
162 | + if ( ! $copy_field ) { |
|
163 | + wp_die(); |
|
164 | + } |
|
165 | 165 | |
166 | 166 | do_action( 'frm_duplicate_field', $copy_field, $form_id ); |
167 | 167 | do_action( 'frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id ); |
168 | 168 | |
169 | - $values = array( 'id' => $form_id ); |
|
170 | - FrmFieldsHelper::fill_field( $values, $copy_field, $form_id ); |
|
169 | + $values = array( 'id' => $form_id ); |
|
170 | + FrmFieldsHelper::fill_field( $values, $copy_field, $form_id ); |
|
171 | 171 | |
172 | 172 | $field_count = FrmDb::get_count( $wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array( 'or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id ) ); |
173 | 173 | |
174 | - $values['field_order'] = $field_count + 1; |
|
174 | + $values['field_order'] = $field_count + 1; |
|
175 | 175 | |
176 | - if ( ! $field_id = FrmField::create($values) ) { |
|
177 | - wp_die(); |
|
178 | - } |
|
176 | + if ( ! $field_id = FrmField::create($values) ) { |
|
177 | + wp_die(); |
|
178 | + } |
|
179 | 179 | |
180 | - self::include_single_field($field_id, $values); |
|
180 | + self::include_single_field($field_id, $values); |
|
181 | 181 | |
182 | - wp_die(); |
|
183 | - } |
|
182 | + wp_die(); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Load a single field in the form builder along with all needed variables |
|
187 | - */ |
|
188 | - public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
189 | - $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
185 | + /** |
|
186 | + * Load a single field in the form builder along with all needed variables |
|
187 | + */ |
|
188 | + public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
189 | + $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
190 | 190 | $field_name = 'item_meta[' . $field_id . ']'; |
191 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
192 | - $id = $form_id ? $form_id : $field['form_id']; |
|
193 | - if ( $field['type'] == 'html' ) { |
|
194 | - $field['stop_filter'] = true; |
|
195 | - } |
|
191 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
192 | + $id = $form_id ? $form_id : $field['form_id']; |
|
193 | + if ( $field['type'] == 'html' ) { |
|
194 | + $field['stop_filter'] = true; |
|
195 | + } |
|
196 | 196 | |
197 | 197 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' ); |
198 | 198 | |
199 | - return $field; |
|
200 | - } |
|
199 | + return $field; |
|
200 | + } |
|
201 | 201 | |
202 | - public static function destroy() { |
|
202 | + public static function destroy() { |
|
203 | 203 | FrmAppHelper::permission_check('frm_edit_forms'); |
204 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
204 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
205 | 205 | |
206 | 206 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
207 | 207 | FrmField::destroy( $field_id ); |
208 | - wp_die(); |
|
209 | - } |
|
208 | + wp_die(); |
|
209 | + } |
|
210 | 210 | |
211 | - /* Field Options */ |
|
211 | + /* Field Options */ |
|
212 | 212 | |
213 | - //Add Single Option or Other Option |
|
214 | - public static function add_option() { |
|
213 | + //Add Single Option or Other Option |
|
214 | + public static function add_option() { |
|
215 | 215 | FrmAppHelper::permission_check('frm_edit_forms'); |
216 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
216 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
217 | 217 | |
218 | 218 | $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
219 | 219 | $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' ); |
220 | 220 | |
221 | - //Get the field |
|
222 | - $field = FrmField::getOne($id); |
|
221 | + //Get the field |
|
222 | + $field = FrmField::getOne($id); |
|
223 | 223 | |
224 | 224 | if ( ! empty( $field->options ) ) { |
225 | 225 | $keys = array_keys( $field->options ); |
226 | - $last = str_replace( 'other_', '', end( $keys ) ); |
|
227 | - } else { |
|
228 | - $last = 0; |
|
229 | - } |
|
230 | - $opt_key = $last + 1; |
|
226 | + $last = str_replace( 'other_', '', end( $keys ) ); |
|
227 | + } else { |
|
228 | + $last = 0; |
|
229 | + } |
|
230 | + $opt_key = $last + 1; |
|
231 | 231 | |
232 | - if ( 'other' == $opt_type ) { |
|
232 | + if ( 'other' == $opt_type ) { |
|
233 | 233 | $opt = esc_html__( 'Other', 'formidable' ); |
234 | - $other_val = ''; |
|
235 | - $opt_key = 'other_' . $opt_key; |
|
236 | - |
|
237 | - //Update value of "other" in DB |
|
238 | - $field_options = maybe_unserialize( $field->field_options ); |
|
239 | - $field_options['other'] = 1; |
|
240 | - FrmField::update( $id, array( 'field_options' => maybe_serialize( $field_options ) ) ); |
|
241 | - } else { |
|
234 | + $other_val = ''; |
|
235 | + $opt_key = 'other_' . $opt_key; |
|
236 | + |
|
237 | + //Update value of "other" in DB |
|
238 | + $field_options = maybe_unserialize( $field->field_options ); |
|
239 | + $field_options['other'] = 1; |
|
240 | + FrmField::update( $id, array( 'field_options' => maybe_serialize( $field_options ) ) ); |
|
241 | + } else { |
|
242 | 242 | $first_opt = reset( $field->options ); |
243 | 243 | $next_opt = count( $field->options ); |
244 | - if ( $first_opt != '' ) { |
|
245 | - $next_opt++; |
|
246 | - } |
|
244 | + if ( $first_opt != '' ) { |
|
245 | + $next_opt++; |
|
246 | + } |
|
247 | 247 | $opt = esc_html__( 'Option', 'formidable' ) . ' ' . $next_opt; |
248 | - unset($next_opt); |
|
249 | - } |
|
250 | - $field_val = $opt; |
|
248 | + unset($next_opt); |
|
249 | + } |
|
250 | + $field_val = $opt; |
|
251 | 251 | $field->options[ $opt_key ] = $opt; |
252 | 252 | |
253 | - //Update options in DB |
|
253 | + //Update options in DB |
|
254 | 254 | FrmField::update( $id, array( 'options' => $field->options ) ); |
255 | 255 | |
256 | - $field_data = $field; |
|
257 | - $field = array( |
|
258 | - 'type' => $field_data->type, |
|
259 | - 'id' => $id, |
|
260 | - 'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0, |
|
261 | - 'form_id' => $field_data->form_id, |
|
262 | - 'field_key' => $field_data->field_key, |
|
263 | - ); |
|
256 | + $field_data = $field; |
|
257 | + $field = array( |
|
258 | + 'type' => $field_data->type, |
|
259 | + 'id' => $id, |
|
260 | + 'separate_value' => isset($field_data->field_options['separate_value']) ? $field_data->field_options['separate_value'] : 0, |
|
261 | + 'form_id' => $field_data->form_id, |
|
262 | + 'field_key' => $field_data->field_key, |
|
263 | + ); |
|
264 | 264 | |
265 | 265 | $field_name = 'item_meta[' . $id . ']'; |
266 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
267 | - $checked = ''; |
|
266 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
267 | + $checked = ''; |
|
268 | 268 | |
269 | - if ( 'other' == $opt_type ) { |
|
269 | + if ( 'other' == $opt_type ) { |
|
270 | 270 | require( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' ); |
271 | - } else { |
|
271 | + } else { |
|
272 | 272 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
273 | - } |
|
274 | - wp_die(); |
|
275 | - } |
|
273 | + } |
|
274 | + wp_die(); |
|
275 | + } |
|
276 | 276 | |
277 | - public static function edit_option() { |
|
277 | + public static function edit_option() { |
|
278 | 278 | FrmAppHelper::permission_check('frm_edit_forms'); |
279 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
279 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
280 | 280 | |
281 | 281 | $element_id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' ); |
282 | 282 | $ids = explode( '-', $element_id ); |
@@ -284,43 +284,43 @@ discard block |
||
284 | 284 | |
285 | 285 | $orig_update_value = $update_value = trim( FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' ) ); |
286 | 286 | if ( strpos( $element_id, 'key_' ) ) { |
287 | - $new_value = $update_value; |
|
288 | - } else { |
|
289 | - $new_label = $update_value; |
|
290 | - } |
|
287 | + $new_value = $update_value; |
|
288 | + } else { |
|
289 | + $new_label = $update_value; |
|
290 | + } |
|
291 | 291 | |
292 | - $field = FrmField::getOne($id); |
|
293 | - $separate_values = FrmField::is_option_true( $field, 'separate_value' ); |
|
292 | + $field = FrmField::getOne($id); |
|
293 | + $separate_values = FrmField::is_option_true( $field, 'separate_value' ); |
|
294 | 294 | |
295 | - $this_opt_id = end($ids); |
|
295 | + $this_opt_id = end($ids); |
|
296 | 296 | $this_opt = (array) $field->options[ $this_opt_id ]; |
297 | 297 | $other_opt = ( $this_opt_id && strpos( $this_opt_id, 'other') !== false ); |
298 | 298 | |
299 | - $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt); |
|
300 | - $value = isset($this_opt['value']) ? $this_opt['value'] : ''; |
|
299 | + $label = isset($this_opt['label']) ? $this_opt['label'] : reset($this_opt); |
|
300 | + $value = isset($this_opt['value']) ? $this_opt['value'] : ''; |
|
301 | 301 | |
302 | - if ( ! isset( $new_label ) ) { |
|
303 | - $new_label = $label; |
|
304 | - } |
|
302 | + if ( ! isset( $new_label ) ) { |
|
303 | + $new_label = $label; |
|
304 | + } |
|
305 | 305 | |
306 | - if ( isset($new_value) || isset($value) ) { |
|
307 | - $update_value = isset($new_value) ? $new_value : $value; |
|
308 | - } |
|
306 | + if ( isset($new_value) || isset($value) ) { |
|
307 | + $update_value = isset($new_value) ? $new_value : $value; |
|
308 | + } |
|
309 | 309 | |
310 | 310 | if ( $update_value != $new_label && $other_opt === false && $separate_values ) { |
311 | 311 | $field->options[ $this_opt_id ] = array( 'value' => $update_value, 'label' => $new_label ); |
312 | - } else { |
|
312 | + } else { |
|
313 | 313 | $field->options[ $this_opt_id ] = $orig_update_value; |
314 | - } |
|
314 | + } |
|
315 | 315 | |
316 | 316 | FrmField::update( $field->id, array( 'options' => $field->options ) ); |
317 | 317 | echo ( $orig_update_value == '' ) ? esc_html__( '(Blank)', 'formidable' ) : stripslashes( $orig_update_value ); |
318 | - wp_die(); |
|
319 | - } |
|
318 | + wp_die(); |
|
319 | + } |
|
320 | 320 | |
321 | - public static function delete_option() { |
|
321 | + public static function delete_option() { |
|
322 | 322 | FrmAppHelper::permission_check('frm_edit_forms'); |
323 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
323 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
324 | 324 | |
325 | 325 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
326 | 326 | $field = FrmField::getOne( $field_id ); |
@@ -328,310 +328,310 @@ discard block |
||
328 | 328 | $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'sanitize_title' ); |
329 | 329 | |
330 | 330 | $options = $field->options; |
331 | - unset( $options[ $opt_key ] ); |
|
332 | - $response = array( 'other' => true ); |
|
331 | + unset( $options[ $opt_key ] ); |
|
332 | + $response = array( 'other' => true ); |
|
333 | 333 | |
334 | - //If the deleted option is an "other" option |
|
334 | + //If the deleted option is an "other" option |
|
335 | 335 | if ( FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
336 | - //Assume all other options are gone, unless proven otherwise |
|
337 | - $other = false; |
|
336 | + //Assume all other options are gone, unless proven otherwise |
|
337 | + $other = false; |
|
338 | 338 | |
339 | - //Check if all other options are really gone |
|
340 | - foreach ( $options as $o_key => $o_val ) { |
|
341 | - //If there is still an other option in the field, set other to true |
|
339 | + //Check if all other options are really gone |
|
340 | + foreach ( $options as $o_key => $o_val ) { |
|
341 | + //If there is still an other option in the field, set other to true |
|
342 | 342 | if ( FrmFieldsHelper::is_other_opt( $o_key ) ) { |
343 | - $other = true; |
|
344 | - break; |
|
345 | - } |
|
346 | - unset( $o_key, $o_val ); |
|
347 | - } |
|
348 | - |
|
349 | - //If all other options are gone |
|
350 | - if ( false === $other ) { |
|
351 | - $field_options = maybe_unserialize( $field->field_options ); |
|
352 | - $field_options['other'] = 0; |
|
343 | + $other = true; |
|
344 | + break; |
|
345 | + } |
|
346 | + unset( $o_key, $o_val ); |
|
347 | + } |
|
348 | + |
|
349 | + //If all other options are gone |
|
350 | + if ( false === $other ) { |
|
351 | + $field_options = maybe_unserialize( $field->field_options ); |
|
352 | + $field_options['other'] = 0; |
|
353 | 353 | FrmField::update( $field_id, array( 'field_options' => maybe_serialize( $field_options ) ) ); |
354 | - $response = array( 'other' => false ); |
|
355 | - } |
|
356 | - } |
|
357 | - echo json_encode( $response ); |
|
354 | + $response = array( 'other' => false ); |
|
355 | + } |
|
356 | + } |
|
357 | + echo json_encode( $response ); |
|
358 | 358 | |
359 | 359 | FrmField::update( $field_id, array( 'options' => maybe_serialize( $options ) ) ); |
360 | 360 | |
361 | - wp_die(); |
|
362 | - } |
|
361 | + wp_die(); |
|
362 | + } |
|
363 | 363 | |
364 | - public static function import_choices() { |
|
365 | - FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
364 | + public static function import_choices() { |
|
365 | + FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
366 | 366 | |
367 | 367 | $field_id = absint( $_REQUEST['field_id'] ); |
368 | 368 | |
369 | - global $current_screen, $hook_suffix; |
|
369 | + global $current_screen, $hook_suffix; |
|
370 | 370 | |
371 | - // Catch plugins that include admin-header.php before admin.php completes. |
|
372 | - if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
373 | - $hook_suffix = ''; |
|
374 | - set_current_screen(); |
|
375 | - } |
|
371 | + // Catch plugins that include admin-header.php before admin.php completes. |
|
372 | + if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
373 | + $hook_suffix = ''; |
|
374 | + set_current_screen(); |
|
375 | + } |
|
376 | 376 | |
377 | - if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
378 | - register_admin_color_schemes(); |
|
379 | - } |
|
377 | + if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
378 | + register_admin_color_schemes(); |
|
379 | + } |
|
380 | 380 | |
381 | - $hook_suffix = $admin_body_class = ''; |
|
381 | + $hook_suffix = $admin_body_class = ''; |
|
382 | 382 | |
383 | - if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
384 | - $admin_body_class .= ' folded'; |
|
385 | - } |
|
383 | + if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
384 | + $admin_body_class .= ' folded'; |
|
385 | + } |
|
386 | 386 | |
387 | - if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
388 | - $admin_body_class .= ' admin-bar'; |
|
389 | - } |
|
387 | + if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
388 | + $admin_body_class .= ' admin-bar'; |
|
389 | + } |
|
390 | 390 | |
391 | - if ( is_rtl() ) { |
|
392 | - $admin_body_class .= ' rtl'; |
|
393 | - } |
|
391 | + if ( is_rtl() ) { |
|
392 | + $admin_body_class .= ' rtl'; |
|
393 | + } |
|
394 | 394 | |
395 | - $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
396 | - $prepop = array(); |
|
397 | - FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
395 | + $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
396 | + $prepop = array(); |
|
397 | + FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
398 | 398 | |
399 | - $field = FrmField::getOne($field_id); |
|
399 | + $field = FrmField::getOne($field_id); |
|
400 | 400 | |
401 | - wp_enqueue_script( 'utils' ); |
|
401 | + wp_enqueue_script( 'utils' ); |
|
402 | 402 | wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' ); |
403 | - FrmAppHelper::load_admin_wide_js(); |
|
403 | + FrmAppHelper::load_admin_wide_js(); |
|
404 | 404 | |
405 | 405 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/import_choices.php' ); |
406 | - wp_die(); |
|
407 | - } |
|
406 | + wp_die(); |
|
407 | + } |
|
408 | 408 | |
409 | - public static function import_options() { |
|
409 | + public static function import_options() { |
|
410 | 410 | FrmAppHelper::permission_check('frm_edit_forms'); |
411 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
411 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
412 | 412 | |
413 | - if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
414 | - return; |
|
415 | - } |
|
413 | + if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
414 | + return; |
|
415 | + } |
|
416 | 416 | |
417 | 417 | $field_id = absint( $_POST['field_id'] ); |
418 | - $field = FrmField::getOne($field_id); |
|
418 | + $field = FrmField::getOne($field_id); |
|
419 | 419 | |
420 | 420 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { |
421 | - return; |
|
422 | - } |
|
423 | - |
|
424 | - $field = FrmFieldsHelper::setup_edit_vars($field); |
|
425 | - $opts = stripslashes_deep($_POST['opts']); |
|
426 | - $opts = explode("\n", rtrim($opts, "\n")); |
|
427 | - if ( $field['separate_value'] ) { |
|
428 | - foreach ( $opts as $opt_key => $opt ) { |
|
429 | - if ( strpos($opt, '|') !== false ) { |
|
430 | - $vals = explode('|', $opt); |
|
431 | - if ( $vals[0] != $vals[1] ) { |
|
432 | - $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
433 | - } |
|
434 | - unset($vals); |
|
435 | - } |
|
436 | - unset($opt_key, $opt); |
|
437 | - } |
|
438 | - } |
|
439 | - |
|
440 | - //Keep other options after bulk update |
|
441 | - if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
442 | - $other_array = array(); |
|
443 | - foreach ( $field['options'] as $opt_key => $opt ) { |
|
444 | - if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
|
445 | - $other_array[ $opt_key ] = $opt; |
|
446 | - } |
|
447 | - unset($opt_key, $opt); |
|
448 | - } |
|
449 | - if ( ! empty($other_array) ) { |
|
450 | - $opts = array_merge( $opts, $other_array); |
|
451 | - } |
|
452 | - } |
|
453 | - |
|
454 | - FrmField::update( $field_id, array( 'options' => maybe_serialize( $opts ) ) ); |
|
455 | - |
|
456 | - $field['options'] = $opts; |
|
457 | - $field_name = $field['name']; |
|
458 | - |
|
459 | - // Get html_id which will be used in single-option.php |
|
460 | - $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
461 | - |
|
462 | - if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
421 | + return; |
|
422 | + } |
|
423 | + |
|
424 | + $field = FrmFieldsHelper::setup_edit_vars($field); |
|
425 | + $opts = stripslashes_deep($_POST['opts']); |
|
426 | + $opts = explode("\n", rtrim($opts, "\n")); |
|
427 | + if ( $field['separate_value'] ) { |
|
428 | + foreach ( $opts as $opt_key => $opt ) { |
|
429 | + if ( strpos($opt, '|') !== false ) { |
|
430 | + $vals = explode('|', $opt); |
|
431 | + if ( $vals[0] != $vals[1] ) { |
|
432 | + $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
433 | + } |
|
434 | + unset($vals); |
|
435 | + } |
|
436 | + unset($opt_key, $opt); |
|
437 | + } |
|
438 | + } |
|
439 | + |
|
440 | + //Keep other options after bulk update |
|
441 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
442 | + $other_array = array(); |
|
443 | + foreach ( $field['options'] as $opt_key => $opt ) { |
|
444 | + if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
|
445 | + $other_array[ $opt_key ] = $opt; |
|
446 | + } |
|
447 | + unset($opt_key, $opt); |
|
448 | + } |
|
449 | + if ( ! empty($other_array) ) { |
|
450 | + $opts = array_merge( $opts, $other_array); |
|
451 | + } |
|
452 | + } |
|
453 | + |
|
454 | + FrmField::update( $field_id, array( 'options' => maybe_serialize( $opts ) ) ); |
|
455 | + |
|
456 | + $field['options'] = $opts; |
|
457 | + $field_name = $field['name']; |
|
458 | + |
|
459 | + // Get html_id which will be used in single-option.php |
|
460 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
461 | + |
|
462 | + if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
463 | 463 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); |
464 | - } else { |
|
465 | - FrmFieldsHelper::show_single_option($field); |
|
466 | - } |
|
464 | + } else { |
|
465 | + FrmFieldsHelper::show_single_option($field); |
|
466 | + } |
|
467 | 467 | |
468 | - wp_die(); |
|
469 | - } |
|
468 | + wp_die(); |
|
469 | + } |
|
470 | 470 | |
471 | - public static function update_order() { |
|
471 | + public static function update_order() { |
|
472 | 472 | FrmAppHelper::permission_check('frm_edit_forms'); |
473 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
473 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
474 | 474 | |
475 | 475 | $fields = FrmAppHelper::get_post_param( 'frm_field_id' ); |
476 | 476 | foreach ( (array) $fields as $position => $item ) { |
477 | 477 | FrmField::update( absint( $item ), array( 'field_order' => absint( $position ) ) ); |
478 | 478 | } |
479 | - wp_die(); |
|
480 | - } |
|
479 | + wp_die(); |
|
480 | + } |
|
481 | 481 | |
482 | 482 | public static function change_type( $type ) { |
483 | - $type_switch = array( |
|
484 | - 'scale' => 'radio', |
|
485 | - '10radio' => 'radio', |
|
486 | - 'rte' => 'textarea', |
|
487 | - 'website' => 'url', |
|
488 | - ); |
|
489 | - if ( isset( $type_switch[ $type ] ) ) { |
|
490 | - $type = $type_switch[ $type ]; |
|
491 | - } |
|
483 | + $type_switch = array( |
|
484 | + 'scale' => 'radio', |
|
485 | + '10radio' => 'radio', |
|
486 | + 'rte' => 'textarea', |
|
487 | + 'website' => 'url', |
|
488 | + ); |
|
489 | + if ( isset( $type_switch[ $type ] ) ) { |
|
490 | + $type = $type_switch[ $type ]; |
|
491 | + } |
|
492 | 492 | |
493 | 493 | $frm_field_selection = FrmField::field_selection(); |
494 | - $types = array_keys($frm_field_selection); |
|
495 | - if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
496 | - $type = 'text'; |
|
497 | - } |
|
494 | + $types = array_keys($frm_field_selection); |
|
495 | + if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
496 | + $type = 'text'; |
|
497 | + } |
|
498 | 498 | |
499 | - return $type; |
|
500 | - } |
|
499 | + return $type; |
|
500 | + } |
|
501 | 501 | |
502 | 502 | public static function display_field_options( $display ) { |
503 | 503 | switch ( $display['type'] ) { |
504 | - case 'captcha': |
|
505 | - $display['required'] = false; |
|
506 | - $display['invalid'] = true; |
|
507 | - $display['default_blank'] = false; |
|
504 | + case 'captcha': |
|
505 | + $display['required'] = false; |
|
506 | + $display['invalid'] = true; |
|
507 | + $display['default_blank'] = false; |
|
508 | 508 | $display['captcha_size'] = true; |
509 | - break; |
|
510 | - case 'radio': |
|
511 | - $display['default_blank'] = false; |
|
512 | - break; |
|
513 | - case 'text': |
|
514 | - case 'textarea': |
|
515 | - $display['size'] = true; |
|
516 | - $display['clear_on_focus'] = true; |
|
517 | - break; |
|
518 | - case 'select': |
|
519 | - $display['size'] = true; |
|
520 | - break; |
|
521 | - case 'url': |
|
522 | - case 'website': |
|
523 | - case 'email': |
|
524 | - $display['size'] = true; |
|
525 | - $display['clear_on_focus'] = true; |
|
526 | - $display['invalid'] = true; |
|
527 | - } |
|
528 | - |
|
529 | - return $display; |
|
530 | - } |
|
531 | - |
|
532 | - public static function input_html( $field, $echo = true ) { |
|
533 | - $class = array(); //$field['type']; |
|
534 | - self::add_input_classes($field, $class); |
|
535 | - |
|
536 | - $add_html = array(); |
|
537 | - self::add_html_size($field, $add_html); |
|
538 | - self::add_html_length($field, $add_html); |
|
539 | - self::add_html_placeholder($field, $add_html, $class); |
|
509 | + break; |
|
510 | + case 'radio': |
|
511 | + $display['default_blank'] = false; |
|
512 | + break; |
|
513 | + case 'text': |
|
514 | + case 'textarea': |
|
515 | + $display['size'] = true; |
|
516 | + $display['clear_on_focus'] = true; |
|
517 | + break; |
|
518 | + case 'select': |
|
519 | + $display['size'] = true; |
|
520 | + break; |
|
521 | + case 'url': |
|
522 | + case 'website': |
|
523 | + case 'email': |
|
524 | + $display['size'] = true; |
|
525 | + $display['clear_on_focus'] = true; |
|
526 | + $display['invalid'] = true; |
|
527 | + } |
|
528 | + |
|
529 | + return $display; |
|
530 | + } |
|
531 | + |
|
532 | + public static function input_html( $field, $echo = true ) { |
|
533 | + $class = array(); //$field['type']; |
|
534 | + self::add_input_classes($field, $class); |
|
535 | + |
|
536 | + $add_html = array(); |
|
537 | + self::add_html_size($field, $add_html); |
|
538 | + self::add_html_length($field, $add_html); |
|
539 | + self::add_html_placeholder($field, $add_html, $class); |
|
540 | 540 | self::add_validation_messages( $field, $add_html ); |
541 | 541 | |
542 | - $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
542 | + $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
543 | 543 | |
544 | 544 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
545 | 545 | |
546 | - self::add_shortcodes_to_html($field, $add_html); |
|
546 | + self::add_shortcodes_to_html($field, $add_html); |
|
547 | 547 | |
548 | 548 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
549 | 549 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
550 | 550 | |
551 | - if ( $echo ) { |
|
552 | - echo $add_html; |
|
553 | - } |
|
551 | + if ( $echo ) { |
|
552 | + echo $add_html; |
|
553 | + } |
|
554 | 554 | |
555 | - return $add_html; |
|
556 | - } |
|
555 | + return $add_html; |
|
556 | + } |
|
557 | 557 | |
558 | 558 | private static function add_input_classes( $field, array &$class ) { |
559 | - if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
560 | - $class[] = $field['input_class']; |
|
561 | - } |
|
559 | + if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
560 | + $class[] = $field['input_class']; |
|
561 | + } |
|
562 | 562 | |
563 | - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
564 | - return; |
|
565 | - } |
|
563 | + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
564 | + return; |
|
565 | + } |
|
566 | 566 | |
567 | - global $frm_vars; |
|
567 | + global $frm_vars; |
|
568 | 568 | if ( is_admin() && ! FrmAppHelper::is_preview_page() && ! in_array( $field['type'], array( 'scale', 'radio', 'checkbox', 'data' ) ) ) { |
569 | - $class[] = 'dyn_default_value'; |
|
570 | - } |
|
569 | + $class[] = 'dyn_default_value'; |
|
570 | + } |
|
571 | 571 | |
572 | - if ( isset($field['size']) && $field['size'] > 0 ) { |
|
573 | - $class[] = 'auto_width'; |
|
574 | - } |
|
575 | - } |
|
572 | + if ( isset($field['size']) && $field['size'] > 0 ) { |
|
573 | + $class[] = 'auto_width'; |
|
574 | + } |
|
575 | + } |
|
576 | 576 | |
577 | 577 | private static function add_html_size( $field, array &$add_html ) { |
578 | 578 | if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden' ) ) ) { |
579 | - return; |
|
580 | - } |
|
579 | + return; |
|
580 | + } |
|
581 | 581 | |
582 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
583 | - return; |
|
584 | - } |
|
582 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
583 | + return; |
|
584 | + } |
|
585 | 585 | |
586 | - if ( is_numeric($field['size']) ) { |
|
587 | - $field['size'] .= 'px'; |
|
588 | - } |
|
586 | + if ( is_numeric($field['size']) ) { |
|
587 | + $field['size'] .= 'px'; |
|
588 | + } |
|
589 | 589 | |
590 | - $important = apply_filters('frm_use_important_width', 1, $field); |
|
591 | - // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
590 | + $important = apply_filters('frm_use_important_width', 1, $field); |
|
591 | + // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
592 | 592 | $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"'; |
593 | 593 | |
594 | - self::add_html_cols($field, $add_html); |
|
595 | - } |
|
594 | + self::add_html_cols($field, $add_html); |
|
595 | + } |
|
596 | 596 | |
597 | 597 | private static function add_html_cols( $field, array &$add_html ) { |
598 | 598 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) { |
599 | - return; |
|
600 | - } |
|
599 | + return; |
|
600 | + } |
|
601 | 601 | |
602 | - // convert to cols for textareas |
|
603 | - $calc = array( |
|
604 | - '' => 9, |
|
605 | - 'px' => 9, |
|
606 | - 'rem' => 0.444, |
|
607 | - 'em' => 0.544, |
|
608 | - ); |
|
602 | + // convert to cols for textareas |
|
603 | + $calc = array( |
|
604 | + '' => 9, |
|
605 | + 'px' => 9, |
|
606 | + 'rem' => 0.444, |
|
607 | + 'em' => 0.544, |
|
608 | + ); |
|
609 | 609 | |
610 | - // include "col" for valid html |
|
611 | - $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
610 | + // include "col" for valid html |
|
611 | + $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
612 | 612 | |
613 | - if ( ! isset( $calc[ $unit ] ) ) { |
|
614 | - return; |
|
615 | - } |
|
613 | + if ( ! isset( $calc[ $unit ] ) ) { |
|
614 | + return; |
|
615 | + } |
|
616 | 616 | |
617 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
617 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
618 | 618 | |
619 | 619 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
620 | - } |
|
620 | + } |
|
621 | 621 | |
622 | 622 | private static function add_html_length( $field, array &$add_html ) { |
623 | - // check for max setting and if this field accepts maxlength |
|
623 | + // check for max setting and if this field accepts maxlength |
|
624 | 624 | if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden' ) ) ) { |
625 | - return; |
|
626 | - } |
|
625 | + return; |
|
626 | + } |
|
627 | 627 | |
628 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
629 | - // don't load on form builder page |
|
630 | - return; |
|
631 | - } |
|
628 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
629 | + // don't load on form builder page |
|
630 | + return; |
|
631 | + } |
|
632 | 632 | |
633 | 633 | $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"'; |
634 | - } |
|
634 | + } |
|
635 | 635 | |
636 | 636 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
637 | 637 | if ( empty( $field['default_value'] ) || FrmAppHelper::is_admin_page( 'formidable' ) ) { |
@@ -639,35 +639,35 @@ discard block |
||
639 | 639 | } |
640 | 640 | |
641 | 641 | $default_value_array = is_array( $field['default_value'] ); |
642 | - if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
642 | + if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
643 | 643 | if ( $default_value_array ) { |
644 | 644 | $field['default_value'] = json_encode( $field['default_value'] ); |
645 | 645 | } |
646 | 646 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
647 | - return; |
|
648 | - } |
|
647 | + return; |
|
648 | + } |
|
649 | 649 | |
650 | 650 | if ( $default_value_array ) { |
651 | 651 | // don't include a json placeholder |
652 | 652 | return; |
653 | 653 | } |
654 | 654 | |
655 | - $frm_settings = FrmAppHelper::get_settings(); |
|
655 | + $frm_settings = FrmAppHelper::get_settings(); |
|
656 | 656 | |
657 | 657 | if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) { |
658 | - // use HMTL5 placeholder with js fallback |
|
658 | + // use HMTL5 placeholder with js fallback |
|
659 | 659 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"'; |
660 | - wp_enqueue_script('jquery-placeholder'); |
|
661 | - } else if ( ! $frm_settings->use_html ) { |
|
660 | + wp_enqueue_script('jquery-placeholder'); |
|
661 | + } else if ( ! $frm_settings->use_html ) { |
|
662 | 662 | $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) ); |
663 | 663 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"'; |
664 | - $class[] = 'frm_toggle_default'; |
|
664 | + $class[] = 'frm_toggle_default'; |
|
665 | 665 | |
666 | - if ( $field['value'] == $field['default_value'] ) { |
|
667 | - $class[] = 'frm_default'; |
|
668 | - } |
|
669 | - } |
|
670 | - } |
|
666 | + if ( $field['value'] == $field['default_value'] ) { |
|
667 | + $class[] = 'frm_default'; |
|
668 | + } |
|
669 | + } |
|
670 | + } |
|
671 | 671 | |
672 | 672 | private static function add_validation_messages( $field, array &$add_html ) { |
673 | 673 | if ( FrmField::is_required( $field ) ) { |
@@ -688,44 +688,44 @@ discard block |
||
688 | 688 | } |
689 | 689 | } |
690 | 690 | |
691 | - private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
692 | - if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
693 | - return; |
|
694 | - } |
|
691 | + private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
692 | + if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
693 | + return; |
|
694 | + } |
|
695 | 695 | |
696 | - foreach ( $field['shortcodes'] as $k => $v ) { |
|
697 | - if ( 'opt' === $k ) { |
|
698 | - continue; |
|
699 | - } |
|
696 | + foreach ( $field['shortcodes'] as $k => $v ) { |
|
697 | + if ( 'opt' === $k ) { |
|
698 | + continue; |
|
699 | + } |
|
700 | 700 | |
701 | - if ( is_numeric($k) && strpos($v, '=') ) { |
|
702 | - $add_html[] = $v; |
|
703 | - } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
701 | + if ( is_numeric($k) && strpos($v, '=') ) { |
|
702 | + $add_html[] = $v; |
|
703 | + } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
704 | 704 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
705 | - } else { |
|
705 | + } else { |
|
706 | 706 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
707 | - } |
|
708 | - |
|
709 | - unset($k, $v); |
|
710 | - } |
|
711 | - } |
|
712 | - |
|
713 | - public static function check_value( $opt, $opt_key, $field ) { |
|
714 | - if ( is_array( $opt ) ) { |
|
715 | - if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
716 | - $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
717 | - } else { |
|
718 | - $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
719 | - } |
|
720 | - } |
|
721 | - return $opt; |
|
722 | - } |
|
707 | + } |
|
708 | + |
|
709 | + unset($k, $v); |
|
710 | + } |
|
711 | + } |
|
712 | + |
|
713 | + public static function check_value( $opt, $opt_key, $field ) { |
|
714 | + if ( is_array( $opt ) ) { |
|
715 | + if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
716 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
717 | + } else { |
|
718 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
719 | + } |
|
720 | + } |
|
721 | + return $opt; |
|
722 | + } |
|
723 | 723 | |
724 | 724 | public static function check_label( $opt ) { |
725 | - if ( is_array($opt) ) { |
|
726 | - $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
727 | - } |
|
725 | + if ( is_array($opt) ) { |
|
726 | + $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
727 | + } |
|
728 | 728 | |
729 | - return $opt; |
|
730 | - } |
|
729 | + return $opt; |
|
730 | + } |
|
731 | 731 | } |