Skip to main content
Post Closed as "Duplicate" by Fabian Schmengler, Amit Bera, Raphael at Digital Pianism, Qaisar Satti, Rakesh Jesadiya
added explanation
Source Link
Qaisar Satti
  • 32.5k
  • 18
  • 87
  • 137

Magento2how to Override Contact Post Controllercontact controller in custom module?

venoder/magento/module-contact/Controller/Index.php

Magento2 Override Contact Post Controller

how to Override contact controller in custom module?

venoder/magento/module-contact/Controller/Index.php
deleted 4 characters in body
Source Link

How to override magento2 contact controller?Magento2 Override Contact Post Controller

How to override magento2 contact controller?

Magento2 Override Contact Post Controller

deleted 978 characters in body
Source Link

create di.xml file in your custom module

/magento2/app/code/Contact/Custom/etc/di.xml 

add below code in di.xml file.

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

create ExtendIndex.php file /magento2/app/code/Contact/Controller/Controller/Index/ExtendIndex.phpHow to override magento2 contact controller?

<?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);
    }
}

create di.xml file in your custom module

/magento2/app/code/Contact/Custom/etc/di.xml 

add below code in di.xml file.

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

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

<?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);
    }
}

How to override magento2 contact controller?

deleted 4 characters in body
Source Link
Loading
added 94 characters in body
Source Link
Qaisar Satti
  • 32.5k
  • 18
  • 87
  • 137
Loading
Source Link
Loading