I am trying to block a recent "Contact Us" form spammer. I figured the best way to do this is by adding a form key and validating it in the controller.
This works when I modify core files, which is obviously not what the end solution should be,
I have read several questions and tutorials on overriding a controller, and I have tried them with no luck, the core controller always gets used, and the validation never happens. What am I doing wrong? (note: I have not created a module in Magento as of yet, this is my first)
Here's what I have:
New file: app/code/local/ACS/Contacts/controllers/IndexController.php
This is a copy of the core file app/code/core/Mage/Contacts/controllers/IndexController.php
with the addition of
if (!$this->_validateFormKey()) {
$error = true;
}
in the try
block of the postAction()
function.
2nd New File: app/code/local/ACS/Contacts/etc/config.xml
Which looks like this:
<?xml version="1.0"?>
<config>
<modules>
<acs_contacts>
<vesion>0.1.0</version>
</acs_contacts>
</modules>
<frontend>
<routers>
<contacts>
<args>
<modules>
<contacts before="Mage_Contacts">ACS_Contacts</contacts>
</modules>
</args>
</contacts>
</routers>
</frontend>
</config>
And finally, last new file app/etc/modules/ACS_Contacts.xml
:
<?xml version="1.0"?>
<config>
<modules>
<ACS_Contacts>
<active>true</active>
<codePool>local</codePool>
</ACS_Contacts>
</modules>
</config>
And of course I have added the form_key to app/design/frontend/theme/template/contacts/form.phtml