Magento’s design theme system has grown significantly over the years. Compared to Magento 1.x, there are so many distinctive changes and improvements were done in default theme structure also now it allows creating unlimited parent themes as well as now its support latest languages like HTML5, CSS3, and jQuery. When it comes to giving a personalized touch to Magento store, instead of modifying default theme files overriding file is the safest way to change the layout & We also never recommended to modify core files. Also, check out the Quick Contact Form extension for Magento 2 which helps to embed the contact button on all the pages of your website.
Recently working on Magento custom development requirement, we came across the requirement of adding an element on the frontend form. At that time, we have overridden child theme contact form which we have shared below.
Firstly, you need to create ‘contact_index_index.xml‘ the file at following location.
app\design\frontend\Your Theme\Magento_Contact\layout\contact_index_index.xml
Magento_Contact::form.phtml
Once you are done, you have to create another file ‘form.phtml‘ at below location and inside that you have to put your contact form code which you want to override.
app\design\frontend\Your_Theme\Magento_Contact\templates\form.phtml
Taada, you have successfully override contact form in your Magento 2 child theme. You can even customize this code according to your need of adding and removing contact form elements.
Comment down below if you are looking for help regarding this code & don’t forget to rate this blog.
Happy Overriding!
Hi,
Thanks for the helpful post. Question: how would I reference the custom contact form block as a namespace? i.e., what’s the equivalent of Magento\Contact\Block\ContactForm here?
Then you can use another method of specify template with the class like this one
< block class="Vendor\Extension\Block\Yourblock" name="yourblockname" template="Vendor_Extension::form.phtml">