3

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...

3 Answers 3

2

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/

2

Make change in following file

/app/etc/modules/Codefire_Contacts.xml

<config>
    <modules>
        <Codefire_Contacts>
            <active>true</active>
            <codePool>local</codePool> <!--If your extension is in community codePool then use community-->
        </Codefire_Contacts>
    </modules>
</config>

Change your controller file name from indexController.php to IndexController.php. i should be in upppercase.

3
  • Its my mistake during copy paste the code.. but its not working
    – rajeevG
    Feb 4, 2016 at 7:46
  • Disable your cache and compilation from admin Feb 4, 2016 at 7:48
  • Thanks i have already do this.. But its OS issue.. working fine.. Thanks yr time
    – rajeevG
    Feb 4, 2016 at 8:02
1

If create a module then you must need define it codePool at module config file and without it cannot be possible to run the extension.There are 3 type of codePool local,community,core. Codefire_Contacts.xml

You did not define it.So as per as,Rohit Kundale said ,you should be define codePool.

Basic format of module config file

<?xml version="1.0" ?>
<config>
    <modules>
        <ModuleNameSpace_ModuleName>
            <active>true</active>
            <codePool>local</codePool> <!-- it value may be local,core,community -->
        </ModuleNameSpace_ModuleName
    </modules>
</config>
4
  • Its my mistake during copy paste the code.. but its not working
    – rajeevG
    Feb 4, 2016 at 7:48
  • change require_once(Mage::getModuleDir('controllers', 'Mage_Contacts') . DS . 'IndexController.php'); to require_once Mage::getModuleDir('controllers', 'Mage_Contacts') . DS . 'IndexController.php';
    – Amit Bera
    Feb 4, 2016 at 7:53
  • No! But its OS issue.. working fine.. Thanks yr time
    – rajeevG
    Feb 4, 2016 at 8:02
  • make indexController.php to IndexController.php.*i*should be uppercas
    – Amit Bera
    Feb 4, 2016 at 8:04

Your Answer

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

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