Contact Form in Magento

Contact Form in Magento

As you know, Magento has a built-in contact form that can be used for general contacts. That form isn’t part of any CMS page, you cannot edit some introduction text, you cannot add phone numbers administration, and you cannot see the breadcrumbs. If you wish to edit text in that default contact form, you will need to update front-end files. Luckily, there is an alternative.

Note:You might notice that this is one of our oldest posts. Upon writing we made one error in the code that was never corrected. Now, this post article is updated and we have fully working instructions. Hope this will help.

If you are a developer, editing your contact form HTML is an easy task. You only need to open file:
app/design/frontend/default/[yourtheme]/template/contacts/form.phtml and you will find your way around.

Once there, you will basically edit the layout of this interface.

However, there are cases when you would like to give your client an option to edit some intro text, edit his phone numbers, edit text behind the form, etc. You are probably guessing that it would be nice to be able to embed contact form in some CMS page. No problem.

  • Go to your CMS> Manage Pages interface
  • Once there, input your HTML as you normally would on any other page
  • Once you are happy with HTML part, add this lines:
    <!– CONTACT FORM –>
    {{block type=”core/template” name=”contactForm” form_action=”/contacts/index/post” template=”contacts/form.phtml”}}

Important note: When you copy/paste the code, it is important to know that WordPress saves the quotes in some weird way, so you should replate the pasted quotes and reenter them.

You will notice that we added xml attribute form_action=”/contacts/index/post”. With it we set form action, and your contact form will work properly. Here is how it looks like. Notice the breadcrumbs.

Contact Form

I know that this is not some breakthrough article, but I will certanly create contact CMS page on all of my future Magento projects.

Hope this was helpful. In case you need some help regarding Magento Development, we would be happy to help. Our team of experts would love to review your code and offer insights on improving your store. Our Magento Technical Audit is a great way to start – feel free to contact us!

You made it all the way down here so you must have enjoyed this post! You may also like:

Out of the box Form Validation in Magento Petar Sambolek
Petar Sambolek, | 24

Out of the box Form Validation in Magento

Magento form field AJAX validation Branko Ajzele
Branko Ajzele, | 8

Magento form field AJAX validation

Problems with Contact form Vanja Devcic
, | 17

Problems with Contact form


  1. For those who find the error /contacts/index/post could not be found, this is because the rendered form html requires an absolute url – if you compare the form action attribute on your CMS page agains the actual contacts page, you will see your CMS action has been rendered as a relative path.

    It’s not ideal, but simply edit this:

    {{block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"}}

    to this:

    {{block type="core/template" name="contactForm" form_action="YOUR_FULL_BASE_URL_HERE/contacts/index/post" template="contacts/form.phtml"}}

    Dirty hack – yes.

  2. {{block type=”core/template” name=”contactForm” form_action=”{{store direct_url=”contacts”}}/index/post” template=”contacts/form.phtml”}}

  3. I’ve problem with Contact Us page template still showing old theme. But I want to replace new theme which is enabled in my other pages. except: Register, Login, About Us, Contact Us, My wishlist & My cart page.

    Please advice me how can i do visible home page temple to given link pages.

    Thanks in advance.


  4. I was unable to getting email BUT after following your steps :-It worked for me.
    Thank You.

  5. I’ve got it working after google it a bit.

    My problem was related to the extension Mandrill which changes contact form functionality.

    I used:
    {{block type=’core/template’ name=’contactForm’ form_action=’/contacts/index/post’ template=’contacts/form.phtml’}}

    In my CMS Page to show the form and fix the contact form with the information of this post.

    Thanks Inchoo team for such a great contribution to the community given in this blog.

  6. I am tried with this way and worked in local but while uploading to live – it is giving me error as Web-form is not active.

    I put as
    {{block type=”webforms/webforms” name=”webforms” template=”webforms/default.phtml”}}

  7. Thank you. I was trying to figure out why the form was nerver posting and your block for the contact us form actually was the only one that had the info.

    {{block type=”core/template” name=”contactForm” form_action=”/contacts/index/post” template=”contacts/form.phtml”}}

    This worked 100%.

  8. If you want to have the contact form with in a phtml page then…

    1- add the block to the xml you want for example I wanted to add a request form to the product view so, i went to catalog.xml at the and add:

    2- just add the getChildHtml:

    getChildHtml(‘contactForm’) ?>

    So simple i know but took me 3 coffes like all easy things in magento…

  9. Thanks for this article. It worked for me but after the form is submitted my navigation links have contacts/index inserted between the base URL and the URL Key, presumably because the URL Key is relative. Any idea how fix this?

  10. Thank you works a dream in 1.6.

    I tried to remove the original link from the footer in my local.xml

    <action method="removeLinkByUrl"><url></url></action>

    but this did not work so I have ended up copying the contacts.xml into my app/theme removing the following section.

            <reference name="footer_links">
                <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
  11. Bumping…

    Is there anyway to preserve controller in the CMS page? The block is instantiated right and works fina but after the submit from the contacts form it redirects back to home_url/contacts…

    I think what everyone realy needs is to stay(after submit) in the CMS page like home_url/my-cms-page..


  12. Hi I am trying to add that block type to my CMS and it works great for the main website. But does anyone know how to add it to a multi-store set up? if I add that block to my CMS page that is used by more than one of the other “sub”-stores (eg. the form just redirects back to the main store. Any help would be greatly appreciated.

  13. I’ve used this coding, but it does not give a success message stating that the form has been sent.

    Can you help?

  14. Please, edit previous comment:

    reference name=”content”

    block type=”core/template” name=”contactForm” template=”contacts/form.phtml” form_action=”/contacts/index/post”


  15. @Christopher have you tried with some custom code on your category page? you could do an if statement based on the category the client is and show some info or hide it. Don’t think it is the best way but it should work. When the client is on the t-shirt category show t-shirt message and when on the tobacco one show the tobacco message.
    Hope it helps.

  16. how do I edit the post php file. I need to make sure users can not post javascript etc through the form

  17. Dear inchoo team, I like your work, your blog and your tutorials. Keep up the good work! For me your blog is really important and your articles are everything else than ripped off. Some people might think that this is a free support chat, but don’t get confused by that 😉

    Thumbs up! Best from Berlin,


  18. Christopher,

    I’m really sorry, but our developers are extremely busy and didn’t find time to answer a question in the comments on a blog post written last year.

    I hope you understand that although we wrote over 500 tutorials / modules / extensions completely free for the community here, we do have obligation to finish work for our clients and feed our families. I hope you don’t mind.

    Kind regards,

    Marketing Manager, Inchoo

  19. I guess these guys dont respond to inquires or interact with their readers… been back everyday for a month looking for a response on my previous comment on this post any another by a different author yet nothing…. Either that or it is another pointless autoblog with ripped off articles… who knows. Sincerely disappointing though thats for sure.

    1. Dear Christopher,

      I can understand why you might get this impression, but let me try to shed some light for you to understand our environment. For 3 years, we are trying to share knowledge via this site and help community in learning. There are now over 100.000 people who visit this site on monthly basis. However, due this reason, some people feel like sharing knowledge is our obligation. Let me be blunt. It is not. We get cca 5-10 inquiries per day currently to provide free support. Theses inquiries are often sent after someone messed up something.

      Imagine our workday if we would jump from one side to another trying to help everyone. For free. You don’t need to be economy expert to figure out what would happen. Word would be spread and such free-support inquiries would explode. Inchoo couldn’t pay salaries for employees and they would leave. Quite soon, we would be out of business because nobody would stay.

      I am sad you find this blog pointless. It is your opinion and you are entitled to it. However, I can confirm that the articles are not ripped.

      Thank you!

  20. We have .htaccess rules, which adds a trailing slash at the end of the url. If you have that, you have to change the form action to /contacts/index/post/! Otherwise email won’t be sent.

  21. Just worked out forgot to add the var to email template

    Mobile: {{var}}
    Fax: {{var data.fax}}

    What I really need to do is create a completely New form , not connected to contact us form. I made a duplicate of form.phtml called request.phtml but don’t it is still associated to contact us email template , is it possible to associate away from contact us email template? And how?

  22. I am trying to add 2 extra input fields (Mobile & Fax) by editing form.phtml, they appear when viewing & submitting the form but not in the email?

    <label for="Mobile"><?php echo Mage::helper('contacts')->__('Mobile') ?></label>
    <div class="input-box">
    <input name="mobile" id="mobile" title="<?php echo Mage::helper('contacts')->__('Mobile') ?>" value="" class="input-text" type="text" />

    Have I missed something out?

  23. this is a bit off topic but in previous comments on this thread you mention some altering of the

    <div id="messages_product_view">

    I been looking all over for some help with this and even though its a bit off topic im hoping you can help me out. Heres a copy and paste of the comment i left on another article on this site but by a different author and the article was a bit old so i wasnt sure if i would hear back from him or if he is active on here still.
    I want to display a notice at the top of certain product pages with additional information regarding what they should select and why. For instance you have lets say a tshirt shop and five of the shirts comes in 4 different materials and you want to display a notice at the top of those 5 product pages that tells you the benefit of choosing one material over the other (this is just example mind you heh) and then you also sell something like hookah tobacco in the same shop which has different levels of nicotine and you want to describe how the different levels of nicotine compare to a regular cigarette or something in that notice box is there a way this can be acheived with your guide?

  24. After submitting the form I’m getting a 404. I think this might be related to the fact that I enabled this option: System – Configuration – General – Web – URL Options – Add storecode to URL’s. The storecode is not added after submitting this form. Do you have any solution for this?

  25. I got it working, here’s my code….

    <div id="messages_product_view">
    <?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?>
    <?php echo Mage::app()->getLayout()->getMessagesBlock()->getGroupedHtml(); ?> 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.