I am trying to run a SQL INSERT query from the Mage_contacts_indexcontroller that I have extended to my own module but the query never runs. I have tried creating a separate function and running the function within the postAction but no luck. The function runs in other modules just not the contacts module. I was also thinking that creating an observer for this might be the way to go but I don't think the contacts form fires an event that Magento tracks. Any help or ideas is appreciated.

edited my post to add my code:

class Mage_Contacts_IndexController extends Mage_Core_Controller_Front_Action

    const XML_PATH_EMAIL_RECIPIENT  = 'contacts/email/recipient_email';
    const XML_PATH_EMAIL_SENDER     = 'contacts/email/sender_email_identity';
    const XML_PATH_EMAIL_TEMPLATE   = 'contacts/email/email_template';
    const XML_PATH_ENABLED          = 'contacts/contacts/enabled';

    public function preDispatch()

        if( !Mage::getStoreConfigFlag(self::XML_PATH_ENABLED) ) {


    public function indexAction()

            ->setFormAction( Mage::getUrl('*/*/post') );


    public function insert(){
        $post = $this->getRequest()->getPost();

        $resource   = Mage::getSingleton('core/resource');
        $write      = Mage::getSingleton('core/resource')->getConnection('core_write');

        $table      = $resource->getTableName('contact_forms');
        $subject    = $post['subject'];
        $name       = $post['name'];
        $email      = $post['email'];
        $telephone  = $post['telephone'];
        $comments   = $post['comments'];

        $query      =  "Insert Into {$table} (subject,name,email,telephone,comment,modified_at) values (:subject,:name,:email,:telephone,:comments, NOW())";

        $binds      =  array(
            'subject'   => $subject,
            'name'      => $name,
            'email'     => $email,
            'telephone' => $telephone,
            'comments'  => $comments


    public function postAction()
        $post = $this->getRequest()->getPost();


        if ( $post ) {
            $translate = Mage::getSingleton('core/translate');
            /* @var $translate Mage_Core_Model_Translate */
            try {
                $postObject = new Varien_Object();

                $error = false;
                $error2 = '';

                if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
                    $error = true;
                    $error2 = 'Please add a contact name for this inquiry.';

                if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                    $error = true;
                    $error2 = 'Please add a valid email address and resubmit the contact form.';

                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'))
                        array('data' => $postObject)

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


                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.'));

            } catch (Exception $e) {


                Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__( $error2 ));

        } else {

  • please share your code.what you have tried Jul 9, 2014 at 17:48

1 Answer 1


It looks as if you're incorrectly defining the controller rewrite. Merely creating the controller in your own local module will not create the rewrite. To define the rewrite you must:

  • Create your own module
  • Create a controller rewrite
  • Author the rewrite so that it extends the class you're targeting to rewrite. This class must be a class within your own module's namespace.

Some example code:

1. Add this to your module's config.xml:

File: app/code/local/YourCompany/Contacts/etc/config.xml

                        <yourcompany_contacts before="Mage_Contacts">YourCompany_Contacts</yourcompany_contacts>

2. Create your own rewritten controller:

File: app/code/local/YourCompany/Contacts/controllers/IndexController.php

class YourCompany_Contacts_IndexController extends Mage_Contacts_IndexController
    //your targeted controller action rewrite here
  • Yeah I didn't realize I had not extended it properly. Thanks for pointing that out. Yeah I dropped my function into the core file to test it and sure enough it worked. Thanks for the help.
    – Egregory
    Jul 10, 2014 at 14:29

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