@@ -1,18 +1,18 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FrmEntryValidate { |
| 4 | - public static function validate( $values, $exclude = false ) { |
|
| 5 | - FrmEntry::sanitize_entry_post( $values ); |
|
| 6 | - $errors = array(); |
|
| 4 | + public static function validate( $values, $exclude = false ) { |
|
| 5 | + FrmEntry::sanitize_entry_post( $values ); |
|
| 6 | + $errors = array(); |
|
| 7 | 7 | |
| 8 | - if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
| 9 | - $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
| 10 | - return $errors; |
|
| 11 | - } |
|
| 8 | + if ( ! isset($values['form_id']) || ! isset($values['item_meta']) ) { |
|
| 9 | + $errors['form'] = __( 'There was a problem with your submission. Please try again.', 'formidable' ); |
|
| 10 | + return $errors; |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | 13 | 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' ) ) ) { |
| 14 | - $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
| 15 | - } |
|
| 14 | + $errors['form'] = __( 'You do not have permission to do that', 'formidable' ); |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | 17 | self::set_item_key( $values ); |
| 18 | 18 | |
@@ -57,24 +57,24 @@ discard block |
||
| 57 | 57 | return FrmField::getAll( $where, 'field_order' ); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
| 61 | - $defaults = array( |
|
| 62 | - 'id' => $posted_field->id, |
|
| 63 | - 'parent_field_id' => '', // the id of the repeat or embed form |
|
| 64 | - 'key_pointer' => '', // the pointer in the posted array |
|
| 65 | - 'exclude' => array(), // exclude these field types from validation |
|
| 66 | - ); |
|
| 67 | - $args = wp_parse_args( $args, $defaults ); |
|
| 60 | + public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
|
| 61 | + $defaults = array( |
|
| 62 | + 'id' => $posted_field->id, |
|
| 63 | + 'parent_field_id' => '', // the id of the repeat or embed form |
|
| 64 | + 'key_pointer' => '', // the pointer in the posted array |
|
| 65 | + 'exclude' => array(), // exclude these field types from validation |
|
| 66 | + ); |
|
| 67 | + $args = wp_parse_args( $args, $defaults ); |
|
| 68 | 68 | |
| 69 | - if ( empty($args['parent_field_id']) ) { |
|
| 69 | + if ( empty($args['parent_field_id']) ) { |
|
| 70 | 70 | $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; |
| 71 | - } else { |
|
| 72 | - // value is from a nested form |
|
| 73 | - $value = $values; |
|
| 74 | - } |
|
| 71 | + } else { |
|
| 72 | + // value is from a nested form |
|
| 73 | + $value = $values; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // Check for values in "Other" fields |
|
| 77 | - FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
| 76 | + // Check for values in "Other" fields |
|
| 77 | + FrmEntriesHelper::maybe_set_other_validation( $posted_field, $value, $args ); |
|
| 78 | 78 | |
| 79 | 79 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
| 80 | 80 | |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | $value = trim( $value ); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
| 90 | + if ( $posted_field->required == '1' && ! is_array( $value ) && trim( $value ) == '' ) { |
|
| 91 | 91 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'blank' ); |
| 92 | - } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
| 93 | - $_POST['item_name'] = $value; |
|
| 94 | - } |
|
| 92 | + } else if ( $posted_field->type == 'text' && ! isset( $_POST['item_name'] ) ) { |
|
| 93 | + $_POST['item_name'] = $value; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | FrmEntriesHelper::set_posted_value( $posted_field, $value, $args ); |
| 97 | 97 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
| 105 | 105 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) { |
| 109 | 109 | $is_default = ( FrmField::is_option_true_in_object( $field, 'default_blank' ) && $value == $field->default_value ); |
@@ -239,34 +239,34 @@ discard block |
||
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | self::validate_field_types( $errors, $field, '', $args ); |
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * check for spam |
|
| 246 | - * @param boolean $exclude |
|
| 247 | - * @param array $values |
|
| 248 | - * @param array $errors by reference |
|
| 249 | - */ |
|
| 250 | - public static function spam_check( $exclude, $values, &$errors ) { |
|
| 251 | - if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
| 252 | - // only check spam if there are no other errors |
|
| 253 | - return; |
|
| 254 | - } |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * check for spam |
|
| 246 | + * @param boolean $exclude |
|
| 247 | + * @param array $values |
|
| 248 | + * @param array $errors by reference |
|
| 249 | + */ |
|
| 250 | + public static function spam_check( $exclude, $values, &$errors ) { |
|
| 251 | + if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
|
| 252 | + // only check spam if there are no other errors |
|
| 253 | + return; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | 256 | if ( self::is_honeypot_spam() || self::is_spam_bot() ) { |
| 257 | 257 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if ( self::blacklist_check( $values ) ) { |
|
| 261 | - $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' ); |
|
| 262 | - } |
|
| 260 | + if ( self::blacklist_check( $values ) ) { |
|
| 261 | + $errors['spam'] = __( 'Your entry appears to be blacklist spam!', 'formidable' ); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - if ( self::is_akismet_spam( $values ) ) { |
|
| 264 | + if ( self::is_akismet_spam( $values ) ) { |
|
| 265 | 265 | if ( self::is_akismet_enabled_for_user( $values['form_id'] ) ) { |
| 266 | 266 | $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); |
| 267 | 267 | } |
| 268 | - } |
|
| 269 | - } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | private static function is_honeypot_spam() { |
| 272 | 272 | $honeypot_value = FrmAppHelper::get_param( 'frm_verify', '', 'get', 'sanitize_text_field' ); |
@@ -288,15 +288,15 @@ discard block |
||
| 288 | 288 | return ( isset( $form->options['akismet'] ) && ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] != 'logged' || ! is_user_logged_in() ) ); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - public static function blacklist_check( $values ) { |
|
| 292 | - if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
| 293 | - return false; |
|
| 294 | - } |
|
| 291 | + public static function blacklist_check( $values ) { |
|
| 292 | + if ( ! apply_filters('frm_check_blacklist', true, $values) ) { |
|
| 293 | + return false; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
| 297 | - if ( empty( $mod_keys ) ) { |
|
| 298 | - return false; |
|
| 299 | - } |
|
| 296 | + $mod_keys = trim( get_option( 'blacklist_keys' ) ); |
|
| 297 | + if ( empty( $mod_keys ) ) { |
|
| 298 | + return false; |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | 301 | $content = FrmEntriesHelper::entry_array_to_string( $values ); |
| 302 | 302 | if ( empty( $content ) ) { |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $user_info = self::get_spam_check_user_info( $values ); |
| 309 | 309 | |
| 310 | 310 | return wp_blacklist_check( $user_info['comment_author'], $user_info['comment_author_email'], $user_info['comment_author_url'], $content, $ip, $user_agent ); |
| 311 | - } |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | 313 | /** |
| 314 | 314 | * Check entries for Akismet spam |