Adding a Contact Form to a Drupal 7 Site
Welcome to another Daily Dose of Drupal, this is Episode 10 and this is brought to you by codekarate.com. Today we are going over a very simple Drupal concept. We’re just going to be adding a Contact Form to our Drupal site and in this episode we’re going to use the Drupal Core Contact module and we’ll start off by going to the modules page and you’ll notice that in the core group of modules there’s a module called Contact and let’s go ahead and scroll down and we’ll click on Save and immediately right out of the box that’s all you need to do to get to a Contact Page.
You’ll notice that we now have a Contact page where you can put your name, e-mail address, subject and message and it will send a message to the … whatever you have as a site e-mail for your Drupal site.
If you go into Structure we can change some of these settings, there’s a Contact Form Administration page here and there’s a few things you’ll notice here; there’s a link right there to your Contact Form, it says that there’s a Menu Item that you can turn on if you want and it also says if you’d like to add additional content to the Content Page you can do so as a block which will go over that here in a second but we’ll go ahead and add another category and we’ll call this General Info; you can put who you’d like to receive this.
So just make up an e-mail for now, if you want to have an auto-reply so that it will send the user an auto-reply message; you can say “thanks for contacting me” and you can select if you want this one to be selected by default. So now that you have two; if you go back to your Contact page there’s a category list in here and this will allow you to select what type of category this contact will be in when the user goes to submit a contact form and it will send it to whatever e-mail address is set in that Con tact Form.
So you’ll notice here this is the actual site address or site e-mail for the Drupal 7 site but you can always come in and change it, so we can change that, hit Save and now we have two different e-mail addresses so you could have support questions go to a Support Team and product related questions go to a Sales Team and you could route things that way.
So let’s go back to our Contact Form; it’s very simple, we’re just going to add a little bit of text up here; so go into Structure Blocks and we’re going to add a new block, we’ll call the title Contact Us and we’ll say Contact Form Text and I just added some tags in there so you can see that you can use HTML to format this, you could do whatever you need to make the contact page look better and we only want to show this on the contact page and the reason we want to do this is because we obviously don’t want this block showing up on other pages, we’ll leave everything else the same and hit Save Block and then we will go ahead and find this block which should be down here and disabled and we can drag it up to … we can put it in the Feature section and we’ll say of our team, we save that and go back to the Contact page and you’ll see now we have this Contact Us text in the featured section.
We can always move that of course to the main content section, save it and now it’s going to show up here. So there’s a couple of things that you can do to increase the design or enhance the design of your Contact page. One thing you’ll notice is that obviously limited on the fields that you can use and you’re kind of stuck with what it gives you.
There’s a couple of ways you can change that; you can either create a custom module and add some fields using the form API which I might suggests if you’re working on a very large site that is using multiple environments and version control but if you just need a contact form for a simple site then you may need to look into the Web Form module and that’s what we’re going to go over next time.
So until net time, this is the Daily Dose of Drupal, you can follow me on Twitter @smthomas3 and subscribe to my codekarate.com newsletter and I will see you next time.