Customising contact form emails based on field values

You can now customise contact emails based on which contact form is being submitted or any other form field value. Awesome!

Today we added a feature we’ve been meaning to do for quite some time. You can now customise contact emails based on which contact form is being submitted! Awesome!

To be honest, I cannot see why it took so long because it is a cracking little update. Not only can you use it to customise the message based on what form, but the approach we took was to be able to customise the email based on any value in the submitted form.

So if you have two contact forms and we want a custom response on one of the forms. The first thing I did is to add a hidden input field to the form and set the value so I can easily identify when that form is submitted. Just like this …

<input type=“hidden” name=“form_name” value=“first-form”>

Now, here is the fun part.

In the email snippet, let’s grab the value of which form is being submitted.

{% capture form_name %}{{ contact.parameters | find_param: 'form_name’ }}{% endcapture %}

Great. Now that I have a variable called form_name, I can customise my email like this …

{% case form_name %}
{% when ‘first-form’ %}
  ... Special layout just for first form goes here. You can access form field values directly like this
  {{ contact.parameters | find_param: ‘contacts’ }}
{% else %}
  ... existing layout goes here
{% endcase %}

We used this technique to distinguish between quote request forms, doctors referral forms and plain old contact forms. It works a treat.

by Craig Sullivan

24 Oct 2014