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