0

I'm creating a custom module for a page with an email form on. Everything seems to work fine but I cant get my layout updates to work. This is my first custom module so any help would be great. Thank you.

app/code/local/Adtrak/ArrangeSurvey/ect/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <adtrak_arrangesurvey>
            <version>0.1.0</version>
        </adtrak_arrangesurvey>
    </modules>
    <global>
        <rewrite>
            <adtrak_arrangesurvey>
                <from><![CDATA[#^/arrangesurvey/#]]></from>
                <to>/adtrakArrangeSurvey/</to>
            </adtrak_arrangesurvey>
        </rewrite>
    </global>
    <frontend>
        <routers>
            <adtrak_arrangesurvey>
                <use>standard</use>
                <args>
                    <module>Adtrak_ArrangeSurvey</module>
                    <frontName>adtrakArrangeSurvey</frontName>
                </args>
            </adtrak_arrangesurvey>
        </routers>
        <layout>
            <updates>
                <adtrak_arrangesurvey>
                    <file>adtrakArrangeSurvey.xml</file>
                </adtrak_arrangesurvey>
            </updates>
        </layout>
    </frontend>
</config>

app/design/frontend/doorfit/deafult/layout/adtrakArrangeSurvey.xml

<?xml version="1.0"?>
<layout version="0.1.0">

<adtrak_arrangesurvey_index_index>
    <label>Arrange A Survey</label>
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
            <action method="setHeaderTitle" translate="title" module="arrangesurvey"><title>Arrange A Survey</title></action>
        </reference>
        <reference name="content">
            <block type="core/template" name="surveyForm" template="arrangesurvey/index.phtml"/>
        </reference>
    </adtrak_arrangesurvey_index_index>

    <adtrak_arrangesurvey_thanks_index>
        <label>Thank You</label>
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
            <action method="setHeaderTitle" translate="title" module="contacts"><title>Thank You</title></action>
        </reference>
        <reference name="content">
            <block type="core/template" name="surveyForm" template="arrangesurvey/thanks.phtml"/>
        </reference>
    </adtrak_arrangesurvey_thanks_index>
</layout>

app/code/local/Adtrak/ArrangeSurvey/controllers/IndexController.php

I've inserted the form block here because I couldnt get the layout file working so hopefully I can remove that after.

require_once 'Mage/Contacts/controllers/IndexController.php';

class Adtrak_ArrangeSurvey_IndexController extends Mage_Contacts_IndexController
{

   public function indexAction()
    {
        $this->loadLayout();

        $block = $this->getLayout()->createBlock(
        'Mage_Core_Block_Template',
        'arrangesurvey.form',
        array('template' => 'arrangesurvey/index.phtml')
        );


        $this->getLayout()->getBlock('content')->append($block);

        $this->renderLayout();

    }

    public function postAction()
    {
      Mage::log('postAction rewritten');
        $post = $this->getRequest()->getPost();
        if ( $post ) {
            $translate = Mage::getSingleton('core/translate');
            /* @var $translate Mage_Core_Model_Translate */
            $translate->setTranslateInline(false);
            try {
                $postObject = new Varien_Object();
                $postObject->setData($post);

                $error = false;

                if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
                    $error = true;
                }

                if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
                    $error = true;
                }

                if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                    $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'))
                    ->setReplyTo($post['email'])
                    ->sendTransactional(
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                        null,
                        array('data' => $postObject)
                    );

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

                $translate->setTranslateInline(true);

                $this->_redirect('arrangesurvey/thanks');

                return;
            } catch (Exception $e) {
                $translate->setTranslateInline(true);

                Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
                $this->_redirect('*/*/');
                return;
             }

        } else {
            $this->_redirect('*/*/');
        }
    }

}

Any help or advice would be great.

1 Answer 1

3

Try to replace

<adtrakArrangeSurvey_index_index>

with

<Adtrak_ArrangeSurvey_index_index>

May be there is another errors. But this is the first I met

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the answer, I'm afraid this didnt seem to work (its still loading the 2 coloumn template instead of 1) I'll update the code above.
After looking at examples I've used the 'frontname' to define the layout file <adtrakArrangeSurvey> <file>adtrakArrangeSurvey.xml</file> </adtrakArrangeSurvey> Is this correct?
I have some notes about your code. Some of them is not so important but it can be a reason of unexpected erroes: 1. Don't use camel case notation in xml. <Adtrak_ArrangeSurvey> - <adtrak_arrangesurvey>
2. Define layout in xml with the same tag as the router: <adtrak_arrangesurvey>
And the last thing that can help you: add to the index action of controller the next code: $this->loadLayout(); echo "<pre>"; print_r($this->getLayout()->getUpdate()->getHandles()); echo "</pre>"; die(); This code will show you list of all layout update handlers. Good luck
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.