Richard Castera

Application Developer/Designer
  • Home
  • About
  • Projects

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! ;)

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Don't forget to Subscribe and Follow!

Be sure to subscribe to the feed and follow me on Twitter for more insights and resources!

22 Responses to “Magento – Add additional fields to the Contact Form”

  1. Comment #1 - Permalink
    Nexus Rex
    11/03/2009

    What if I want a new field to be required? Any way to add validation?

  2. Comment #2 - Permalink
    custom software
    11/26/2009

    Quite inspiring,

    Keep up the good work,

    Thanks for writing, most people don’t bother.

  3. Comment #3 - Permalink
    Richard
    12/06/2009

    @William, Thanks!

  4. Comment #4 - Permalink
    Richard
    12/12/2009

    @Nexus Rex,

    Sure, just add this class to the field: class=”required-entry input-text”

  5. Comment #5 - Permalink
    HDV
    12/15/2009

    Can this be applied to a duplicated form.phtml (ex: formb.phtml)?

  6. Comment #6 - Permalink
    Sudeshna Kundu
    12/22/2009

    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

  7. Comment #7 - Permalink
    Johan Strand
    01/13/2010

    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?

  8. Comment #8 - Permalink
    Mike
    01/14/2010

    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.

  9. Comment #9 - Permalink
    ugg boots
    01/27/2010

    Ok, I see what you’re saying. I think I’m gonna have to look into this more…

  10. Comment #10 - Permalink
    vaseem ansari
    01/29/2010

    my contact form is not sending me comments in mail
    how can i resolve this

  11. Comment #11 - Permalink
    Sweeper
    01/29/2010

    BIG BIG Big Thank you for that!

  12. Comment #12 - Permalink
    vil
    02/12/2010

    Thanks

  13. Comment #13 - Permalink
    Richard
    02/16/2010

    @HDV, it depends how you have that additional form setup but by default no.

  14. Comment #14 - Permalink
    Richard
    02/16/2010

    @Johan, Yes! If you follow the instructions, it will accomplish just that :)

  15. Comment #15 - Permalink
    Richard
    02/16/2010

    @Mike, your correct!

  16. Comment #16 - Permalink
    Richard
    02/16/2010

    @Sweeper, ;)

  17. Comment #17 - Permalink
    Richard
    02/16/2010

    @Vaseem, You may have modified the original template. I advise looking at the default theme’s template to see what you may have changed.

  18. Comment #18 - Permalink
    sriraman
    05/12/2010

    Hi Richard,
    Keep up the good work,Can you please suggest me some good sites to learn magento

  19. Comment #19 - Permalink
    Richard
    06/08/2010

    @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!

  20. Comment #20 - Permalink
    preeti
    07/12/2010

    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 :)

  21. Comment #21 - Permalink
    macaroon
    08/06/2010

    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!

  22. Comment #22 - Permalink
    Medieval Swords
    08/23/2010

    I would like to thank you for the efforts you have made in composing this article. thanks for sharing the great information.

It's Your turn

Click here to cancel reply.
You

CAPTCHA Image
CAPTCHA Audio
Refresh Image



About The Author

Richard is a Web Developer currently working for SankyNet. He is available for freelance work. Visit Shifting Ideas for inquiries. Thanks!
  • Premium Email Templates

    Social Profiles

  • Twitter
  • Facebook
  • LinkedIn
  • Digg
  • Google
  • GitHub

    Last Tweet

  • Beware the heat-seeking Nerf machine-gun coming to a cubicle near you http://om.ly/svHF #fb
  • Follow me
  • Archives

    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • September 2008
    • August 2008
    • July 2008
    • June 2008
  • Categories

    • AJAX
    • Apache
    • Books
    • Drupal
    • Ecommerce
    • Flash
    • Google
    • Javascript
    • jQuery
    • Magento
    • Marketing
    • Mootools
    • My Thoughts
    • MySQL
    • News
    • Photoshop
    • PHP
    • Prototype
    • SEO
    • Web Resources
    • Wordpress
  • My Favorites

    • 37 Signals
    • Andrew Warner
    • Chris Coyier
    • Chris Shiflett
    • Collis Ta'eed
    • Development Seed
    • Drupal
    • HubSpot
    • James Padolsey
    • Joel On Software
    • John Resig
    • jQuery
    • Kevin Rose
    • Life Hacker
    • Magento
    • Mashable
    • Matt Cutts
    • Matt Ryan
    • MySQL
    • NetTuts
    • Noupe
    • Photoshop Tutorials
    • PHP
    • Smashing Magazine
    • Tech Crunch
    • WoorkUp
    • Wordpress

2010 © Copyright. Richard Castera - All Rights Reserved.

Top