@@ -5,69 +5,69 @@ discard block |
||
5 | 5 | |
6 | 6 | class FrmEntriesHelper { |
7 | 7 | |
8 | - public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
9 | - $values = array(); |
|
8 | + public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
9 | + $values = array(); |
|
10 | 10 | foreach ( array( 'name' => '', 'description' => '', 'item_key' => '' ) as $var => $default ) { |
11 | 11 | $values[ $var ] = FrmAppHelper::get_post_param( $var, $default, 'wp_kses_post' ); |
12 | - } |
|
13 | - |
|
14 | - $values['fields'] = array(); |
|
15 | - if ( empty($fields) ) { |
|
16 | - return apply_filters('frm_setup_new_entry', $values); |
|
17 | - } |
|
18 | - |
|
19 | - foreach ( (array) $fields as $field ) { |
|
20 | - $new_value = self::get_field_value_for_new_entry( $field, $reset, $args ); |
|
21 | - |
|
22 | - $field_array = array( |
|
23 | - 'id' => $field->id, |
|
24 | - 'value' => $new_value, |
|
25 | - 'default_value' => $field->default_value, |
|
26 | - 'name' => $field->name, |
|
27 | - 'description' => $field->description, |
|
28 | - 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
29 | - 'options' => $field->options, |
|
30 | - 'required' => $field->required, |
|
31 | - 'field_key' => $field->field_key, |
|
32 | - 'field_order' => $field->field_order, |
|
33 | - 'form_id' => $field->form_id, |
|
12 | + } |
|
13 | + |
|
14 | + $values['fields'] = array(); |
|
15 | + if ( empty($fields) ) { |
|
16 | + return apply_filters('frm_setup_new_entry', $values); |
|
17 | + } |
|
18 | + |
|
19 | + foreach ( (array) $fields as $field ) { |
|
20 | + $new_value = self::get_field_value_for_new_entry( $field, $reset, $args ); |
|
21 | + |
|
22 | + $field_array = array( |
|
23 | + 'id' => $field->id, |
|
24 | + 'value' => $new_value, |
|
25 | + 'default_value' => $field->default_value, |
|
26 | + 'name' => $field->name, |
|
27 | + 'description' => $field->description, |
|
28 | + 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
29 | + 'options' => $field->options, |
|
30 | + 'required' => $field->required, |
|
31 | + 'field_key' => $field->field_key, |
|
32 | + 'field_order' => $field->field_order, |
|
33 | + 'form_id' => $field->form_id, |
|
34 | 34 | 'parent_form_id' => isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id, |
35 | - 'reset_value' => $reset, |
|
35 | + 'reset_value' => $reset, |
|
36 | 36 | 'in_embed_form' => isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0', |
37 | - ); |
|
37 | + ); |
|
38 | 38 | |
39 | - $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
40 | - $opt_defaults['required_indicator'] = ''; |
|
39 | + $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
40 | + $opt_defaults['required_indicator'] = ''; |
|
41 | 41 | $opt_defaults['original_type'] = $field->type; |
42 | 42 | |
43 | 43 | foreach ( $opt_defaults as $opt => $default_opt ) { |
44 | - $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
45 | - unset($opt, $default_opt); |
|
46 | - } |
|
44 | + $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
45 | + unset($opt, $default_opt); |
|
46 | + } |
|
47 | 47 | |
48 | - unset($opt_defaults); |
|
48 | + unset($opt_defaults); |
|
49 | 49 | |
50 | - if ( $field_array['custom_html'] == '' ) { |
|
51 | - $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
52 | - } |
|
50 | + if ( $field_array['custom_html'] == '' ) { |
|
51 | + $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
52 | + } |
|
53 | 53 | |
54 | - $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
55 | - $field_array = array_merge( $field->field_options, $field_array ); |
|
54 | + $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field, $args ); |
|
55 | + $field_array = array_merge( $field->field_options, $field_array ); |
|
56 | 56 | |
57 | - $values['fields'][] = $field_array; |
|
57 | + $values['fields'][] = $field_array; |
|
58 | 58 | |
59 | - if ( ! $form || ! isset($form->id) ) { |
|
60 | - $form = FrmForm::getOne($field->form_id); |
|
61 | - } |
|
62 | - } |
|
59 | + if ( ! $form || ! isset($form->id) ) { |
|
60 | + $form = FrmForm::getOne($field->form_id); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - $form->options = maybe_unserialize($form->options); |
|
65 | - if ( is_array($form->options) ) { |
|
66 | - foreach ( $form->options as $opt => $value ) { |
|
67 | - $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
68 | - unset($opt, $value); |
|
69 | - } |
|
70 | - } |
|
64 | + $form->options = maybe_unserialize($form->options); |
|
65 | + if ( is_array($form->options) ) { |
|
66 | + foreach ( $form->options as $opt => $value ) { |
|
67 | + $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
68 | + unset($opt, $value); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | 72 | $form_defaults = FrmFormsHelper::get_default_opts(); |
73 | 73 | |
@@ -77,19 +77,19 @@ discard block |
||
77 | 77 | $values = array_merge( $form_defaults, $values ); |
78 | 78 | |
79 | 79 | return apply_filters( 'frm_setup_new_entry', $values ); |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | 82 | /** |
83 | - * Set the value for each field |
|
84 | - * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
85 | - * |
|
86 | - * @since 2.0.13 |
|
87 | - * |
|
88 | - * @param object $field - this is passed by reference since it is an object |
|
89 | - * @param boolean $reset |
|
90 | - * @param array $args |
|
91 | - * @return string|array $new_value |
|
92 | - */ |
|
83 | + * Set the value for each field |
|
84 | + * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
85 | + * |
|
86 | + * @since 2.0.13 |
|
87 | + * |
|
88 | + * @param object $field - this is passed by reference since it is an object |
|
89 | + * @param boolean $reset |
|
90 | + * @param array $args |
|
91 | + * @return string|array $new_value |
|
92 | + */ |
|
93 | 93 | private static function get_field_value_for_new_entry( $field, $reset, $args ) { |
94 | 94 | //If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array |
95 | 95 | $return_array = FrmField::is_field_with_multiple_values( $field ); |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Check if a field has a posted value |
|
125 | - * |
|
126 | - * @since 2.01.0 |
|
127 | - * @param object $field |
|
128 | - * @param array $args |
|
129 | - * @return boolean $value_is_posted |
|
130 | - */ |
|
124 | + * Check if a field has a posted value |
|
125 | + * |
|
126 | + * @since 2.01.0 |
|
127 | + * @param object $field |
|
128 | + * @param array $args |
|
129 | + * @return boolean $value_is_posted |
|
130 | + */ |
|
131 | 131 | public static function value_is_posted( $field, $args ) { |
132 | 132 | $value_is_posted = false; |
133 | 133 | if ( $_POST ) { |
@@ -145,15 +145,15 @@ discard block |
||
145 | 145 | |
146 | 146 | public static function setup_edit_vars( $values, $record ) { |
147 | 147 | $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' ); |
148 | - $values['form_id'] = $record->form_id; |
|
149 | - $values['is_draft'] = $record->is_draft; |
|
150 | - return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
151 | - } |
|
148 | + $values['form_id'] = $record->form_id; |
|
149 | + $values['is_draft'] = $record->is_draft; |
|
150 | + return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
151 | + } |
|
152 | 152 | |
153 | - public static function get_admin_params( $form = null ) { |
|
153 | + public static function get_admin_params( $form = null ) { |
|
154 | 154 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_admin_params' ); |
155 | 155 | return FrmForm::set_current_form( $form ); |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | 158 | public static function set_current_form( $form_id ) { |
159 | 159 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::set_current_form' ); |
@@ -165,284 +165,284 @@ discard block |
||
165 | 165 | return FrmForm::get_current_form( $form_id ); |
166 | 166 | } |
167 | 167 | |
168 | - public static function get_current_form_id() { |
|
168 | + public static function get_current_form_id() { |
|
169 | 169 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_current_form_id' ); |
170 | 170 | return FrmForm::get_current_form_id(); |
171 | - } |
|
171 | + } |
|
172 | 172 | |
173 | - public static function maybe_get_entry( &$entry ) { |
|
173 | + public static function maybe_get_entry( &$entry ) { |
|
174 | 174 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntry::maybe_get_entry' ); |
175 | 175 | FrmEntry::maybe_get_entry( $entry ); |
176 | - } |
|
176 | + } |
|
177 | 177 | |
178 | 178 | public static function replace_default_message( $message, $atts ) { |
179 | - if ( strpos($message, '[default-message') === false && |
|
180 | - strpos($message, '[default_message') === false && |
|
181 | - ! empty( $message ) ) { |
|
182 | - return $message; |
|
183 | - } |
|
184 | - |
|
185 | - if ( empty($message) ) { |
|
186 | - $message = '[default-message]'; |
|
187 | - } |
|
188 | - |
|
189 | - preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
190 | - |
|
191 | - foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
192 | - $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
193 | - if ( $add_atts ) { |
|
194 | - $this_atts = array_merge($atts, $add_atts); |
|
195 | - } else { |
|
196 | - $this_atts = $atts; |
|
197 | - } |
|
179 | + if ( strpos($message, '[default-message') === false && |
|
180 | + strpos($message, '[default_message') === false && |
|
181 | + ! empty( $message ) ) { |
|
182 | + return $message; |
|
183 | + } |
|
184 | + |
|
185 | + if ( empty($message) ) { |
|
186 | + $message = '[default-message]'; |
|
187 | + } |
|
188 | + |
|
189 | + preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
190 | + |
|
191 | + foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
192 | + $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
193 | + if ( $add_atts ) { |
|
194 | + $this_atts = array_merge($atts, $add_atts); |
|
195 | + } else { |
|
196 | + $this_atts = $atts; |
|
197 | + } |
|
198 | 198 | |
199 | 199 | $default = FrmEntryFormat::show_entry( $this_atts ); |
200 | 200 | |
201 | - // Add the default message |
|
202 | - $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
203 | - } |
|
201 | + // Add the default message |
|
202 | + $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
203 | + } |
|
204 | 204 | |
205 | - return $message; |
|
206 | - } |
|
205 | + return $message; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | public static function prepare_display_value( $entry, $field, $atts ) { |
209 | 209 | $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false; |
210 | 210 | |
211 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
211 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
212 | 212 | FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value ); |
213 | - } |
|
213 | + } |
|
214 | 214 | |
215 | - if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
216 | - return self::display_value($field_value, $field, $atts); |
|
217 | - } |
|
215 | + if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
216 | + return self::display_value($field_value, $field, $atts); |
|
217 | + } |
|
218 | 218 | |
219 | - // this is an embeded form |
|
220 | - $val = ''; |
|
219 | + // this is an embeded form |
|
220 | + $val = ''; |
|
221 | 221 | |
222 | - if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
223 | - //this is a repeating section |
|
222 | + if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
223 | + //this is a repeating section |
|
224 | 224 | $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) ); |
225 | - } else { |
|
226 | - // get all values for this field |
|
227 | - $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
225 | + } else { |
|
226 | + // get all values for this field |
|
227 | + $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
228 | 228 | |
229 | - if ( $child_values ) { |
|
230 | - $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
231 | - } |
|
232 | - } |
|
229 | + if ( $child_values ) { |
|
230 | + $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
231 | + } |
|
232 | + } |
|
233 | 233 | |
234 | - $field_value = array(); |
|
234 | + $field_value = array(); |
|
235 | 235 | |
236 | - if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
237 | - return $val; |
|
238 | - } |
|
236 | + if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
237 | + return $val; |
|
238 | + } |
|
239 | 239 | |
240 | - foreach ( $child_entries as $child_entry ) { |
|
241 | - $atts['item_id'] = $child_entry->id; |
|
242 | - $atts['post_id'] = $child_entry->post_id; |
|
240 | + foreach ( $child_entries as $child_entry ) { |
|
241 | + $atts['item_id'] = $child_entry->id; |
|
242 | + $atts['post_id'] = $child_entry->post_id; |
|
243 | 243 | |
244 | - // get the value for this field -- check for post values as well |
|
245 | - $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
244 | + // get the value for this field -- check for post values as well |
|
245 | + $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
246 | 246 | |
247 | - if ( $entry_val ) { |
|
248 | - // foreach entry get display_value |
|
249 | - $field_value[] = self::display_value($entry_val, $field, $atts); |
|
250 | - } |
|
247 | + if ( $entry_val ) { |
|
248 | + // foreach entry get display_value |
|
249 | + $field_value[] = self::display_value($entry_val, $field, $atts); |
|
250 | + } |
|
251 | 251 | |
252 | - unset($child_entry); |
|
253 | - } |
|
252 | + unset($child_entry); |
|
253 | + } |
|
254 | 254 | |
255 | - $val = implode(', ', (array) $field_value ); |
|
255 | + $val = implode(', ', (array) $field_value ); |
|
256 | 256 | $val = wp_kses_post( $val ); |
257 | 257 | |
258 | - return $val; |
|
259 | - } |
|
258 | + return $val; |
|
259 | + } |
|
260 | 260 | |
261 | - /** |
|
262 | - * Prepare the saved value for display |
|
263 | - * @return string |
|
264 | - */ |
|
261 | + /** |
|
262 | + * Prepare the saved value for display |
|
263 | + * @return string |
|
264 | + */ |
|
265 | 265 | public static function display_value( $value, $field, $atts = array() ) { |
266 | 266 | |
267 | - $defaults = array( |
|
268 | - 'type' => '', 'html' => false, 'show_filename' => true, |
|
269 | - 'truncate' => false, 'sep' => ', ', 'post_id' => 0, |
|
270 | - 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0, |
|
267 | + $defaults = array( |
|
268 | + 'type' => '', 'html' => false, 'show_filename' => true, |
|
269 | + 'truncate' => false, 'sep' => ', ', 'post_id' => 0, |
|
270 | + 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0, |
|
271 | 271 | 'return_array' => false, |
272 | - ); |
|
272 | + ); |
|
273 | 273 | |
274 | - $atts = wp_parse_args( $atts, $defaults ); |
|
275 | - $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
274 | + $atts = wp_parse_args( $atts, $defaults ); |
|
275 | + $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
276 | 276 | |
277 | - if ( ! isset($field->field_options['post_field']) ) { |
|
278 | - $field->field_options['post_field'] = ''; |
|
279 | - } |
|
277 | + if ( ! isset($field->field_options['post_field']) ) { |
|
278 | + $field->field_options['post_field'] = ''; |
|
279 | + } |
|
280 | 280 | |
281 | - if ( ! isset($field->field_options['custom_field']) ) { |
|
282 | - $field->field_options['custom_field'] = ''; |
|
283 | - } |
|
281 | + if ( ! isset($field->field_options['custom_field']) ) { |
|
282 | + $field->field_options['custom_field'] = ''; |
|
283 | + } |
|
284 | 284 | |
285 | - if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
286 | - $atts['pre_truncate'] = $atts['truncate']; |
|
287 | - $atts['truncate'] = true; |
|
288 | - $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
285 | + if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
286 | + $atts['pre_truncate'] = $atts['truncate']; |
|
287 | + $atts['truncate'] = true; |
|
288 | + $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
289 | 289 | |
290 | - $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
291 | - $atts['truncate'] = $atts['pre_truncate']; |
|
292 | - } |
|
290 | + $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
291 | + $atts['truncate'] = $atts['pre_truncate']; |
|
292 | + } |
|
293 | 293 | |
294 | - if ( $value == '' ) { |
|
295 | - return $value; |
|
296 | - } |
|
294 | + if ( $value == '' ) { |
|
295 | + return $value; |
|
296 | + } |
|
297 | 297 | |
298 | - $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts); |
|
298 | + $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts); |
|
299 | 299 | $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) ); |
300 | 300 | |
301 | - $new_value = ''; |
|
301 | + $new_value = ''; |
|
302 | 302 | |
303 | - if ( is_array($value) && $atts['type'] != 'file' ) { |
|
304 | - foreach ( $value as $val ) { |
|
305 | - if ( is_array($val) ) { |
|
303 | + if ( is_array($value) && $atts['type'] != 'file' ) { |
|
304 | + foreach ( $value as $val ) { |
|
305 | + if ( is_array($val) ) { |
|
306 | 306 | //TODO: add options for display (li or ,) |
307 | - $new_value .= implode($atts['sep'], $val); |
|
308 | - if ( $atts['type'] != 'data' ) { |
|
309 | - $new_value .= '<br/>'; |
|
310 | - } |
|
311 | - } |
|
312 | - unset($val); |
|
313 | - } |
|
314 | - } |
|
315 | - |
|
316 | - if ( ! empty($new_value) ) { |
|
317 | - $value = $new_value; |
|
318 | - } else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) { |
|
319 | - $value = implode($atts['sep'], $value); |
|
320 | - } |
|
321 | - |
|
322 | - if ( $atts['truncate'] && $atts['type'] != 'image' ) { |
|
323 | - $value = FrmAppHelper::truncate($value, 50); |
|
324 | - } |
|
307 | + $new_value .= implode($atts['sep'], $val); |
|
308 | + if ( $atts['type'] != 'data' ) { |
|
309 | + $new_value .= '<br/>'; |
|
310 | + } |
|
311 | + } |
|
312 | + unset($val); |
|
313 | + } |
|
314 | + } |
|
315 | + |
|
316 | + if ( ! empty($new_value) ) { |
|
317 | + $value = $new_value; |
|
318 | + } else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) { |
|
319 | + $value = implode($atts['sep'], $value); |
|
320 | + } |
|
321 | + |
|
322 | + if ( $atts['truncate'] && $atts['type'] != 'image' ) { |
|
323 | + $value = FrmAppHelper::truncate($value, 50); |
|
324 | + } |
|
325 | 325 | |
326 | 326 | if ( ! $atts['keepjs'] && ! is_array( $value ) ) { |
327 | 327 | $value = wp_kses_post( $value ); |
328 | 328 | } |
329 | 329 | |
330 | - return apply_filters('frm_display_value', $value, $field, $atts); |
|
331 | - } |
|
330 | + return apply_filters('frm_display_value', $value, $field, $atts); |
|
331 | + } |
|
332 | 332 | |
333 | 333 | public static function set_posted_value( $field, $value, $args ) { |
334 | - // If validating a field with "other" opt, set back to prev value now |
|
335 | - if ( isset( $args['other'] ) && $args['other'] ) { |
|
336 | - $value = $args['temp_value']; |
|
337 | - } |
|
338 | - if ( empty($args['parent_field_id']) ) { |
|
339 | - $_POST['item_meta'][ $field->id ] = $value; |
|
340 | - } else { |
|
341 | - $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
342 | - } |
|
343 | - } |
|
334 | + // If validating a field with "other" opt, set back to prev value now |
|
335 | + if ( isset( $args['other'] ) && $args['other'] ) { |
|
336 | + $value = $args['temp_value']; |
|
337 | + } |
|
338 | + if ( empty($args['parent_field_id']) ) { |
|
339 | + $_POST['item_meta'][ $field->id ] = $value; |
|
340 | + } else { |
|
341 | + $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
342 | + } |
|
343 | + } |
|
344 | 344 | |
345 | 345 | public static function get_posted_value( $field, &$value, $args ) { |
346 | 346 | $field_id = is_object( $field ) ? $field->id : $field; |
347 | 347 | |
348 | - if ( empty($args['parent_field_id']) ) { |
|
349 | - $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
350 | - } else { |
|
351 | - $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : ''; |
|
352 | - } |
|
348 | + if ( empty($args['parent_field_id']) ) { |
|
349 | + $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
350 | + } else { |
|
351 | + $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : ''; |
|
352 | + } |
|
353 | 353 | FrmAppHelper::sanitize_value( 'wp_kses_post', $value ); |
354 | 354 | $value = stripslashes_deep( $value ); |
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Check if field has an "Other" option and if any other values are posted |
|
359 | - * |
|
360 | - * @since 2.0 |
|
361 | - * |
|
362 | - * @param object $field |
|
363 | - * @param string|array $value |
|
364 | - * @param array $args |
|
365 | - */ |
|
366 | - public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
367 | - $args['other'] = false; |
|
368 | - if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
369 | - return; |
|
370 | - } |
|
371 | - |
|
372 | - // Get other value for fields in repeating section |
|
373 | - self::set_other_repeating_vals( $field, $value, $args ); |
|
374 | - |
|
375 | - // Check if there are any posted "Other" values |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Check if field has an "Other" option and if any other values are posted |
|
359 | + * |
|
360 | + * @since 2.0 |
|
361 | + * |
|
362 | + * @param object $field |
|
363 | + * @param string|array $value |
|
364 | + * @param array $args |
|
365 | + */ |
|
366 | + public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
367 | + $args['other'] = false; |
|
368 | + if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
369 | + return; |
|
370 | + } |
|
371 | + |
|
372 | + // Get other value for fields in repeating section |
|
373 | + self::set_other_repeating_vals( $field, $value, $args ); |
|
374 | + |
|
375 | + // Check if there are any posted "Other" values |
|
376 | 376 | if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { |
377 | 377 | |
378 | - // Save original value |
|
379 | - $args['temp_value'] = $value; |
|
380 | - $args['other'] = true; |
|
381 | - $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
382 | - |
|
383 | - // Set the validation value now |
|
384 | - self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
385 | - } |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
390 | - * |
|
391 | - * @since 2.0 |
|
392 | - * |
|
393 | - * @param object $field |
|
394 | - * @param string|array $value |
|
395 | - * @param array $args |
|
396 | - */ |
|
397 | - public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
398 | - if ( ! $args['parent_field_id'] ) { |
|
399 | - return; |
|
400 | - } |
|
401 | - |
|
402 | - // Check if there are any other posted "other" values for this field |
|
378 | + // Save original value |
|
379 | + $args['temp_value'] = $value; |
|
380 | + $args['other'] = true; |
|
381 | + $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
382 | + |
|
383 | + // Set the validation value now |
|
384 | + self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
385 | + } |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
390 | + * |
|
391 | + * @since 2.0 |
|
392 | + * |
|
393 | + * @param object $field |
|
394 | + * @param string|array $value |
|
395 | + * @param array $args |
|
396 | + */ |
|
397 | + public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
398 | + if ( ! $args['parent_field_id'] ) { |
|
399 | + return; |
|
400 | + } |
|
401 | + |
|
402 | + // Check if there are any other posted "other" values for this field |
|
403 | 403 | if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { |
404 | - // Save original value |
|
405 | - $args['temp_value'] = $value; |
|
406 | - $args['other'] = true; |
|
407 | - |
|
408 | - $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
409 | - |
|
410 | - // Set the validation value now |
|
411 | - self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
412 | - } |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Modify value used for validation |
|
417 | - * This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
418 | - * It also adds any text from the free text fields to the value |
|
419 | - * |
|
420 | - * Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
421 | - * |
|
422 | - * @since 2.0 |
|
423 | - * |
|
424 | - * @param string|array $value |
|
425 | - * @param string|array $other_vals (usually of posted values) |
|
426 | - * @param object $field |
|
427 | - * @param array $args |
|
428 | - */ |
|
429 | - public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
430 | - // Checkboxes and multi-select dropdowns |
|
431 | - if ( is_array( $value ) && $field->type == 'checkbox' ) { |
|
432 | - // Combine "Other" values with checked values. "Other" values will override checked box values. |
|
433 | - $value = array_merge( $value, $other_vals ); |
|
434 | - $value = array_filter( $value ); |
|
435 | - if ( count( $value ) == 0 ) { |
|
436 | - $value = ''; |
|
437 | - } |
|
438 | - } else { |
|
404 | + // Save original value |
|
405 | + $args['temp_value'] = $value; |
|
406 | + $args['other'] = true; |
|
407 | + |
|
408 | + $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
409 | + |
|
410 | + // Set the validation value now |
|
411 | + self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
412 | + } |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Modify value used for validation |
|
417 | + * This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
418 | + * It also adds any text from the free text fields to the value |
|
419 | + * |
|
420 | + * Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
421 | + * |
|
422 | + * @since 2.0 |
|
423 | + * |
|
424 | + * @param string|array $value |
|
425 | + * @param string|array $other_vals (usually of posted values) |
|
426 | + * @param object $field |
|
427 | + * @param array $args |
|
428 | + */ |
|
429 | + public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
430 | + // Checkboxes and multi-select dropdowns |
|
431 | + if ( is_array( $value ) && $field->type == 'checkbox' ) { |
|
432 | + // Combine "Other" values with checked values. "Other" values will override checked box values. |
|
433 | + $value = array_merge( $value, $other_vals ); |
|
434 | + $value = array_filter( $value ); |
|
435 | + if ( count( $value ) == 0 ) { |
|
436 | + $value = ''; |
|
437 | + } |
|
438 | + } else { |
|
439 | 439 | // Radio and dropdowns |
440 | - $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
441 | - $other_key = reset( $other_key ); |
|
440 | + $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
441 | + $other_key = reset( $other_key ); |
|
442 | 442 | |
443 | - // Multi-select dropdown |
|
444 | - if ( is_array( $value ) ) { |
|
445 | - $o_key = array_search( $field->options[ $other_key ], $value ); |
|
443 | + // Multi-select dropdown |
|
444 | + if ( is_array( $value ) ) { |
|
445 | + $o_key = array_search( $field->options[ $other_key ], $value ); |
|
446 | 446 | |
447 | 447 | if ( $o_key !== false ) { |
448 | 448 | // Modify the original value so other key will be preserved |
@@ -457,20 +457,20 @@ discard block |
||
457 | 457 | $args['temp_value'] = $value; |
458 | 458 | $value[ $other_key ] = reset( $other_vals ); |
459 | 459 | } |
460 | - } else if ( $field->options[ $other_key ] == $value ) { |
|
461 | - $value = $other_vals; |
|
462 | - } |
|
463 | - } |
|
464 | - } |
|
460 | + } else if ( $field->options[ $other_key ] == $value ) { |
|
461 | + $value = $other_vals; |
|
462 | + } |
|
463 | + } |
|
464 | + } |
|
465 | 465 | |
466 | 466 | public static function enqueue_scripts( $params ) { |
467 | 467 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmFormsController::enqueue_scripts' ); |
468 | 468 | FrmFormsController::enqueue_scripts( $params ); |
469 | 469 | } |
470 | 470 | |
471 | - // Add submitted values to a string for spam checking |
|
471 | + // Add submitted values to a string for spam checking |
|
472 | 472 | public static function entry_array_to_string( $values ) { |
473 | - $content = ''; |
|
473 | + $content = ''; |
|
474 | 474 | foreach ( $values['item_meta'] as $val ) { |
475 | 475 | if ( $content != '' ) { |
476 | 476 | $content .= "\n\n"; |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | } |
486 | 486 | |
487 | 487 | return $content; |
488 | - } |
|
488 | + } |
|
489 | 489 | |
490 | 490 | public static function fill_entry_values( $atts, $f, array &$values ) { |
491 | 491 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryFormat::fill_entry_values' ); |