WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
[resolved] How to do away with blank lines in email for unfilled form items (6 posts)

  1. Ray Gulick
    Member
    Posted 3 years ago #

    I love CF7; very flexible and clean. I recently, however, had a need to create a very long form with very few required fields. A blank line in the email is created for each unfilled field and, due to the number of fields, this sometimes creates very long blank spaces in the email and a lot of scrolling to get to the bottom.

    Is there some way to remove these blank lines from the email?

    http://wordpress.org/extend/plugins/contact-form-7/

  2. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    It's easy if you utilize 'wpcf7_mail_components' filter. Add these lines into the functions.php in your active theme:

    add_filter( 'wpcf7_mail_components', 'remove_blank_lines' );
    
    function remove_blank_lines( $mail ) {
    	if ( is_array( $mail ) && ! empty( $mail['body'] ) )
    		$mail['body'] = preg_replace( '|\n\s*\n|', "\n\n", $mail['body'] );
    
    	return $mail;
    }
  3. Ray Gulick
    Member
    Posted 3 years ago #

    That sounds great! Thanks! Was this info available in the docs and I just missed it?

  4. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    That's good.

    Was this info available in the docs and I just missed it?

    No, it's not in docs. I just wrote it for your demand as it's not that difficult.

  5. Ray Gulick
    Member
    Posted 3 years ago #

    I really appreciate your help. Worked beautifully, BTW.

  6. Ray Gulick
    Member
    Posted 3 years ago #

    I made a donation. Well-supported plugins deserve donations from time to time. Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic