Showing results for 
Search instead for 
Did you mean: 

customizing the default magento 2 contact form department wise

customizing the default magento 2 contact form department wise


my client has a team of 1000+ employees with minimum of 100+ employees in each department. i want to customize the contact form to add the department field selection, so that each department receives only related contact inquiries. I'm ready to pay for the readymade solution for this if available. I'm in a bit hurry to implement customization of the contact form, please help me with solution.

thanks in advance


Re: customizing the default magento 2 contact form department wise

Re: customizing the default magento 2 contact form department wise

To customize the default Magento 2 contact form department-wise programmatically, The basic idea is that you can create a custom module and override the default behavior of the contact form. Here are the general steps you can follow:
Create a Magento 2 Module:
  • Create a new module in your Magento 2 installation. Let's name it Custom_ContactForm.
Create the following directory structure:
Create Module Files:
Create the registration file:
Create the module declaration file:
<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Custom_ContactForm" setup_version="1.0.0">
            <module name="Magento_Contact"/>
Create A Plugin for the Contact Form:
Create a file for the plugin:
namespace Custom\ContactForm\Plugin;

class ContactPost
    public function aroundExecute(
        \Magento\Contact\Controller\Index\Post $subject,
        \Closure $proceed
    ) {
        // Your customization logic goes here

        // Call the original method
        $result = $proceed();

        return $result;
Customize the Contact Form logic:
Update the aroundExecute method in the ContactPost plugin to customize the contact form logic based on departments. You can use the request data to identify the selected department and perform your customization.
// Inside the aroundExecute method
$request = $subject->getRequest();
$department = $request->getParam('department');

// Implement your logic based on the selected department
if ($department == 'sales') {
    // Customize for the Sales department
} elseif ($department == 'support') {
    // Customize for the Support department

// Call the original method
$result = $proceed();

return $result;
Configure the Plugin:
Create a configuration file for the module:
<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Contact\Controller\Index\Post">
        <plugin name="custom_contactform_contactpost" type="Custom\ContactForm\Plugin\ContactPost" sortOrder="1"/>
Run Setup Commands:
php bin/magento setup:upgrade
php bin/magento cache:flush
Now, your custom module should override the default behavior of the Magento 2 contact form based on the selected department. Adjust the code in the ContactPost plugin according to your specific requirements and business logic.
If you have any question regarding this then please browse our Hire Magento Developer page we can discuss further in details.