Magento2 Override Contact Post Controller

by Karamdeep Singh   Last Updated July 18, 2018 06:09 AM

how to Override contact controller in custom module?


Answers 1

create di.xml file in your custom module


add below code in di.xml file.

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="\Magento\Contact\Controller\Index\Post" type="Contact\Custom\Controller\Index\ExtendIndex" />

create ExtendIndex.php file /magento2/app/code/Contact/Controller/Index/ExtendIndex.php

     namespace Contact\Custom\Controller\Index;
class ExtendIndex extends \Magento\Contact\Controller\Index\Post
     * Index action
     * @return $this
    public function execute($coreRoute = null)

        $this->messageManager->addSuccess('Message from new controller.');
        return parent::execute($coreRoute);
Karamdeep Singh
Karamdeep Singh
August 30, 2016 05:06 AM

Related Questions

Override method that Print Invoice

Updated April 14, 2017 11:09 AM