# Tidy Up Contact Form 7 Submissions

> Trims stray spaces, lowercases email addresses and collapses repeated blank lines in Contact Form 7 submissions before they are emailed or stored.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: contact-form-7, data, cleanup
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/cf7-normalize-posted-data/

## Code

```php
add_filter( 'wpcf7_posted_data', function ( $data ) {
    foreach ( (array) $data as $key => $value ) {
        if ( is_array( $value ) || 0 === strpos( $key, '_' ) ) {
            continue;
        }

        $value = trim( preg_replace( "/(\r?\n){3,}/", "\n\n", (string) $value ) );

        if ( false !== stripos( $key, 'email' ) ) {
            $value = strtolower( $value );
        }

        $data[ $key ] = $value;
    }

    return $data;
} );
```

## Notes

Field names containing "email" are lowercased; everything else keeps its case.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Tidy Up Contact Form 7 Submissions" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
