
Creating a Letter to the Editor Form in Drupal
A common action advocacy organizations ask their constituents to take is to submit a letter to the editor to their local newspaper. Not only does an organization want their supporters to do it but they also want to be able to track who submitted them and how many were submitted.
There are many (expensive) software options that can do this through your website but DharmaTech recently helped a client, HEAL Utah, achieve this through their Drupal website using the very powerful Webform module.
Our goal was to have a form where HEAL Utah members can send a letter to any number of Utah newspapers and it look like an email sent directly from their email client. Here's what we did:
- Create the form as normal using webform. One of the fields will be a list of newspapers your constituents can submit their letter to. In webform, the component is a select type with options for every major paper in Utah. Here, you will need to enter one option per line and, for each line, separate the paper's email address from their name with a pipe. It should look like this on every line:

- Create a field called email subject with optional default text.
- Since almost all newspapers require at least a phone number and address for the writer, make those fields required as well.
- Naturally, you'll want to create a text area type field called body. This is where people will enter their letter text.
- Once your components are built, select which fields will be sent in the email to each newspaper.

Using the column of check boxes called "Email" only include the fields that the newspaper will require. In this example, all but email subject (that will be used in the subject field not the body of the message), newspaper, and email are included. - Now go to the configuration page for your webform and scroll down to the setting called "Conditional Recipients."

Select the name of the component that lists your newspapers (in this case, Newspaper). - Under webform mail settings, select the components that will make up the email. These include the email from name, address, and subject.

These settings allow you to make a field, for example subject, be the actual subject of the email sent to each newspaper. - Now you will need to do some theming. Because our goal is to make the email received by each newspaper look like any other email, we now need to format the default webform notification email theme. Note, this is for advanced users only since programming skills are required. Instructions on how to theme emails are here. As an example, the LTE is node id 907. We created a file in sites/all/themes/healutah/ called webform-mail-907.tpl.php with the following code:
$v = $form_values['submitted_tree']; print $v['letter_body']['body'] ."\n\n"; print $v['firstname'] .' '. $v['lastname'] ."\n"; print $v['phone'] ."\n"; print $v['street_address'] ."\n"; print $v['city'] .', '. $v['state'] .' '. $v['zip_code'] ."\n";
- A last and pretty cool touch is to add a word counter to your body field. Letters to the editor are recommended to be kept below 250 words. So we added a word counter to this form so people know how many words they've typed in real time! Once you hit 250, it turns red (but still lets you type since it's a soft limit). Read how to do this in Jason's blog post here.
- Test and that's it!
Not only will emails sent to a newspaper look like real emails but they will be sent individually so a newspaper editor wont know the same letter was sent to other newspapers. Plus, with webform, you can track how many submissions you have received, export the list as a spreadsheet to then import into your database, for example, and much more.
To learn more about webform, visit: http://drupal.org/project/webform
To see the form we built for HEAL Utah, visit: http://healutah.org/takeaction/submit_lte (Note: this form is "live." If you fill it out, emails will be sent to the newspaper(s) you select!)
EDIT: I'm attaching a text file that will allow you to quickly and easily import a sample LTE form already built! All you will need is the node export and webform modules enabled. Go to /admin/content/import and paste the code. Node Export will do the rest!
Download file here: http://dharmatech.org/sites/default/files/u16/lte_sample_webform.txt
Form Letters
Hi
I like what you have done. I was wanting to create a form letter where a standard formatted letter was used but elements could be added from form submitted by users, eg reporting litter in street. So in essence standard letter gets sent with data stripped out of other form so you get customised letters sent. Have you done any thing like this or make a suggestion where to look.
I am afraid my programming skills are very limited.
andrew
Hi Andrew. I think you may
Hi Andrew. I think you may want to look at creating a unique content type using the CCK module then using the rules module to create the email that gets sent out. The Rules module allows you to essentially "mail merge" data that someone enters in the form into a template email. It also has a lot of power because you can use conditions to account for the scenario where maybe different emails get sent based on the role of the person filling it out. If you need more details on how to do this, maybe we can help. My email is tony@dharmatech.org
Hope this helps
thanks
Tony
Re request
Thanks for information I will let you know how I get on. Andrew
Thanks!
Nice tutorial. I was looking specifically for the theming part for the webform emails and this helped tremendously.
No problem, Mike. Glad it
No problem, Mike. Glad it helped.
- Tony
Webform
THanks for the tutorial. I'm still having issues modifiying the webform-mail.tpl file. When I use your code, I get the exact code in my email. How (or what is missing) to make the email look like a form letter. I have a form that I'd like to theme so that when the business owner receives it, it is easil to read.
The form is at http://www.cordillpropane.com/content/form/new-customer-form. When a user submits the form, the data gets sent to the company so they can follow up. I'm trying to clean up the email CordillPropane receives. I can't really find anything online to help and everything I find on the internet is vague. I'm not an expert at php so that doesn't really help either.
Any help is greatly appreciated.
Mike