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