Magento Forum

Page 3 of 3
Contact form on a CMS page
 
Dezzign777
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2012-06-03
Australia
 

I’ve read through the whole thread and can get the contact form working but not with the original successful submit message on the custom CMS page that I created.

This is a Video Tutorial work-around that works pretty well and allows you to have your own success page whilst still letting you call up the form on any standard cms page. Contact Form On Magento CMS Page

 
Magento Community Magento Community
Magento Community
Magento Community
 
sungod000
Jr. Member
 
Total Posts:  17
Joined:  2011-11-14
 
1Maximo - 16 February 2011 01:14 PM

Simple answer !!!!

After days to pulling mi hair out, I find out the contact page URL Key need to be call just contacts
don’t changed

go to CMS / PAGES / contact us / URL Key= contacts


Cheers

Geeze, this works! Thank you!

Edit:  It worked, but I lost my CMS content when I did this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
v_shall1987
Jr. Member
 
Total Posts:  17
Joined:  2012-04-05
 

i have included form using action form_action=’/contacts/index/post’ in static block but when i submit button it redirect to contact form with blank page also mail not sending.
While my magneto\\\\\\\’s default form is working fine.

Any solution?

 
Magento Community Magento Community
Magento Community
Magento Community
 
accountname
Jr. Member
 
Total Posts:  2
Joined:  2012-12-20
 

Least intrusive solution to use the contacts form on a CMS page seems to be subclassing the Contacts controller. This just redirects to the calling page:

require_once 'Mage/Contacts/controllers/IndexController.php';

class 
Namespace_Module_IndexController extends Mage_Contacts_IndexController
{
    
protected function _redirect($path$arguments = array())
    
{
        $this
->_redirectReferer();
    
}
}

This avoid hard-coded references to URLs, changes very little code, and preserves your error/success message (although they may appear twice, once at the top of the page and once at the top of the form; edit form.phtml to remove it if you don’t use the stand-alone form, otherwise you need to find some other way to deal with this).

Drawback is that you need to set up a module first, which takes a bit of XML wrangling (see the wiki).

 
Magento Community Magento Community
Magento Community
Magento Community
 
fr0x
Member
 
Total Posts:  59
Joined:  2009-05-20
 

The above post is definitely the way to go if you want the redirect for form submission to redirect back to the original page the form was submitted on (thanks btw, it helped alot).

I also found a little more indepth explanation here:
http://stackoverflow.com/questions/10404558/magento-1-6-2-problems-overriding-contacts-controller

I can explain what I did to help out others a bit.

Here are the added / edited files:

/app/code/local/MyModules/Contacts/controllers/IndexController.php
/app/code/local/MyModules/Contacts/etc/config.xml
/app/etc/modules/MyModules_All.xml

For IndexController.php

require_once 'Mage/Contacts/controllers/IndexController.php';

class 
MyModules_Contacts_IndexController extends Mage_Contacts_IndexController
{
    
protected function _redirect($path$arguments = array())
    
{
        $this
->_redirectReferer();
    
}
}

For config.xml

<config>
  <
modules>
    <
MyModules_Contacts>
      <
version>0.1.0</version>
    </
MyModules_Contacts>
  </
modules>
  <
frontend>
    <
routers>
     <
contacts>
       <
args>
         <
modules>
           <
MyModules_Contacts before="Mage_Contacts">MyModules_Contacts</MyModules_Contacts>
         </
modules>
       </
args>
     </
contacts>
    </
routers>
  </
frontend>
</
config>

For MyModules_All.xml (or whatever file you have that stores the list of your active modules, you could also create a seperate one per module)

<?xml version="1.0" encoding="utf-8"?>
<config>
  <
modules>
    <
MyModules_Contacts>
      <
active>true</active>
      <
codePool>local</codePool>
    </
MyModules_Contacts>
  </
modules>
</
config>

That is it.  Upload those and you are good to go.  Make sure to flush your cache after uploading those!

Now, you *may* lose the notification that it was successfully submitted.

I was already overriding the original form layout (app/design/frontend/base/default/template/contacts/form.phtml) so I just needed to change:

<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>

to

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

 
Magento Community Magento Community
Magento Community
Magento Community
 
babyskill
Jr. Member
 
Total Posts:  17
Joined:  2009-05-30
 

its work! Thankyou for all!

 
Magento Community Magento Community
Magento Community
Magento Community
 
conor100
Jr. Member
 
Total Posts:  1
Joined:  2013-02-13
 

Please be very careful changing the core php files, it means that you will break your installation when you upgrade.  always take a copy of the file and place it in the /app/code/local folder with the same subfolder path.

Hi,

Post #7 says the above, can someone please tell me where to copy the “IndexController.php.” file too. I have tried copying it to /app/code/local but none of the changes I make to the file at this location work, leading me to believe that the file is not being read at this location.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Netzlichter
Jr. Member
 
Total Posts:  2
Joined:  2013-08-29
 

Hi!
I have a contact form on product pages.

1. I added this code in a stativ block on the product page:
{{block type="core/template" name="contactForm" template="contacts/form_produkt.phtml" form_action="/contacts/index/post"}}

2. I copied the code from “form.phtml” into “form_produkt.phtml”.

3. The form works, but the costumer is redirected to “/contacts/index/”.

4. How is it possible to redirect the customer to the same product page and display the success message instead of redirected to “/contacts/index/”?

I don’t want to edit the core files… I use Magento 1.8

I tried several code from the internet, but nothing works.
Hope someone can help,
Best

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jase007
Guru
 
Total Posts:  388
Joined:  2013-11-05
 

Hi,

Magento has a built-in contact form that does the job, but isn’t easy to edit. You may for example want to add your company address, contact details or even a Google Map. This can quite easily be done by creating a CMS page and including the contact form portion of the standard Magento contact form as a static block.

To achieve this, do the following:

1. Create your CMS page (Admin > Manage Pages)

2. Paste the following HTML where you would like the contact form to be positioned in your CMS page:

{{block type="core/template" name="contactForm" 

form_action="/contacts/index/post" template="contacts/form.phtml"}}

Hope this will help you!

Thanks

iLoveMage

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 3 of 3