Magento Enable Captcha For Contact Us Form

Magento has default contact us form and by default is had been disabled, you need to enable it from the admin configuration. The same way Magento also has CAPTCHA and by default it is disabled.

Find below steps to enable the Contact us form.

Step-1 : On the Admin menu, select System > Configuration.

Step-2 : In the panel on the left, under General, click Contacts.

Step-3 : Click to expand the Contact Us section, and set Enable Contact Us to Yes.

Magento enable contact us

To Enable CAPTCHA, Follow the below steps

Step-1 : On the Admin menu, select System -> Configuration -> ADVANCED ->Admin.

Step-2 : Click to expand the CAPTCHA section, and Enable CAPTCHA in Admin to Yes. There you can find “Forms” and “Displaying Mode”, Find Below image for your reference

Magento enable captcha

Step-3 : Under Forms, you could not find “Contact Us” form, To add Contact Us form, find captcha/forms element in core_config table and add “contact_form” form name to the list and modify config.xml in


in – <frontend><areas> add something like

<label>Contact Us</label>

Step-4 : and in – <always_for> add the below


Also there’s a miss for translation in the config file, so you should add this to the <frontend> section:


Step-5 : Refresh cache. Login to Admin, and make sure Contact Us form is listed in CAPTCHA configuration

Step-6 : Modify captcha layout xml file in frontend/base/default (or your theme) and add this section

<reference name=”contactForm”>
<block type=”core/text_list” name=””>
<block type=”captcha/captcha” name=”captcha”>
<reference name=”head”>
<action method=”addJs”>
<action method=”setFormId”>
<action method=”setImgWidth”>
<action method=”setImgHeight”>

and Refresh cache.

Step-7 : Modify form code in /frontend/base/default/template/contacts/form.phtml to add placeholder to render captcha layout .Add this line of code right before </ul>

<?php echo $this->getChildHtml(\\\’\\\’); ?>

Step-8 : Now, how to “trap” the post from the Contact Us form and check the captcha
Mage uses Events and Observer to achieve this, and it works very well for the forms/events they have implemented this feature. I was not able to find events specific for Contact Us form, so, IMHO the most obvious solution is to override indexController in code/core/Mage/Contacts/controllers and in the postAction method, inside try block add the following code:

$formId = ‘contact_form';
$captchaModel = Mage::helper(‘captcha’)->getCaptcha($formId);
if ($captchaModel->isRequired()) {
if (!$captchaModel->isCorrect($this->_getCaptchaString($this->getRequest(), $formId))) {
Mage::getSingleton(‘customer/session’)->addError(Mage::helper(‘captcha’)->__(‘Incorrect CAPTCHA.’));
$this->setFlag(”, Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);

and add this utility method to the controller class:

protected function _getCaptchaString($request, $formId)
$captchaParams = $request->getPost(Mage_Captcha_Helper_Data::INPUT_NAME_FIELD_VALUE);
return $captchaParams[$formId];

Step-9 : Refresh Cache, You are done.


  1. Deepak K.


    Also, when I checked the form id using firebug its showing “contactForm” instead “contact_form”. I’m using magento 1.9. Please help.

  2. Susanta Kumar Das


  3. Susanta Kumar Das

    It really Help full

  4. Thank you very much. This is exactly what i am looking for. Worked perfectly! Thaks!

Leave a Comment