Customizing the Contact Form Module - Adding or Changing Fields
The default Contact Form Module for Exponent CMS only has a few fields. In this tutorial, you will learn how to change these fields, or add new fields. You can also customize the layout of the email that you recieve.
First, open the file exponentroot/modules/contactmodule/views/Default.tpl in a text editor. If you cannot edit them directly on the server, first download this file, make your changes, save it again, and upload it. I recommend that you use Filezilla as your FTP client.
In this tutorial, I will add a field for their name.
Find the line:
<tr>
<td width="10" style="width: 10px" valign="top">Email:</td>
<td>
<input type="text" name="email" />
</td>
</tr>
Above this line, insert this code:
<tr>
<td width="10" style="width: 10px" valign="top">Name:</td>
<td>
<input type="text" name="name" />
</td>
</tr>
...
On this page you can add any fields you want, change the layout of the form, etc. Just remember what the name="" is for each of the forms--you'll need this for later.
Now, open the file exponentroot/modules/contactmodule/views/_Default.tpl in a text editor. Note the _ character in front of Default.tpl.
Find the code:
MESSAGE:
Email: {$post.email}
Subject: {$post.subject}
Message: {$post.message}
This is what the email will look like. Note, the variable names after $post. are the names of the input fields that are on Default.tpl. So if I want to add a name field, replace that code with this:
MESSAGE:
Name: {$post.name}
Email: {$post.email}
Subject: {$post.subject}
Message: {$post.message}
That's it! Just change these 2 files to change how the form will look and how the email will look.
Current Comments
2 comments so far (post your own)I was thrilled to see how to change the layout of the email that comes from the form.
Unfortunately this advice won't fit for me since I have made my form with the form module instead of this contact module.
Any idea how to modify the layout of the email sent by a form made by form module? Now everything looks messed. Maybe some <br /> added somewhere would already help.
Thanks!
Gene
Posted by Gene on Monday, 04.25.05 @ 03:10pm | #511
I think you have to add the word into language file also in subsystem/lang
Posted by Eric on Friday, 10.12.07 @ 05:23pm | #3045
Rate this Tutorial
Current Rating: