2

Using Magento 1.7 and I've created a simple frontend form, however, when I go to test and submit the form it returns the 404 page, though I'm really not sure why.

Here is my code structure:

|-Vendor
|-----Module
|---------Block
|-------------Form.php
|---------controllers
|-------------IndexController.php
|---------etc
|-------------config.xml

Form.php:

<?php
    class Vendor_Module_Block_Form extends Mage_Core_Block_Template
    {
        public function getFormAction()
        {
            return $this->getUrl('module/index/post');
        }
    }

IndexController.php

<?php
    class Vendor_Module_IndexController extends Mage_Contacts_IndexController
    {
        public function postAction()
        {
            //custom form stuff
        }
    }

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Vendor_Module>
            <version>0.1.0</version>
        </Vendor_Module>
    </modules>
    <frontend>
        <routers>
            <module>
                <args>
                    <modules>
                        <Vendor_Module before="Mage_Contacts">Vendor_Module</Vendor_Module>
                    </modules>
                </args>
            </module>
        </routers>
    </frontend>
    <global>
        <blocks>
            <module>
                <class>Vendor_Module_Block</class>
            </module>
        </blocks>
    </global>
</config>

I've checked in admin and can see that it is enabled, I've added a Helper/Data.php file as suggested in another SO post. I've cleared cache and reindexed but still, it doesn't work.

Any ideas or anything clearly wrong that I've missed?

5
  • There might be an issue with your form action URL. Please check it again. Nov 20, 2017 at 13:03
  • @Piyush because I want custom validation stuff :)
    – treyBake
    Nov 20, 2017 at 13:28
  • @DineshYadav how can I checkl more than I already have?
    – treyBake
    Nov 20, 2017 at 13:29
  • @ThisGuyHasTwoThumbs if overriding controller is necessary then check this answer magento.stackexchange.com/a/134010/20064
    – Piyush
    Nov 20, 2017 at 13:33
  • @Piyush the only thing that was new was the observer, but that's not needed because I don't intend to prevent anything :/
    – treyBake
    Nov 20, 2017 at 13:51

1 Answer 1

3

I assume that you are extending/rewriting the contacts index controller, so you should use contacts/index/postcustom in your form action instead of module/index/post. And update your codes with the below guide.

In your IndexController.php, require the Mage_Contacts_IndexController file. See version below:

<?php

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

class Vendor_Module_IndexController extends Mage_Contacts_IndexController {
    public function postcustomAction()
    {
        //custom form stuff
    }
}

And in your config.xml, update the frontend>routers... like below:

<?xml version="1.0"?>
<config>
    ...
    <frontend>
      <routers>
        <contacts>
          <args>
            <modules>
              <vendor_module_contacts before="Mage_Contacts">Vendor_Module</vendor_module_contacts>
            </modules>
          </args>
        </contacts>
      </routers>
    </frontend>
    ...
</config>

Make sure that you flush your cache to see the new changes.

4
  • You are extending the contactss router, so you should use contacts/index/post in your form action instead of module/index/post.
    – Ner
    Nov 20, 2017 at 13:55
  • Notice the contacts and before="Mage_Contacts" in your config.xml file. It tells Magento to use yours first before the actual class from contacts module.
    – Ner
    Nov 20, 2017 at 14:00
  • 1
    Can you compress your module and attach it here. Just the module in app/code so we can better investigate what's the issue. :)
    – Ner
    Nov 20, 2017 at 14:03
  • Let us continue this discussion in chat.
    – Ner
    Nov 20, 2017 at 14:06

Your Answer

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

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