<?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>By Jason Gill</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:01:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<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>
<pre> $form['newsletter'] = array('#type' =&gt; 'checkbox',
    '#title' =&gt; t('Sign me up for the Newsletter'),
  );</pre>
<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>
<pre lang="php" line="n">// Compose the body:</pre>
<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>
<pre> if ($form_values['newsletter'] == 1) {
    $message[] = "Yes, please send me a newsletter";
  } else {
    $message[] = "No, please do not send me a newsletter";
  }</pre>
<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>8</slash:comments>
		</item>
	</channel>
</rss>

