<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gilluminate &#187; Drupal</title>
	<atom:link href="http://www.gilluminate.com/tag/drupal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gilluminate.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 Jun 2010 02:50:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Add a field to Contact Us form in Drupal</title>
		<link>http://www.gilluminate.com/2008/03/04/add-a-field-to-contact-us-form-in-drupal/</link>
		<comments>http://www.gilluminate.com/2008/03/04/add-a-field-to-contact-us-form-in-drupal/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 06:19:00 +0000</pubDate>
		<dc:creator>Jason Gill</dc:creator>
				<category><![CDATA[Developer Blog]]></category>
		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://blog.gillumiante.com/2008/03/05/add-a-field-to-contact-us-form-in-drupal</guid>
		<description><![CDATA[I needed to add a checkbox to Drupal&#8217;s Contact Us form for a client of mine. The client requested that I add a way for those filling out the form to request a newsletter. I discovered it&#8217;s pretty easy to add a form field and get it added as part of the email that&#8217;s sent. [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to add a checkbox to Drupal&#8217;s Contact Us form for a client of mine. The client requested that I add a way for those filling out the form to request a newsletter. I discovered it&#8217;s pretty easy to add a form field and get it added as part of the email that&#8217;s sent. You just need to hack into the module on your server (sorry, no GUI for this). Here&#8217;s what I did:</p>
<p>First, find the module file:
<pre>modules/contact/contact.module</pre>
<p>If you prefer command line editing open up that file in your favorite editor. If you prefer the download/edit/upload approach via FTP that will work also. I assume if you have interest in this article, that you have some knowledge of either of those 2 methods. If not, I wonder how you set up Drupal in the first place.</p>
<p>Now that you are in edit mode, find a chunk of code that talks about not allowing anonymous users to send themselves a copy for spam reasons. Found that comment? Good, now just above it you are going to add your field. I found it easy to copy/paste an existing form element and edit it&#8217;s contents, but you can type it out if you like. Actually, feel free to copy/paste and edit my example below. Here&#8217;s what I ended up with:</p>

<div class="wp_codebox"><table><tr id="p52684"><td class="code" id="p5268code4"><pre class="php" style="font-family:monospace;"> <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'newsletter'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'checkbox'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#title'</span> <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sign me up for the Newsletter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You may want to add a comment somewhere in there to remind yourself at a later date that this is no longer part of the original configuration.</p>
<p>That was easy, now I just need to tell it to add content to the email sent out so that when that box is checked, it actually does something! Next look for a chunk of comment code that looks like this:</p>

<div class="wp_codebox"><table><tr id="p52685"><td class="code" id="p5268code5"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Compose the body:</span></pre></td></tr></table></div>

<p>below that you will find a couple lines that start with &#8220;$message[] =&#8221; which is where the body of the email&#8217;s message gets created. Just add another line that says something like the following:</p>

<div class="wp_codebox"><table><tr id="p52686"><td class="code" id="p5268code6"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form_values</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'newsletter'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Yes, please send me a newsletter&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;No, please do not send me a newsletter&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now crank open your form and test it out. Assuming you are the recipient of the email being generated, you will get a nice extra piece of text at the bottom of the email with this new content based on the user&#8217;s input.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gilluminate.com/2008/03/04/add-a-field-to-contact-us-form-in-drupal/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
