2

Let me preface this by the fact that I am 100% new to Magento.

I am trying to extend the contact us page to allow me to add some information to the page, like the form, in which it cannot be change via the CMS (specifically the address information to start). I have done a ton of google searches and looked at similar questions here (this seems to be the closest: Contact Us form is not displaying) but I am not figuring it out.

I have tried various methods of solving but I am currently trying to add a block. All I am trying to do at this point is get the "special" text to show on the page along with form. Realize that might be wrong, just looking for some direction on what I am missing.

Code:

etc/modules/TPW_Contacts.xml

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

app/code/local/TPW/Contacts/controllers/IndexController.php

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

class TPW_Contacts_IndexController extends Mage_Contacts_IndexController
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
}
?>

app/code/local/TPW/Contacts/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <TPW_Contacts>
            <version>0.1.0</version>
        </TPW_Contacts>
    </modules>
    <global>
        <blocks>
            <contacts>
                <class>TPW_Contacts_Block</class>
            </contacts>
        </blocks>
    </global>
    <frontend>
        <routers>
            <contacts>
                <args>
                    <modules>
                        <TPW_Contacts before="Mage_Contacts">TPW_Contacts</TPW_Contacts>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
</config>

app/design/frontend/enterprise/hellov/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">
        <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/1column.phtml</template></action>
            <action method="setHeaderTitle" translate="title" module="contacts"><title>Contact Us</title></action>
        </reference>
        <reference name="content">
            <block type="contacts/location" name="contacts.locationinfo" template="contacts/locationinfo.phtml"/>
        </reference>
        <reference name="content">
            <block type="core/template" name="contactForm" template="contacts/form.phtml"/>
        </reference>
    </contacts_index_index>
</layout>

app/code/local/TPW/Contacts/Block/Contacts.php

<?php
class TPW_Contacts_Block_Location extends Mage_Core_Block_Template
{
    public function getLocation()
    {
        return 'This is my address!';
    }
}
?>

app/design/frontend/enterprise/hellov/template/contacts/locationinfo.phtml

<p><?php echo $this->getLocation(); ?></p>

Your help is appreciated. Thank you!

  • do you get any error? – MTM Sep 4 '14 at 15:23
  • Check these files: var/log/system.log, var/log/exception.log, anything under var/reports and also anything under your apache error log. – Dan Hanly Sep 4 '14 at 15:32
  • Did not have an error but I did have an exception which was cleared up by what Amit Bera and Keyul Shah suggested. – oach Sep 4 '14 at 18:26
  • then revert it and check in all xml file and php of your instance the code contacts/form.phtml occurs again or not,if it occur more then once then remove second – Amit Bera Sep 4 '14 at 19:02
  • Removing the code that Keyul mentioned removes the doubling up of the output. – oach Sep 4 '14 at 19:43
0

Issue1:Also as you used blocks type at contacts/location so it means this class should be Mage_Contacts_Block_Location.

As this class not exits then override this class using another class

<global>
        <blocks>
            <contacts>
                <class>TPW_Contacts_Block</class>
            </contacts>
        </blocks>
    </global>

change to

 <global>
            <blocks>
                <customcontacts>
                    <class>TPW_Contacts_Block</class>
                </customcontacts>
        <contacts>
            <rewrite>
                <location>TPW_Contacts_Block_Location</location>
            <rewrite>
        <contacts>
            </blocks>
        </global>

Issue2: Other issue with file location:

As TPW_Contacts_Block_Location if location should be app/code/local/TPW/Contacts/Block/Location.php from app/code/local/TPW/Contacts/Block/Contacts.php

Step3: your current indexAction did not set form post action .In default magento from post action is set from indexAction function of Mage_Contacts_IndexController.If your rewrite class indexAction class inherit parent class then post action easy come

So,you need to change from

public function indexAction()
{

    $this->loadLayout();
    $this->renderLayout();
}

to

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

    }
  • Made the changes. Thank you (and Keyul Shah as well). It is working but now I see the output I added and the form on the page twice. – oach Sep 4 '14 at 18:14
  • give screen.. for check issue – Amit Bera Sep 4 '14 at 18:23
  • Screen Shot – oach Sep 4 '14 at 18:43
  • An aside: since I am new to this is there another way that is simpler than I am doing or is this the correct process? – oach Sep 4 '14 at 18:45
  • remove <reference name="content"> <block type="core/template" name="contactForm" template="contacts/form.phtml"/> </reference> code from contacts.xml for testing – Amit Bera Sep 4 '14 at 18:46
0

In <frontend> you are forgot to add the below line.

 <layout>
  <updates>
    <contacts>
      <file>contacts.xml</file>
    </contacts>
  </updates>
</layout>

So It will not calling your contacts.xml file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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