7 answers
i want to add captcha in contact us page contact form,im using aroma theme kindly help me…
@yasar,
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.
http://prntscr.com/6z0mgw
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
http://prntscr.com/6z0mnp
Step-3 : Under Forms, you could not find “Contact Us” form, To add Contact Us form, findcaptcha/forms element in core_config table and add “contact_form” form name to the list and modify config.xml in
/app/code/core/Mage/Captcha/etc
in – <frontend> – <areas> add something like
<contact_form>
<label>Contact Us</label>
</contact_form>
Step-4 : and in – <always_for> add the below
<contact_form>1</contact_form>
Also there’s a miss for translation in the config file, so you should add this to the<frontend> section:
<translate>
<modules>
<Mage_Captcha>
<files>
<default>Mage_Captcha.csv</default>
</files>
</Mage_Captcha>
</modules>
</translate>
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
<contacts_index_index>
<reference name=”contactForm”>
<block type=”core/text_list” name=”form.additional.info”>
<block type=”captcha/captcha” name=”captcha”>
<reference name=”head”>
<action method=”addJs”>
<file>mage/captcha.js</file>
</action>
</reference>
<action method=”setFormId”>
<formId>contact_form</formId>
</action>
<action method=”setImgWidth”>
<width>230</width>
</action>
<action method=”setImgHeight”>
<width>50</width>
</action>
</block>
</block>
</reference>
</contacts_index_index>
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(\\\’form.additional.info\\\’); ?>
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 theforms/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 incode/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);
Mage::getSingleton(‘customer/session’)->setCustomerFormData($this->getRequest()->getPost());
$this->getResponse()->setRedirect(Mage::getUrl(‘*/*/’));
return;
}
}
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.
Good Luck.
i have implement our code
i get this error
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in …/app/code/core/Mage/Contacts/controllers/IndexController.php on line 81
kindly help me
thanks in advance
regards -- yasar
im solved the Error but it did not showing the captcha on contact page if im enable the testimonial submitting form its working good,captcha is showing ,but in a contact us page it did not show,
Kindly help me
Captcha did not show in front end but when im fill the form and submit it say
- Incorrect CAPTCHA.
Kindly help Me
Im find a solution for this
<?php echo $this->getChildHtml(\\\’form.additional.info\\\’); ?>
its not call a echo function
just make it to
<?php echo $this->getChildHtml('form.additional.info'); ?>
and also change the captcha layout xml file ” to "