redirect to a particular page after contact form is submitted in Magento

I know its answered, just sharing my experience. I had made a contact form through a CMS page. The form worked fine. But after submitting it, it would redirect to the magento contact form. To redirect it back to CMS page, i had to put

$this->_redirect('contactus');

where contactus is the URL identifier.

Also after redirect, the success / error message would not show up. For that i had to make changes here.

Go to /app/design/frontend/default/yourstore/template/contacts/form.phtml

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

with:

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

I got the solution from here


For the next person

  1. go to silk software and create a new module using their module creator http://www.silksoftware.com/magento-module-creator/
  2. Enter your company name and module name
  3. Then change "Need Rewrite Magento Class" to Yes
  4. click "Add Class" the class name will be Mage_Contacts_IndexController
  5. This will create a module with everything you need
  6. Add the postAction method from the Core Controller to your newly created controller
  7. Then change the redirect to redirectReferer() at the end of the postAction method

The module creator will create everything you need to overload the Contacts Controller and save you time from troubleshooting typos. Also, save yourself the trouble down the road of editing the core files directly.

DO NOT EDIT THE CORE FILES!


Could also just create custom url redirect.

  • id path - contacts/index
  • request path - contacts/index
  • target path - 'redirect url'

Tags:

Magento