Contact Form in Magento

login-form

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"}}
    <!– END OF CONTACT FORM –>

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.

Interested in hiring us?

Have a chat with us. You would be surprised how small changes can make your business even more successful.


About Domagoj Potkoc

Backend Developer

Domagoj is Magento Certified Developer who enjoys playing tennis after long hours in front of computer screen.

Read more posts by Domagoj / Visit Domagoj's profile

96 comments

  1. 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.

    Regards.

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

  3. 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.

  4. Just a quick thanks for this & all the other articles that you have done for the Magento community.
    Best wishes,
    Eddie

  5. 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”}}

  6. 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%.

  7. 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…

  8. 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?

  9. 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>http://www.mysite.com/contacts/</url></action>

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

    <default>
            <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>
            </reference>
        </default>
  10. 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..

    Gratz.

  11. 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. http://www.MyStore.com/store1/) the form just redirects back to the main store. Any help would be greatly appreciated.

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

    Can you help?

  13. Please, edit previous comment:

    reference name=”content”

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

    reference

  14. @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.

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

  16. Thanks.

    I used like this in my CMS PAGE content and it works fine.

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

  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,

    Thilo

  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 data.mobile}}
    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(); ?> 
    </div>

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> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.