Magento add an postDispatch to a post action

1.3k views Asked by At

I have this controller :

class Mage_Contacts_IndexController extends Mage_Core_Controller_Front_Action
{

public function preDispatch()
{
    parent::preDispatch();

    if( !Mage::getStoreConfigFlag(self::XML_PATH_ENABLED) ) {
        $this->norouteAction();
    }
}

public function indexAction()
{
    $this->_initLayoutMessages('juron/ses');
    $this->renderLayout();
}

public function postAction()
{
    $post = $this->getRequest()->getPost();
    if ( $post ) {
        ......
    }
 }
}

In the /Mage/Contacts/etc/config.yml :

<events>
        <controller_action_postdispatch_contacts_post_action>
            <observers>
                <contacts>
                    <type>model</type>
                    <class>contacts/observer</class>
                    <method>postDispatch</method>
                <contacts>
            </observers>
        </controller_action_postdispatch_contacts_post_action>
    </events>

And in /Mage/Contacts/Model/Observer.php :

class Mage_Contacts_Model_Observer
{
    public function postDispatch(Varien_Event_Observer $observer)
    {
        echo 'Stop';
        die();
    }
}

Normally when I try to submit the contact form I shoul see Stop and the execution should be finished but not work like this. Seems the observer is not called. Can you help me please ? Thx in advance.

1

There are 1 answers

0
OddBrew On

The right event to listen to here would be controller_action_postdispatch_contacts_index_post. The structure is controller_action_postdispatch_ROUTER_CONTROLLERNAME_ACTIONNAME.

P.S. : acknowledge that you should write your module in the local pool and not in the core.