How to Use Pipes in Contact Form 7

Contact Form 7 gives you the capabilities to create forms to accomplish a variety of needs. There is a feature that exists that some may not realize, and it can be very powerful in how you use it. Contact Form 7 has the ability for pipe (‘|’) support which allows you to present one value to people who submit the form, and then get a different value passed to you via an email.

Contact Form 7 Pipe Example | Brandon CoppernollYou can use the pipe only in the drop-down menu values, radio buttons, or checkboxes. By default, this feature is available to installations of the plugin. The anatomy of the value is “<user-visible-field>|<data-value>”.

Applying the Pipe in the Field

One of the most common uses is providing a series of options to users and using those options to select who may receive an email. This can be done via select, radio, or checkbox tags.

[select* email-recipient "Sales|sales@yourdomain.com" "Tech Support|support@yourdomain.com" "Inquiry|info@yourdomain.com"]

The “*” indicates the field is required.

Get the Value of the Field

Using our example above, it’s time to get the value and send an email to the selected email address. Within the Mail section, look at the To: field. You will want to include [email-recipient] in this field, and the value after the pipe is used for the email recipient.

Final Example

Using the example created above, this is how the form will look.

Your Email

Who Do You Want to Reach?

You can download Contact Form 7 from the WordPress Plugin Repository.

Any questions?

  • Jack Meyer

    Is there a way to display the first part of the piped field in the email body, ie, if you have a “Reason for Contact” field, that determines who the email is sent to, but in the body of the mail you want to report the Reason for Contact.

  • http://brandoncoppernoll.com/ Brandon Coppernoll

    There is a way to do it, and I had to do some digging to find the solution or else I was going to end up building something. It’s hard to find, but I found one.

    http://glasshouse.fr/dnload/contact-form-7-beforepipe.zip

    It’s pretty simple. After you install, you can use [email-recipient:before] to get the value before the pipe. I think I’ll write something to show a working example.

    Let me know if that helps!

  • James van der Hoven

    Could you please post an example using the checkbox options. I have tried numerous tricks now, none of which has worked. The select option works but as soon as I try the checkbox option, it fails with the error message…”Failed to send your message. Please try later or contact the administrator by another method.”

  • http://brandoncoppernoll.com/ Brandon Coppernoll

    Are you using checkboxes to potentially send to multiple recipients? If you could provide an example of what you’re trying to do I’ll be happy to help!

  • James van der Hoven

    Thanks for the super quick response Brandon! Here’s my example tag

    [checkbox i_am_interested_in class:i_am_interested_in use_label_element email-recipient "General|jim....@gmail.com" "Undergraduate admission|jim@va...co.za"]

    (domain names removed in example)

    And this is what’s in my TO field

    [email-recipient]

    Thanks again.

  • http://brandoncoppernoll.com/ Brandon Coppernoll

    Try this:

    [checkbox* i_am_interested_in class:i_am_interested_in use_label_element "General|jim....@gmail.com" "Undergraduate admission|jim@va...co.za"]

    In the TO field, use: [i_am_interested_in]

    I took out the extra “email-recipient” from the checkbox and updated the TO field.

    I added * after checkbox to make the field required so they have to send to at least one option in your checkboxes.

    I hope this helps!