Completed
Push — master ( 32fe2f...1b01bd )
by Stephanie
03:41
created
classes/models/FrmEntryValidate.php 2 patches
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -1,26 +1,26 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class FrmEntryValidate {
4
-    public static function validate( $values, $exclude = false ) {
5
-        global $wpdb;
4
+	public static function validate( $values, $exclude = false ) {
5
+		global $wpdb;
6 6
 
7
-        FrmEntry::sanitize_entry_post( $values );
8
-        $errors = array();
7
+		FrmEntry::sanitize_entry_post( $values );
8
+		$errors = array();
9 9
 
10
-        if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
11
-            $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );
12
-            return $errors;
13
-        }
10
+		if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
11
+			$errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );
12
+			return $errors;
13
+		}
14 14
 
15 15
 		if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) {
16
-            $errors['form'] = __( 'You do not have permission to do that', 'formidable' );
17
-        }
16
+			$errors['form'] = __( 'You do not have permission to do that', 'formidable' );
17
+		}
18 18
 
19
-        if ( ! isset($values['item_key']) || $values['item_key'] == '' ) {
20
-            $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
21
-        }
19
+		if ( ! isset($values['item_key']) || $values['item_key'] == '' ) {
20
+			$_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
21
+		}
22 22
 
23
-        $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) );
23
+		$where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) );
24 24
 		// Don't get subfields
25 25
 		$where['fr.parent_form_id'] = array( null, 0 );
26 26
 		// Don't get excluded fields (like file upload fields in the ajax validation)
@@ -28,46 +28,46 @@  discard block
 block discarded – undo
28 28
 			$where['fi.type not'] = $exclude;
29 29
 		}
30 30
 
31
-        $posted_fields = FrmField::getAll($where, 'field_order');
31
+		$posted_fields = FrmField::getAll($where, 'field_order');
32 32
 
33
-        // Pass exclude value to validate_field function so it can be used for repeating sections
34
-        $args = array( 'exclude' => $exclude );
33
+		// Pass exclude value to validate_field function so it can be used for repeating sections
34
+		$args = array( 'exclude' => $exclude );
35 35
 
36
-        foreach ( $posted_fields as $posted_field ) {
37
-            self::validate_field($posted_field, $errors, $values, $args);
38
-            unset($posted_field);
39
-        }
36
+		foreach ( $posted_fields as $posted_field ) {
37
+			self::validate_field($posted_field, $errors, $values, $args);
38
+			unset($posted_field);
39
+		}
40 40
 
41
-        // check for spam
42
-        self::spam_check( $exclude, $values, $errors );
41
+		// check for spam
42
+		self::spam_check( $exclude, $values, $errors );
43 43
 
44
-        $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') );
44
+		$errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') );
45 45
 
46
-        return $errors;
47
-    }
46
+		return $errors;
47
+	}
48 48
 
49
-    public static function validate_field( $posted_field, &$errors, $values, $args = array() ) {
50
-        $defaults = array(
51
-            'id'              => $posted_field->id,
52
-            'parent_field_id' => '', // the id of the repeat or embed form
53
-            'key_pointer'     => '', // the pointer in the posted array
54
-            'exclude'         => array(), // exclude these field types from validation
55
-        );
56
-        $args = wp_parse_args( $args, $defaults );
49
+	public static function validate_field( $posted_field, &$errors, $values, $args = array() ) {
50
+		$defaults = array(
51
+			'id'              => $posted_field->id,
52
+			'parent_field_id' => '', // the id of the repeat or embed form
53
+			'key_pointer'     => '', // the pointer in the posted array
54
+			'exclude'         => array(), // exclude these field types from validation
55
+		);
56
+		$args = wp_parse_args( $args, $defaults );
57 57
 
58
-        if ( empty($args['parent_field_id']) ) {
58
+		if ( empty($args['parent_field_id']) ) {
59 59
 			$value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : '';
60
-        } else {
61
-            // value is from a nested form
62
-            $value = $values;
63
-        }
60
+		} else {
61
+			// value is from a nested form
62
+			$value = $values;
63
+		}
64 64
 
65
-        // Check for values in "Other" fields
66
-        FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args );
65
+		// Check for values in "Other" fields
66
+		FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args );
67 67
 
68
-        if ( isset($posted_field->field_options['default_blank']) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) {
69
-            $value = '';
70
-        }
68
+		if ( isset($posted_field->field_options['default_blank']) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) {
69
+			$value = '';
70
+		}
71 71
 
72 72
 		// Check for an array with only one value
73 73
 		// Don't reset values in "Other" fields because array keys need to be preserved
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
 			$value = reset($value);
76 76
 		}
77 77
 
78
-        if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) {
78
+		if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) {
79 79
 			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' );
80
-        } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) {
81
-            $_POST['item_name'] = $value;
82
-        }
80
+		} else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) {
81
+			$_POST['item_name'] = $value;
82
+		}
83 83
 
84 84
 		if ( $value != '' ) {
85 85
 			self::validate_url_field( $errors, $posted_field, $value, $args );
@@ -88,41 +88,41 @@  discard block
 block discarded – undo
88 88
 			self::validate_phone_field( $errors, $posted_field, $value, $args );
89 89
 		}
90 90
 
91
-        FrmEntriesHelper::set_posted_value($posted_field, $value, $args);
91
+		FrmEntriesHelper::set_posted_value($posted_field, $value, $args);
92 92
 
93
-        self::validate_recaptcha($errors, $posted_field, $args);
93
+		self::validate_recaptcha($errors, $posted_field, $args);
94 94
 
95
-        $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args);
96
-    }
95
+		$errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args);
96
+	}
97 97
 
98 98
 	public static function validate_url_field( &$errors, $field, &$value, $args ) {
99 99
 		if ( $value == '' || ! in_array( $field->type, array( 'website', 'url', 'image' ) ) ) {
100
-            return;
101
-        }
102
-
103
-        if ( trim($value) == 'http://' ) {
104
-            $value = '';
105
-        } else {
106
-            $value = esc_url_raw( $value );
107
-            $value = preg_match('/^(https?|ftps?|mailto|news|feed|telnet):/is', $value) ? $value : 'http://'. $value;
108
-        }
109
-
110
-        //validate the url format
111
-        if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) {
100
+			return;
101
+		}
102
+
103
+		if ( trim($value) == 'http://' ) {
104
+			$value = '';
105
+		} else {
106
+			$value = esc_url_raw( $value );
107
+			$value = preg_match('/^(https?|ftps?|mailto|news|feed|telnet):/is', $value) ? $value : 'http://'. $value;
108
+		}
109
+
110
+		//validate the url format
111
+		if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) {
112 112
 			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
113
-        }
114
-    }
113
+		}
114
+	}
115 115
 
116 116
 	public static function validate_email_field( &$errors, $field, $value, $args ) {
117
-        if ( $value == '' || $field->type != 'email' ) {
118
-            return;
119
-        }
117
+		if ( $value == '' || $field->type != 'email' ) {
118
+			return;
119
+		}
120 120
 
121
-        //validate the email format
122
-        if ( ! is_email($value) ) {
121
+		//validate the email format
122
+		if ( ! is_email($value) ) {
123 123
 			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
124
-        }
125
-    }
124
+		}
125
+	}
126 126
 
127 127
 	public static function validate_number_field( &$errors, $field, $value, $args ) {
128 128
 		//validate the number format
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
 	}
200 200
 
201 201
 	public static function validate_recaptcha( &$errors, $field, $args ) {
202
-        if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) {
203
-            return;
204
-        }
202
+		if ( $field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters( 'frm_is_field_hidden', false, $field, stripslashes_deep( $_POST ) ) ) {
203
+			return;
204
+		}
205 205
 
206 206
 		$frm_settings = FrmAppHelper::get_settings();
207 207
 		if ( empty( $frm_settings->pubkey ) ) {
@@ -209,53 +209,53 @@  discard block
 block discarded – undo
209 209
 			return;
210 210
 		}
211 211
 
212
-        if ( ! isset($_POST['g-recaptcha-response']) ) {
213
-            // If captcha is missing, check if it was already verified
212
+		if ( ! isset($_POST['g-recaptcha-response']) ) {
213
+			// If captcha is missing, check if it was already verified
214 214
 			if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) {
215
-                // There was no captcha submitted
215
+				// There was no captcha submitted
216 216
 				$errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' );
217
-            }
218
-            return;
219
-        }
217
+			}
218
+			return;
219
+		}
220 220
 
221
-        $arg_array = array(
222
-            'body'      => array(
221
+		$arg_array = array(
222
+			'body'      => array(
223 223
 				'secret'   => $frm_settings->privkey,
224 224
 				'response' => $_POST['g-recaptcha-response'],
225 225
 				'remoteip' => FrmAppHelper::get_ip_address(),
226 226
 			),
227 227
 		);
228
-        $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array );
229
-        $response = json_decode(wp_remote_retrieve_body( $resp ), true);
228
+		$resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array );
229
+		$response = json_decode(wp_remote_retrieve_body( $resp ), true);
230 230
 
231
-        if ( isset( $response['success'] ) && ! $response['success'] ) {
232
-            // What happens when the CAPTCHA was entered incorrectly
231
+		if ( isset( $response['success'] ) && ! $response['success'] ) {
232
+			// What happens when the CAPTCHA was entered incorrectly
233 233
 			$errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid'];
234
-        }
235
-    }
236
-
237
-    /**
238
-     * check for spam
239
-     * @param boolean $exclude
240
-     * @param array $values
241
-     * @param array $errors by reference
242
-     */
243
-    public static function spam_check( $exclude, $values, &$errors ) {
244
-        if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
245
-            // only check spam if there are no other errors
246
-            return;
247
-        }
248
-
249
-        if ( self::is_akismet_spam( $values ) ) {
234
+		}
235
+	}
236
+
237
+	/**
238
+	 * check for spam
239
+	 * @param boolean $exclude
240
+	 * @param array $values
241
+	 * @param array $errors by reference
242
+	 */
243
+	public static function spam_check( $exclude, $values, &$errors ) {
244
+		if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
245
+			// only check spam if there are no other errors
246
+			return;
247
+		}
248
+
249
+		if ( self::is_akismet_spam( $values ) ) {
250 250
 			if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) {
251 251
 				$errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
252 252
 			}
253
-	    }
253
+		}
254 254
 
255
-    	if ( self::blacklist_check( $values ) ) {
256
-            $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
257
-    	}
258
-    }
255
+		if ( self::blacklist_check( $values ) ) {
256
+			$errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
257
+		}
258
+	}
259 259
 
260 260
 	private static function is_akismet_spam( $values ) {
261 261
 		global $wpcom_api_key;
@@ -267,54 +267,54 @@  discard block
 block discarded – undo
267 267
 		return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) );
268 268
 	}
269 269
 
270
-    public static function blacklist_check( $values ) {
271
-        if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
272
-            return false;
273
-        }
270
+	public static function blacklist_check( $values ) {
271
+		if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
272
+			return false;
273
+		}
274 274
 
275
-    	$mod_keys = trim( get_option( 'blacklist_keys' ) );
275
+		$mod_keys = trim( get_option( 'blacklist_keys' ) );
276 276
 
277
-    	if ( empty( $mod_keys ) ) {
278
-    		return false;
279
-    	}
277
+		if ( empty( $mod_keys ) ) {
278
+			return false;
279
+		}
280 280
 
281
-    	$content = FrmEntriesHelper::entry_array_to_string($values);
281
+		$content = FrmEntriesHelper::entry_array_to_string($values);
282 282
 
283 283
 		if ( empty($content) ) {
284
-		    return false;
284
+			return false;
285 285
 		}
286 286
 
287
-    	$words = explode( "\n", $mod_keys );
287
+		$words = explode( "\n", $mod_keys );
288 288
 
289
-    	foreach ( (array) $words as $word ) {
290
-    		$word = trim( $word );
289
+		foreach ( (array) $words as $word ) {
290
+			$word = trim( $word );
291 291
 
292
-    		if ( empty($word) ) {
293
-    			continue;
294
-    		}
292
+			if ( empty($word) ) {
293
+				continue;
294
+			}
295 295
 
296
-    		if ( preg_match('#' . preg_quote( $word, '#' ) . '#', $content) ) {
297
-    			return true;
298
-    		}
299
-    	}
296
+			if ( preg_match('#' . preg_quote( $word, '#' ) . '#', $content) ) {
297
+				return true;
298
+			}
299
+		}
300 300
 
301
-    	return false;
302
-    }
301
+		return false;
302
+	}
303 303
 
304
-    /**
305
-     * Check entries for spam
306
-     *
307
-     * @return boolean true if is spam
308
-     */
309
-    public static function akismet( $values ) {
310
-	    $content = FrmEntriesHelper::entry_array_to_string( $values );
304
+	/**
305
+	 * Check entries for spam
306
+	 *
307
+	 * @return boolean true if is spam
308
+	 */
309
+	public static function akismet( $values ) {
310
+		$content = FrmEntriesHelper::entry_array_to_string( $values );
311 311
 
312 312
 		if ( empty( $content ) ) {
313
-		    return false;
313
+			return false;
314 314
 		}
315 315
 
316
-        $datas = array();
317
-        self::parse_akismet_array( $datas, $content );
316
+		$datas = array();
317
+		self::parse_akismet_array( $datas, $content );
318 318
 
319 319
 		$query_string = '';
320 320
 		foreach ( $datas as $key => $data ) {
@@ -322,35 +322,35 @@  discard block
 block discarded – undo
322 322
 			unset( $key, $data );
323 323
 		}
324 324
 
325
-        $response = Akismet::http_post($query_string, 'comment-check');
325
+		$response = Akismet::http_post($query_string, 'comment-check');
326 326
 
327 327
 		return ( is_array( $response ) && $response[1] == 'true' );
328
-    }
329
-
330
-    /**
331
-     * @since 2.0
332
-     * @param string $content
333
-     */
334
-    private  static function parse_akismet_array( &$datas, $content ) {
335
-        $datas['blog'] = FrmAppHelper::site_url();
336
-        $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() );
328
+	}
329
+
330
+	/**
331
+	 * @since 2.0
332
+	 * @param string $content
333
+	 */
334
+	private  static function parse_akismet_array( &$datas, $content ) {
335
+		$datas['blog'] = FrmAppHelper::site_url();
336
+		$datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() );
337 337
 		$datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' );
338 338
 		$datas['referrer'] = isset( $_SERVER['HTTP_REFERER'] ) ? FrmAppHelper::get_server_value( 'HTTP_REFERER' ) : false;
339
-        $datas['comment_type'] = 'formidable';
340
-        $datas['comment_content'] = $content;
339
+		$datas['comment_type'] = 'formidable';
340
+		$datas['comment_content'] = $content;
341 341
 
342
-        if ( $permalink = get_permalink() ) {
343
-            $datas['permalink'] = $permalink;
344
-        }
342
+		if ( $permalink = get_permalink() ) {
343
+			$datas['permalink'] = $permalink;
344
+		}
345 345
 
346
-        foreach ( $_SERVER as $key => $value ) {
346
+		foreach ( $_SERVER as $key => $value ) {
347 347
 			if ( ! in_array( $key, array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ) ) && is_string( $value ) ) {
348 348
 				$datas[ $key ] = wp_strip_all_tags( $value );
349
-            } else {
349
+			} else {
350 350
 				$datas[ $key ] = '';
351
-            }
351
+			}
352 352
 
353
-            unset($key, $value);
354
-        }
355
-    }
353
+			unset($key, $value);
354
+		}
355
+	}
356 356
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -7,20 +7,20 @@  discard block
 block discarded – undo
7 7
         FrmEntry::sanitize_entry_post( $values );
8 8
         $errors = array();
9 9
 
10
-        if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) {
10
+        if ( ! isset( $values['form_id'] ) || ! isset( $values['item_meta'] ) ) {
11 11
             $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' );
12 12
             return $errors;
13 13
         }
14 14
 
15
-		if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values[ 'frm_submit_entry_' . $values['form_id'] ] ) || ! wp_verify_nonce( $values[ 'frm_submit_entry_' . $values['form_id'] ], 'frm_submit_entry_nonce' ) ) ) {
15
+		if ( FrmAppHelper::is_admin() && is_user_logged_in() && ( ! isset( $values['frm_submit_entry_' . $values['form_id']] ) || ! wp_verify_nonce( $values['frm_submit_entry_' . $values['form_id']], 'frm_submit_entry_nonce' ) ) ) {
16 16
             $errors['form'] = __( 'You do not have permission to do that', 'formidable' );
17 17
         }
18 18
 
19
-        if ( ! isset($values['item_key']) || $values['item_key'] == '' ) {
20
-            $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
19
+        if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) {
20
+            $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
21 21
         }
22 22
 
23
-        $where = apply_filters('frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) );
23
+        $where = apply_filters( 'frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) );
24 24
 		// Don't get subfields
25 25
 		$where['fr.parent_form_id'] = array( null, 0 );
26 26
 		// Don't get excluded fields (like file upload fields in the ajax validation)
@@ -28,20 +28,20 @@  discard block
 block discarded – undo
28 28
 			$where['fi.type not'] = $exclude;
29 29
 		}
30 30
 
31
-        $posted_fields = FrmField::getAll($where, 'field_order');
31
+        $posted_fields = FrmField::getAll( $where, 'field_order' );
32 32
 
33 33
         // Pass exclude value to validate_field function so it can be used for repeating sections
34 34
         $args = array( 'exclude' => $exclude );
35 35
 
36 36
         foreach ( $posted_fields as $posted_field ) {
37
-            self::validate_field($posted_field, $errors, $values, $args);
38
-            unset($posted_field);
37
+            self::validate_field( $posted_field, $errors, $values, $args );
38
+            unset( $posted_field );
39 39
         }
40 40
 
41 41
         // check for spam
42 42
         self::spam_check( $exclude, $values, $errors );
43 43
 
44
-        $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact('exclude') );
44
+        $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude' ) );
45 45
 
46 46
         return $errors;
47 47
     }
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
         );
56 56
         $args = wp_parse_args( $args, $defaults );
57 57
 
58
-        if ( empty($args['parent_field_id']) ) {
59
-			$value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : '';
58
+        if ( empty( $args['parent_field_id'] ) ) {
59
+			$value = isset( $values['item_meta'][$args['id']] ) ? $values['item_meta'][$args['id']] : '';
60 60
         } else {
61 61
             // value is from a nested form
62 62
             $value = $values;
@@ -65,18 +65,18 @@  discard block
 block discarded – undo
65 65
         // Check for values in "Other" fields
66 66
         FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args );
67 67
 
68
-        if ( isset($posted_field->field_options['default_blank']) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) {
68
+        if ( isset( $posted_field->field_options['default_blank'] ) && $posted_field->field_options['default_blank'] && $value == $posted_field->default_value ) {
69 69
             $value = '';
70 70
         }
71 71
 
72 72
 		// Check for an array with only one value
73 73
 		// Don't reset values in "Other" fields because array keys need to be preserved
74
-		if ( is_array($value) && count( $value ) == 1 && $args['other'] !== true ) {
75
-			$value = reset($value);
74
+		if ( is_array( $value ) && count( $value ) == 1 && $args['other'] !== true ) {
75
+			$value = reset( $value );
76 76
 		}
77 77
 
78 78
         if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) {
79
-			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' );
79
+			$errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' );
80 80
         } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) {
81 81
             $_POST['item_name'] = $value;
82 82
         }
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 			self::validate_phone_field( $errors, $posted_field, $value, $args );
89 89
 		}
90 90
 
91
-        FrmEntriesHelper::set_posted_value($posted_field, $value, $args);
91
+        FrmEntriesHelper::set_posted_value( $posted_field, $value, $args );
92 92
 
93
-        self::validate_recaptcha($errors, $posted_field, $args);
93
+        self::validate_recaptcha( $errors, $posted_field, $args );
94 94
 
95
-        $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value, $args);
95
+        $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args );
96 96
     }
97 97
 
98 98
 	public static function validate_url_field( &$errors, $field, &$value, $args ) {
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
             return;
101 101
         }
102 102
 
103
-        if ( trim($value) == 'http://' ) {
103
+        if ( trim( $value ) == 'http://' ) {
104 104
             $value = '';
105 105
         } else {
106 106
             $value = esc_url_raw( $value );
107
-            $value = preg_match('/^(https?|ftps?|mailto|news|feed|telnet):/is', $value) ? $value : 'http://'. $value;
107
+            $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'http://' . $value;
108 108
         }
109 109
 
110 110
         //validate the url format
111
-        if ( ! preg_match('/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value) ) {
112
-			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
111
+        if ( ! preg_match( '/^http(s)?:\/\/([\da-z\.-]+)\.([\da-z\.-]+)/i', $value ) ) {
112
+			$errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
113 113
         }
114 114
     }
115 115
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
         }
120 120
 
121 121
         //validate the email format
122
-        if ( ! is_email($value) ) {
123
-			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
122
+        if ( ! is_email( $value ) ) {
123
+			$errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
124 124
         }
125 125
     }
126 126
 
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 			return;
131 131
 		}
132 132
 
133
-		if ( ! is_numeric( $value) ) {
134
-			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
133
+		if ( ! is_numeric( $value ) ) {
134
+			$errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
135 135
 		}
136 136
 
137 137
 		// validate number settings
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 			if ( $frm_settings->use_html && isset( $field->field_options['minnum'] ) && isset( $field->field_options['maxnum'] ) ) {
142 142
 				//minnum maxnum
143 143
 				if ( (float) $value < $field->field_options['minnum'] ) {
144
-					$errors[ 'field' . $args['id'] ] = __( 'Please select a higher number', 'formidable' );
144
+					$errors['field' . $args['id']] = __( 'Please select a higher number', 'formidable' );
145 145
 				} else if ( (float) $value > $field->field_options['maxnum'] ) {
146
-					$errors[ 'field' . $args['id'] ] = __( 'Please select a lower number', 'formidable' );
146
+					$errors['field' . $args['id']] = __( 'Please select a lower number', 'formidable' );
147 147
 				}
148 148
 			}
149 149
 		}
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		$pattern = self::phone_format( $field );
158 158
 
159 159
 		if ( ! preg_match( $pattern, $value ) ) {
160
-			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
160
+			$errors['field' . $args['id']] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
161 161
 		}
162 162
 	}
163 163
 
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
 			return;
210 210
 		}
211 211
 
212
-        if ( ! isset($_POST['g-recaptcha-response']) ) {
212
+        if ( ! isset( $_POST['g-recaptcha-response'] ) ) {
213 213
             // If captcha is missing, check if it was already verified
214 214
 			if ( ! isset( $_POST['recaptcha_checked'] ) || ! wp_verify_nonce( $_POST['recaptcha_checked'], 'frm_ajax' ) ) {
215 215
                 // There was no captcha submitted
216
-				$errors[ 'field' . $args['id'] ] = __( 'The captcha is missing from this form', 'formidable' );
216
+				$errors['field' . $args['id']] = __( 'The captcha is missing from this form', 'formidable' );
217 217
             }
218 218
             return;
219 219
         }
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 			),
227 227
 		);
228 228
         $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $arg_array );
229
-        $response = json_decode(wp_remote_retrieve_body( $resp ), true);
229
+        $response = json_decode( wp_remote_retrieve_body( $resp ), true );
230 230
 
231 231
         if ( isset( $response['success'] ) && ! $response['success'] ) {
232 232
             // What happens when the CAPTCHA was entered incorrectly
233
-			$errors[ 'field' . $args['id'] ] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid'];
233
+			$errors['field' . $args['id']] = ( ! isset( $field->field_options['invalid'] ) || $field->field_options['invalid'] == '' ) ? $frm_settings->re_msg : $field->field_options['invalid'];
234 234
         }
235 235
     }
236 236
 
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 
260 260
 	private static function is_akismet_spam( $values ) {
261 261
 		global $wpcom_api_key;
262
-		return ( is_callable('Akismet::http_post') && ( get_option('wordpress_api_key') || $wpcom_api_key ) && self::akismet( $values ) );
262
+		return ( is_callable( 'Akismet::http_post' ) && ( get_option( 'wordpress_api_key' ) || $wpcom_api_key ) && self::akismet( $values ) );
263 263
 	}
264 264
 
265 265
 	private static function is_akismet_enabled_for_user( $form_id ) {
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	}
269 269
 
270 270
     public static function blacklist_check( $values ) {
271
-        if ( ! apply_filters('frm_check_blacklist', true, $values) ) {
271
+        if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) {
272 272
             return false;
273 273
         }
274 274
 
@@ -278,9 +278,9 @@  discard block
 block discarded – undo
278 278
     		return false;
279 279
     	}
280 280
 
281
-    	$content = FrmEntriesHelper::entry_array_to_string($values);
281
+    	$content = FrmEntriesHelper::entry_array_to_string( $values );
282 282
 
283
-		if ( empty($content) ) {
283
+		if ( empty( $content ) ) {
284 284
 		    return false;
285 285
 		}
286 286
 
@@ -289,11 +289,11 @@  discard block
 block discarded – undo
289 289
     	foreach ( (array) $words as $word ) {
290 290
     		$word = trim( $word );
291 291
 
292
-    		if ( empty($word) ) {
292
+    		if ( empty( $word ) ) {
293 293
     			continue;
294 294
     		}
295 295
 
296
-    		if ( preg_match('#' . preg_quote( $word, '#' ) . '#', $content) ) {
296
+    		if ( preg_match( '#' . preg_quote( $word, '#' ) . '#', $content ) ) {
297 297
     			return true;
298 298
     		}
299 299
     	}
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 			unset( $key, $data );
323 323
 		}
324 324
 
325
-        $response = Akismet::http_post($query_string, 'comment-check');
325
+        $response = Akismet::http_post( $query_string, 'comment-check' );
326 326
 
327 327
 		return ( is_array( $response ) && $response[1] == 'true' );
328 328
     }
@@ -345,12 +345,12 @@  discard block
 block discarded – undo
345 345
 
346 346
         foreach ( $_SERVER as $key => $value ) {
347 347
 			if ( ! in_array( $key, array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ) ) && is_string( $value ) ) {
348
-				$datas[ $key ] = wp_strip_all_tags( $value );
348
+				$datas[$key] = wp_strip_all_tags( $value );
349 349
             } else {
350
-				$datas[ $key ] = '';
350
+				$datas[$key] = '';
351 351
             }
352 352
 
353
-            unset($key, $value);
353
+            unset( $key, $value );
354 354
         }
355 355
     }
356 356
 }
Please login to merge, or discard this patch.