Magento – Save Magento 1.9.2 contact form data in database

contact-usmagento-1.9PHP

I want to store Magento 1.9.2 contact form data into database?
I have create a New DB Table and create new Module on local Pool but Controller overwrite is not working.

I want to send email as well store all the data in my custom table.

My Code Is:

/app/etc/modules/Codefire_Contacts.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Codefire_Contacts>
            <active>true</active>
            <codePool>local</codePool>
        </Codefire_Contacts>
    </modules>
</config>

/app/code/local/Codefire/Contacts/controllers/indexController.php

<?php

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

class Codefire_Contacts_IndexController extends Mage_Contacts_IndexController {

    //your targeted controller action rewrite here
    public function indexAction() {
        parent::indexAction();
        echo 'Good';
        die;
    }

    public function postAction() {
        echo 'Good';
        die;
    }

}

/app/code/local/Codefire/Contacts/etc

<?xml version="1.0"?>
<config>
    <modules>
        <Codefire_Contacts>
            <version>0.1.0</version>
        </Codefire_Contacts>
    </modules>
    <frontend>
        <routers>
            <contacts>
                <args>
                    <modules>
                        <Codefire_Contacts before="Mage_Contacts">Codefire_Contacts</Codefire_Contacts>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
</config>

Its not working…

Best Answer

Please add the following code in the config.xml file.

 <global>
    <rewrite>
        <customcontactus>
            <from><![CDATA[#^/contacts/index/#]]></from>
            <to>/contactform/index/</to>
        </customcontactus>
    </rewrite>
</global>

Rewrite the postAction() controller file and add the following code.

$model = Mage::getModel("contactform/contactformsave");
            $model->setData(array('created_at'=>NOW(),'name'=>$post['name'],
                'email'=>$post['email'],'telephone'=>$post['telephone'],
                'comment'=>$post['comment']));
            $model->save();

            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('*/*/');

Please refer my tutorial for full code and file structure.

http://www.pearlbells.co.uk/save-contact-form-data-magento-database/