1

In Magento 1.9, after a visitor submits the contact form they get sent back to the contact form page.

How can I send them to a CMS page instead?

(I did try googling this, but the only results I got were for putting the contact form inside a CMS page.)

2 Answers 2

1

To implement such feature, you'll have to create a module that overrides the following file: app/code/core/Mage/Contacts/controllers/IndexController.php.

The change you need to apply on this file is the following, replace that piece of code under the postAction method:

Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
$this->_redirect('*/*/');

With the following:

Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
$this->_redirect('your_cms_page_identifier');

Please note that you should only apply this to the _redirect that's right after the addSuccess line. Do not apply it in the catch block nor in the else at the end of the function as it would result in people getting redirected to your CMS page even if the request submission fails.

1

Override the default IndexController of Mage_Contacts by adding the below in your config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
         <Namespace_Module>
            <version>0.0.1</version>
        </Namespace_Module>
    </modules>
    <frontend>
        <routers>
            <contacts>
                <args>
                    <modules>
                        <Namespace_Module_Contacts before="Mage_Contacts">Namespace_Module_Contacts</Namespace_Module_Contacts>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
</config>

and adding the controller in Namespace/Module/controllers/Contacts/IndexController.php and override the postAction() function

require_once Mage::getModuleDir('controllers', 'Mage_Contacts') . DS . 'IndexController.php';

class Namespace_Module_Contacts_IndexController extends Mage_Contacts_IndexController {
    public function postAction()
    {
        $post = $this->getRequest()->getPost();
        if ( $post ) {
            $translate = Mage::getSingleton('core/translate');
            /* @var $translate Mage_Core_Model_Translate */
            $translate->setTranslateInline(false);
            try {
                $postObject = new Varien_Object();
                $postObject->setData($post);

                $error = false;

                if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
                    $error = true;
                }

                if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
                    $error = true;
                }

                if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                    $error = true;
                }

                if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
                    $error = true;
                }

                if ($error) {
                    throw new Exception();
                }
                $mailTemplate = Mage::getModel('core/email_template');
                /* @var $mailTemplate Mage_Core_Model_Email_Template */
                $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                    ->setReplyTo($post['email'])
                    ->sendTransactional(
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                        null,
                        array('data' => $postObject)
                    );

                if (!$mailTemplate->getSentSuccess()) {
                    throw new Exception();
                }

                $translate->setTranslateInline(true);

                Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
                $this->_redirect('cms_page_identifier'); // it redirects to your cms page instead of the default contact form

                return;
            } catch (Exception $e) {
                $translate->setTranslateInline(true);

                Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
                $this->_redirect('*/*/');
                return;
            }

        } else {
            $this->_redirect('*/*/');
        }
    }
}
1
  • This worked for me.!! Accept the answer, if it worked for you as well.. Commented Feb 17, 2016 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.