WordPress.org

Support

Support » Plugins and Hacks » Contact Form 7 » [Resolved] [Plugin: Contact Form 7] How to do away with blank lines in email for unfilled form items

[Resolved] [Plugin: Contact Form 7] How to do away with blank lines in email for unfilled form items

  • 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/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Takayuki Miyoshi

    @takayukister

    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;
    }

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

    Plugin Author Takayuki Miyoshi

    @takayukister

    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.

    I really appreciate your help. Worked beautifully, BTW.

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] [Plugin: Contact Form 7] How to do away with blank lines in email for unfilled form items’ is closed to new replies.
Skip to toolbar