In this Magento 2 tutorial, we will show you five simple steps to add a contact form to your CMS page (e.g.: Contact us page) in Magento 2. Let’s get started!
Contents
Step 1: Add A New CMS Page
Open your Magento 2 admin panel, navigate to CONTENT, select Pages (under Element), then click on Add New Page button.
(Admin Panel > CONTENT > Pages > Add New Page)
Step 2: Add Information For The CMS Page
Here, you need to enter the Page Title, URL Key, Meta Title, Meta Keyword, Meta Description and select the store view(s) where the page belongs to.
Step 3: Add Content (HTML) To The CMS Page
It’s up to you to add more information to the Content section.
For example, you can insert the Google Maps as the following: firstly, visit the Google Maps, search for your location; secondly, click on Share, select Embed a map and click on COPY HTML; and finally, paste the link to your HTML Content.
Step 4: Add The Contact Form To The CMS Page
You can change the title for each field in the contact form.
In your source code:
app/design/frontend/company/name_theme/ new folder: Magento_Contact
app/design/frontend/company/name_theme/Magento_Contact/ new folder: templates
app/design/frontend/company/name_theme/Magento_Contact/templates/ new file: form.phtml.
In this file, you can customize the form to your need.
Then, to insert the contact form to the CMS page that we are creating, you just need to add: {{block type=’core/template’ name=’contactForm’ template=’contacts/form.phtml’}} to the Content section.
Step 5: Save The Page
Eventually, remember to save the configuration and flush cache (or run the command: php bin/magento cache:flush).
We have given you the detailed instruction to easily add a custom contact form to your CMS Page. If you have any difficulties when following the instruction, be free to leave a comment below. See you in the next tutorial.
Read more:
How To Customize Magento 2 Email Templates in 5 Minutes
I tried going through Step 4 to add a contact form to my CMS page but it doesn’t work. I also tried deploying static content in addition to clearing the cache but still nothing. Any ideas?
Hey Jeff, feel free to email us your question, as it would be quite lengthy to answer your question here. All the best!