Last updated March 31, 2015. Created on June 10, 2010.
Edited by davidhofmann, quicksketch, meridiandigital, nicholas.alipaz. Log in to edit this page.

7.x-4.x

Fields can be called as [submission:values:FIELD_KEY]

If your field in a field set you can use

[submission:values:FIELDSET_FIELD_KEY:FIELD_KEY]

You can find the Field Key and the Field Set Field Key by selecting Edit for the appropriate items on the Form components tab.

Webform 3.x

In newer versions of Webform (3.9 and higher), the e-mail Subject field is tokens-enabled even though it does not include a list of tokens below the field. The tokens for %value[key] are the most useful tokens for generating dynamic subject lines.

Webform 2.x and older 3.x versions

To create a custom email subject using user submitted values you may do it in the following way:

  1. Add a new form component of the type "hidden". Let's call it "Email subject".
  2. Using the desired email subject in the original post for this issue as an example, in the default value field for this component enter:
    Event enquiry from %cid[x] for %cid[y] in %cid[z]

    The x, y, and z keys above should represent the component id numbers (cid) relating to the form's component fields for "name", "eventdate", and "city" (Hint: you can find the cid for a form component by mousing over it's Edit link in the table on the "Form components" page and noting the last argument in the link's url). It seems that %cid is set up in the module as a token for the array of the form's submitted values.

  3. Choose "Email subject" in the Component drop-down for the E-mail subject setting on the webform's Configuration page.

Naturally, this same technique will work for the "Email from name" and "Email from address" settings as well.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

dx17’s picture

Great article, it helps me a lot. But does anyone know what to do in case of multidimensional arrays.

i.e. I want to add the values of my date field into the subject:
"%cid[1] plans a trip on %cid[2]"
results in
"DX17 plans a trip on Array"

Neither this example "%cid[1] plans a trip on %cid[2][day]" nor this one "%cid[1] plans a trip on %cid[2][0]" works.

Thanks for help.

amwranes’s picture

When using %cid[x] in to create a custom e-mail subject, the e-mail goes out with %cid[x] in it instead of the value. I am using Mollom for spam control, but disabling Mollom for the form doesn't fix the issue, so it doesn't appear to be that.

Edit: %value[field name] is now used...

Andrey Zakharov’s picture

Thanks, amwranes! U save my day

doublejosh’s picture

Looks like Webform 6.x-2.9 is %cid[component #]

wheelercreek’s picture

You don't need to make a new component. Just click to "custom subject" when you are entering the emails where the form should send to. I found that you can enter token variables in the subject line (and presumably any of these fields), not just the email template box.

For example I selected a custom subject line and entered: registration %email[name] And the name field from the webform came through in the subject.

brkelner’s picture

Thank you for the information.
I now can have both the First Name and Last Name in the subject line of the submitted webform

Brian Kelner

gthing’s picture

Do you have to do something special if the fields you're calling are inside a fieldset? I can't get it to work with that configuration.

nicholas.alipaz’s picture

depends on your version I believe. In my experience I had to specify the name of the fieldset, but I am not sure on your situation.

Los Angeles Web Design and development for Drupal.

aubjr_drupal’s picture

Saved me some time for sure - Thanks!

amoutiers’s picture

Does someone has the solution for drupal 7 ? None of the above works for me

claudiuceus’s picture

Hi Ptitoine,

I'm using Drupal 7 with Webforms 3.9:

1. Go to your Form Components
2. Edit the field you want to show up on your subject
3. Get the Field Key, in my case it was: full_name

Now go back to your email, and in your custom subject use:

Text you want customized and add this: %value[Field Key]

In my case:
Customized text %value[full_name]

Please let me know if it works?

jamwilli’s picture

I can only get the first field to appear. The subject line ends up with "US for %value[candidate]. Any idea why the second field will not populate?

VonZesen’s picture

Maybe you have nested your field "candidate" in a fieldset? In this case you have to write "US for %value[field_key_of_your_fieldset][candidate]".

nicholsj’s picture

This has changed.

You now need to use [submission:values:[field key]:nolabel]

(the :nolabel bit is optional - and hides the field label)

eg
"This is an email about [submission:values:subject:nolabel] " where the relevant field key is "subject"

davidhofmann’s picture

For custom subject, if your using a field set, you can use the following:

[submission:values:YOUR_FIELDSET_FORM_KEY:YOUR_FIELD_KEY]

Example:

Field Set named: student
Field in Set: name

[submission:values:students:name]

perisdr’s picture

The module should add a description under the subject to clarify that you can use the same tokens there as in the mail body.