Magento - Add additional fields to the Contact Form
If you need to add additional fields to Magento's default contact form, read on! First open the form.phtml file located in your /magento_root/app/design/frontend/YOUR_INTERFACE/YOUR_THEME/template/contacts/form.phtml. So, we are going to add a subject field to this contact form so that customers tell us the subject of their email. Open the file for editing in your favorite editor.
Find this section in the file below (this should be around line 39):
<div class="input-box">
<label for="name"><?php echo Mage::helper('contacts')->__('Name') ?> <span class="required">*</span></label><br />
<input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserName()) ?>" class="required-entry input-text" type="text"/>
</div>
We are going to add another field above this one for the subject of the email. Copy and paste this code above the block of code (name field) referenced above.
<div class="input-box">
<label for="subject"><?php echo Mage::helper('contacts')->__('Subject') ?> <span class="required">*</span></label><br />
<input name="subject" id="subject" title="<?php echo Mage::helper('contacts')->__('Subject') ?>" value="" class="required-entry input-text" type="text"/>
</div>
As far as Magento is concerned, it doesn't care what fields we add to this form. It is written in such a way that it accepts all of the field posted for processing and send that out to the transactional e-mail form that you create. Now, go to System->Transactional E-mails in the Magento Admin section. Click "Add New Template" and from the "Template" dropdown box select "Contact Form" then "Load Template". Under template content you will see:
Name: {{var data.name}}
E-mail: {{var data.email}}
Telephone: {{var data.telephone}}
Comment: {{var data.comment}}
Add your new field before Name: {{var data.name}} so that now it should looks like this:
Subject: {{var data.subject}}
Name: {{var data.name}}
E-mail: {{var data.email}}
Telephone: {{var data.telephone}}
Comment: {{var data.comment}}
Enter a new name under "Template Name" to save your new Template and click on "Save Template". Now we need to tell Magento to use this new template for the Contact form. Go to System->Configuration and select "Contacts". Under "Email Options", select your new template under the "Email Template" dropdown box. Click on "Save Config".
That's it! 
What if I want a new field to...
What if I want a new field to be required? Any way to add validation?
Nexus Rex, Sure, just add...
Nexus Rex,
Sure, just add this class to the field: class=”required-entry input-text”
Quite inspiring, Keep up the...
Quite inspiring,
Keep up the good work,
Thanks for writing, most people don't bother.
Thanks!...
Thanks!
Can this be applied to a...
Can this be applied to a duplicated form.phtml (ex: formb.phtml)?
HDV, it depends how you have...
HDV, it depends how you have that additional form setup but by default no.
hi, I can not save the value...
hi,
I can not save the value in the database .
Though I added the field in the eav_attribute table .
And also added in config.xml file
the line
11
under
according to the tutorial :: http://www.magentocommerce.com/wiki/custom_account/registration_fields
Please help
Thanks in advance
Sudeshna Kundu
Hi, and thank you for an easy...
Hi, and thank you for an easy to understand tutorial!
Is it possible to actually get that subject field as the subject in the email sent?
Johan, Yes! If you follow the...
Johan, Yes! If you follow the instructions, it will accomplish just that
Thank you for this nugget of...
Thank you for this nugget of delicious code. Do I understand correctly that the "input-text" class triggers text validation and the "required-entry" class tests for null entries? If so, its just another reason why Magento gets me excited.
Mike, your correct!...
Mike, your correct!
Ok, I see what you're saying....
Ok, I see what you're saying. I think I'm gonna have to look into this more...
my contact form is not...
my contact form is not sending me comments in mail
how can i resolve this
Vaseem, You may have modified...
Vaseem, You may have modified the original template. I advise looking at the default theme’s template to see what you may have changed.
BIG BIG Big Thank you for...
BIG BIG Big Thank you for that!
Sweeper,...
Sweeper,
Thanks...
Thanks
Hi Richard, Keep up the good...
Hi Richard,
Keep up the good work,Can you please suggest me some good sites to learn magento
sriraman, You can start by...
sriraman,
You can start by going here:
http://www.magentocommerce.com/download and click on the “How to get started” tab
Zend Framework Tutorials because Magento is built on this Framework.
How does Magento code work?
Have fun!
how about if we want to hide...
how about if we want to hide a field as per requirement for one case and show for some other???
like telephone number
Telephone: {{var data.telephone}}
do we need to check it by {{depend data.telephone}} condition....{{/depend}}
i tried it but for both mails its showing up... help
Spectacular! Absolutely...
Spectacular! Absolutely awesome work - this plugin has been extremely helpful to me and I'm so happy to see the improvements. Keep up the good work!
I would like to thank you for...
I would like to thank you for the efforts you have made in composing this article. thanks for sharing the great information.
Thank you for the information...
Thank you for the information you have posted. I enjoyed reading your instructions. Very Impressive!
Hi, Have a lot of spam...
Hi,
Have a lot of spam through my contactform at website..
Can i add a field, where user need to make a word verification (ex. from a image), or how can i fix??
B/rgs
Mads
You can use a captcha...
You can use a captcha extension! This will prevent you from spam. Just Google around and you will find out.
Hi, I have a question, how...
Hi, I have a question, how can I add select field to the contact form. Actually the select field shows up correctly, but the entered value doesn't go over. Any idea? 23
That was a huge help, thank...
That was a huge help, thank you so much.
Now I just need to find out where the posts go in the backend
Post new comment