Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wpcf7_text_validation_filter( $result, $tag ) {
- /* Array of free email domains */
- $FREE_DOMAINS = array('gmail.com', 'yahoo.com', 'hotmail.com');
- $type = $tag['type'];
- $name = $tag['name'];
- $_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
- if ( 'text*' == $type ) {
- if ( '' == $_POST[$name] ) {
- $result['valid'] = false;
- $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
- }
- }
- if ( 'email' == $type || 'email*' == $type ) {
- $arr = explode( '@', $_POST[$name] );
- if( ! empty( $arr[1] ) ){
- $domain = strtolower( trim( $arr[1] ) );
- } else {
- $domain = false;
- }
- if ( 'email*' == $type && '' == $_POST[$name] ) {
- $result['valid'] = false;
- $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
- } elseif ( '' != $_POST[$name] && ! is_email( $_POST[$name] ) ) {
- $arr = explode( '@', $_POST[$name] );
- $result['valid'] = false;
- $result['reason'][$name] = wpcf7_get_message( 'invalid_email' );
- } elseif ( $domain && in_array( $domain, $FREE_DOMAINS ) ) {
- $result['valid'] = false;
- $result['reason'][$name] = wpcf7_get_message( 'invalid_email' );
- }
- }
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement