Lots of spam is being sent to this form. I need to add Google Recaptcha to it.

What is the PHP file that's responsible for receiving the contact POST at /contacts/index/post/ ?

After some search I couldn't find anything relevant except form.phtml which seems to be only responsible for displaying the form but not receiving the POST data.

  • did you get your solution? Aug 11, 2018 at 6:45

2 Answers 2


He is talking about Magento1 because there no contacts in Magento2

Magento1 = contacts/index/post

Magento2 = contact/index/post

So contacts/index/post is a controller contact form module :

contacts = frontname,

index = controllerName,

post = postAction().

If you want to add you captcha, so it's happening in form.phtml, you have nothing to do in controller.

To add GoogleRecaptcha in your contact form :


$sitekey ='site_key_here'; //you get it from googleRecaptcha V3
$secret ='secret_key_here'; //you get it from googleRecaptcha V3
<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post" onsubmit="return validateCaptcha()">
    <div class="g-recaptcha" id="recaptcha" data-sitekey="<?php echo $sitekey; ?>"></div> <!-- Google CAPTCHA-->
    <div id="error-g-captcha" style="display:none;"><?php echo $this->__('Please check the captcha validation !')?></div>

<script type="text/javascript">
    var contactForm = new VarienForm('contactForm', true);

    // captcha validation
    function validateCaptcha() {
        var v = grecaptcha.getResponse();
        if(v.length == 0) {
            return false;
        } else {
            return true;


<?xml version="1.0"?>
<layout version="0.1.0">
        <reference name="head">
           <action method="addItem"><type>external_js</type><name>https://www.google.com/recaptcha/api.js</name><params/></action>

For Magento 1: Goto to below location


You will find postAction() this is the function you are looking for.

Before changing anything please override that function to your custom module then change


You can install 3rd party extension for captcha.

If you are using magento 2 then file location will be different.

Hope this helps.

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.