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