We discussed how to use pipes in Contact Form 7 and create dynamic emails, but what if you really need to get the value before the pipe (‘|’)? In a previous example we created an email form that provides a user-selected value in the email which can be used to determine who would receive an email. Now we’re going to build upon that example and learn how to get the value before the pipe.
Reminder on how to apply a pipe
Remember how we set the email recipient based on a user’s selection? It required using pipes in the various values in the form builder of Contact Form 7.
[select* email-recipient “Sales|sales@yourdomain.com” “Tech Support|support@yourdomain.com” “Inquiry|info@yourdomain.com”]
The “*” indicates the field is required. Once you have the field set up, you would add [email-recipient] to the To: field of the email builder.
Getting the value before the pipe
There is a plugin that is a little hard to find, and this plugin gets the before pipe value in Contact Form 7. Install the plugin as you have any other plugin in your WordPress installation. Once the plugin is installed, you can then use [email-recipient:before] within your email body or perhaps in the subject line to get the value before the pipe in our example above.
Final example
Use the form below to test the results of the “:before” value.
You can download Contact Form 7 from the WordPress Plugin Repository.