Welcome to Discussion Forum, where you can ask questions and receive answers from other members of the community.

How To Add Custom Fields to Magento 2 Contact Page

0 like 0 dislike
Firstly create a module
 
create module.xml in app/code/Magenticians/Modulecontact/etc and put the code:
 
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magenticians_Modulecontact" setup_version="1.0.1">
</module>
</config>
 
 
For module registration, create registration.php in app/code/Magenticians/Modulecontact and put the code:
 
<?php
 
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magenticians_Modulecontact',
__DIR__
);
 
 
 
Now override and add new field in Magento 2 contact form.
 
Copy form.phtml file from the vendor/magento/module-contact/view/frontend/templates and paste in app/code/Magenticians/Modulecontact/view/frontend/templates.
To add a new field to the contact form, open form.phtml file and add the following code:
 
<div class="field subject required">
             <label class="label" for="subject"><span><?php /* @escapeNotVerified */ echo __('Subject') ?></span></label>
             <div class="control">
                  <input name="subject" id="subject" title="<?php /* @escapeNotVerified */ echo __('Subject') ?>" value="" class="input-text" type="text" data-validate="{required:true}"/>
             </div>
        </div>
 
 
asked Oct 30, 2018 in Magento by suthan

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

Related questions

0 like 0 dislike
0 answers 28 views
1 like 0 dislike
1 answer 304 views
304 views asked Mar 6, 2017 in Magento by harsh (8,710 points)
0 like 0 dislike
0 answers 2,442 views
2,442 views asked May 1, 2017 in Magento by harsh (8,710 points)
0 like 0 dislike
0 answers 279 views
1 like 0 dislike
0 answers 18 views
18 views asked Mar 31, 2017 in Magento by harsh (8,710 points)
...