Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7878681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:43:36+00:00 2026-06-03T03:43:36+00:00

Ok so I’ve setup a new module to override the Contacts controller so that

  • 0

Ok so I’ve setup a new module to override the Contacts controller so that I can add a newsletter sign up option to it. My setup is as follows:

/app/code/local/MyNamespace/ContactsPlus/controllers/Contacts/IndexController.php:

<?php
# Controllers are not autoloaded so we will have to do it manually:
require_once 'Mage/Contacts/controllers/IndexController.php';
class MyNameSpace_ContactsPlus_Contacts_IndexController extends Mage_Contacts_IndexController
{
    # Overloaded indexAction
    public function indexAction() {
        # Just to make sure
        error_log('Yes, I did it!');
        parent::indexAction();
    }
}

/app/code/local/MyNamespace/ContactsPlus/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <mynamespace_ContactsPlus>
            <version>0.1.0</version>
        </mynamespace_ContactsPlus>
    </modules>
    <global>
        <rewrite>
            <mynamespace_contactsplus_contacts_index>
                <from><![CDATA[#^/contacts/index/#]]></from>
                <to>/contactsplus/contacts_index/</to>
            </mynamespace_contactsplus_contacts_index>
            <mynamespace_contactsplus_contacts_index>
                <from><![CDATA[#^/contacts/#]]></from>
                <to>/contactsplus/contacts_index/</to>
            </mynamespace_contactsplus_contacts_index>            
        </rewrite>
    </global>
    <frontend>
        <routers>
            <mynamespace_contactsplus>
                <use>standard</use>
                <args>
                    <module>mynamespace_ContactsPlus</module>
                    <frontName>contactsplus</frontName>
                </args>
            </mynamespace_contactsplus>
        </routers>
    </frontend>    
</config>

/app/etc/modules/MyNamespace_All.xml:

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

THe module appears in the admin modules list and it has produced the following error on my /contacts/ page:

Fatal error: Call to a member function setFormAction() on a non-object in /srv/www/foo.com/app/code/core/Mage/Contacts/controllers/IndexController.php on line 54 

That’s this line:

        $this->getLayout()->getBlock('contactForm')->setFormAction( Mage::getUrl('*/*/post') );

I’m not sure where to go from here though, a guess is that it can’t set the form action on whatever is being returned from Mage::getUrl(‘//post’) but I’m clutching at straws tbh.

Any help of advice would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:43:38+00:00Added an answer on June 3, 2026 at 3:43 am

    Ok after much research, help and general frustration here is how I got it working:

    First up, my module directory is set out as follows (note the caps on the directories):

    /app/code/local/MyNamespace/ContactsPlus/etc/

    • config.xml

    /app/code/local/MyNamespace/ContactsPlus/controllers/

    • IndexController.php

    /app/code/local/MyNamespace/ContactsPlus/Helper/

    • Data.php

    Now for the config files:

    /app/code/local/MyNamespace/ContactsPlus/etc/config.xml:

    <?xml version="1.0"?>
    <config>
        <modules>
            <MyNameSpace_ContactsPlus>
                <version>0.1.0</version>
            </MyNameSpace_ContactsPlus>
        </modules>
        <frontend>
            <routers>
    
            <!-- Creates route to my module via /contactsplus/ - I used this for testing -->
                <contactsplus>
                    <use>standard</use>
                    <args>
                        <module>MyNameSpace_ContactsPlus</module>
                        <frontName>contactsplus</frontName>
                    </args>
                </contactsplus>
    
            <!-- Sets Mage_Contacts route to MyNameSpace_ContactsPlus -->              
                <contacts>
                    <args>
                        <modules>
                            <MyNameSpace_ContactsPlus before="Mage_Contacts">MyNameSpace_ContactsPlus</MyNameSpace_ContactsPlus>
                        </modules>
                    </args>
                </contacts> 
            </routers>
        <!-- Sets layout config file (essential for this to work) -->   
            <layout>
                <updates>
                    <contactsplus>
                        <file>contactsplus.xml</file>
                    </contactsplus>
                </updates>
            </layout>        
        </frontend>
        <global>
        <!-- Sets a helper class for the module, when overriding contacts this is also essential. -->   
            <helpers>
                <contactsplus>
                    <class>MyNameSpace_ContactsPlus_Helper</class>
                </contactsplus>
            </helpers>        
        </global>
    </config>
    

    /app/code/local/MyNamespace/ContactsPlus/controllers/Contacts/IndexController.php:

    <?php
    # Controllers are not autoloaded so we will have to do it manually:
    require_once 'Mage/Contacts/controllers/IndexController.php';
    class MyNameSpace_ContactsPlus_IndexController extends Mage_Contacts_IndexController
    {
        # Overloaded indexAction
        public function indexAction() {
            # Just to make sure
            //die('Yes, I did it!');
            parent::indexAction();
        }
    }
    

    /app/code/local/MyNamespace/ContactsPlus/Helper/Data.php:

    <?php
    class MyNameSpace_ContactsPlus_Helper_Data extends Mage_Core_Helper_Abstract
    {
    
    }
    

    /app/etc/modules/MyNamespace_ContactsPlus.xml:

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

    /app/design/frontend/mythemepackage/mytheme/layout/contacts.xml:

    <?xml version="1.0"?>
    <layout version="0.1.0">
        <default>
            <reference name="footer_links">
                <!-- <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
             --></reference>
        </default>
        <contacts_index_index translate="label">
        <!-- had to comment this out in order to prevent a duplicate form issue, if anyone has a better method for this then I'd love to here it :) 
            <label>Contact Us Form</label>
            <reference name="head">
                <action method="setTitle" translate="title" module="contacts"><title>Contact Us</title></action>
            </reference>
            <reference name="root">
                <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
                <action method="setHeaderTitle" translate="title" module="contacts"><title>Contact Us</title></action>
            </reference>
            <reference name="content">
                <block type="core/template" name="contactForm" template="contacts/form.phtml"/>
            </reference>
        -->
        </contacts_index_index>
    
        <!-- added this to rewrite contacts handle to the new modules handle -->
        <contacts_index_index>
            <update handle="contactsplus_index_index"/>
        </contacts_index_index>
    </layout>
    

    /app/design/frontend/mythemepackage/mytheme/layout/contactsplus.xml:

    <?xml version="1.0"?>
    <layout version="0.1.0">
        <default>
            <reference name="footer_links">
                <!-- <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
             --></reference>
        </default>
        <contactsplus_index_index translate="label">
            <label>Contact Us Form</label>
            <reference name="head">
                <action method="setTitle" translate="title" module="contactsplus"><title>Contact Us</title></action>
            </reference>
            <reference name="root">
                <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
                <action method="setHeaderTitle" translate="title" module="contactsplus"><title>Contact Us</title></action>
            </reference>
            <reference name="content">
                <block type="core/template" name="contactForm" template="contactsplus/custom_form.phtml"/>
            </reference>
        </contactsplus_index_index>
    
    </layout>
    

    I also made a copy of /app/design/frontend/mythemepackage/mytheme/template/contacts/form.phtml and placed it in /app/design/frontend/mythemepackage/mytheme/template/contactsplus/ and then modified it to suit my requirements.

    Resources I found particularly useful during this process were google, IRC #magento and

    http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table

    http://alanstorm.com

    Hope this helps someone else at some point.

    Now it’s onto adding a newsletter sign up option to my new form!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.