I want to set the title of the email based on some of the fields.

eg if a form submitter called Richard, creates a form subject called Seeking Drupal Job, under category JobSeeker

I would like to set the email title to something like Web Enquiry Form :%user;%jobseeker;%subject which would set the email title to Web Enquiry Form:Richard;JobSeeker;Seeking Drupal Job.

Can the field names be used as place holders to achieve something like that?

Comments

vuzzbox’s picture

You can do this. There might be simpler ways to do it, but here's one I know will work.

When defining your webform and compenents you can identify that you would like to use the value of a specific field as your subject. In Addtional Processing you can set the value of that field when it is submitted.

Here are the steps to produce this:

Create a component called "EmailSubject" as a hidden field. In configuration, set that as the field to use for your subject line.

You will be able to populate this field at runtime, but you need to determine what the index of that field is before you can write the code to do it. I'm sure there's a simpler way to do this, but what I know you can do is add the following line to your webform-mail.tpl.php file (which you should copy to the root of your theme folder before editing):

print_r($form_values);

This will spew forth into the email all of the field indexes and values in your form. So submit a form, get the email, look through it until you can determine the index value of your new Subject field. It may not be obvious.

Let's assume for our purposes that the index of the Subject field is 1. And let's assume you have three additional fields on your form: User, JobSeeker and Subject

In Additional Processing your code might look like this:

$form_values['submitted'][1] = "Web Enquiry Form ".$form_values['submitted_tree']['User'].";".$form_values['submitted_tree']['JobSeeker'].";".$form_values['submitted_tree']['Subject'];

Hope that helps.

brnnrc’s picture

I tried to rewrite the email address used as destination address:

$form_values['submitted'][13]='foo@bar';

but it does not work: $form_values dump is correct, but the email goes to the previous address.
I think the Additional Processing runs after the mail array will be computed.

kindafun’s picture

I've got the same problem, would love to get an answer on this one. It does seem that what is set to go in mail is done prior to Additional Processing.

kindafun’s picture

Turned out to be easy you just have to put the info in the right array.

$form_values['submitted_tree']['your_component_key'] = $whatever_you_want;

Check this out: http://drupal.org/handbook/modules/webform/submission-code

brnnrc’s picture

I forgot to say I set $form_values['submitted_tree']['your_component_key'] with no success.

quicksketch’s picture

Status: Active » Closed (duplicate)