Skip to main content
Share Your Experience: Take the 2024 Developer Survey
43 votes

Add custom field to contact form Magento 2?

First, open the form.phtml file located in your theme. /magento_root/app/design/frontend/VENDER_NAME/YOUR_THEME/Magento_Contact/templates/form.phtml, then add subject field to this contact form: <...
Technocracker's user avatar
23 votes

Magento2 contact form in CMS page

Call your contact form block with template file in the cms pages. Try below code : {{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}
Manthan Dave's user avatar
  • 9,826
18 votes
Accepted

Magento2: How to validate form and display error message below input field

You need to do add data-mage-init='{"validation":{}}' inside form declaration as following: <form class="form contact" action="<?php /* @escapeNotVerified */ echo $block->getFormAction(); ...
Sohel Rana's user avatar
  • 35.9k
14 votes

Magento 2 - State/Province dropdown and Country Dropdown in Contact form

Following method will add Country and Region dropdown to contact us form, [namespace]/[modulename]/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
Ekta Puri's user avatar
  • 1,116
9 votes
Accepted

How to Validate the Google reCaptcha

You should try this code: I have been using this on my site. <script> window.onload = function() { var recaptcha = document.forms["contactForm"]["g-recaptcha-response"]; recaptcha.required =...
NID's user avatar
  • 937
8 votes

Contact form after submission not redirecting to cms page Magento 2

Contact Post Controller needs to be overridden here, because by default it redirects to contact/index $this->_redirect('contact/index'); needs to be changed to $this->_redirect('cms-page-url-...
Anshu Mishra's user avatar
  • 8,970
7 votes

How to Validate the Google reCaptcha

The accepted JavaScript solution above is definitely NOT the way to go in my opinion. Any bot that's not using JS (which is most of them) will simply bypass your validation and you'll get all that ...
Sean Michaud's user avatar
7 votes

How to Validate the Google reCaptcha

This script use for validation google reCaptcha like a default validation of magento. please use it. <form name="freeeventForm" id="freeeventForm"> <div id="RecaptchaField"></div&...
Shorabh's user avatar
  • 1,508
7 votes

Add Captcha to magento 2 contact form on cms page

There is no need to call <p>{{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}</p> in the content tab. If you don't have any ...
Mohit Kumar Arora's user avatar
6 votes

How to Validate the Google reCaptcha

I used recaptcha in contact form.. <form action="<?php echo Mage::getUrl('mcrecaptcha/index/save'); ?>" id="contactForm" method="post" onSubmit="return checkcaptcha() ;"> <ul class=...
Jigs Parmar's user avatar
  • 2,438
5 votes

Magento2 contact form in CMS page

{{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}
omelandr's user avatar
  • 1,267
5 votes

Magento 2 : Show captcha at contact us form

You can make a custom form template (based on the original) then you can load reCaptcha block programmatically whith this : <?php echo $block->getLayout() ->createBlock('MSP\...
Yann Charlou's user avatar
4 votes
Accepted

Magento Contact Form: What is the 'hideit' input for?

I reckon it's the same use as it was back in M1. If I remember right it was introduced around 1.4 to prevent spam. As you can see from the controller part you pasted, it will throw an error if this ...
Raphael at Digital Pianism's user avatar
4 votes

Contact us email not sending

Try this, Hope It's helpful for you. your website is just on localhost, which does not support sending email (some tools allow but not many). The following solution will help you much with ...
Randhir Yadav's user avatar
4 votes
Accepted

Magento 2 Plugin for Contact Form Post Controller

At this,case you have to use around method (aroundExecute()). First, create di.xml at app/code/{VendorName}/{Modulename}/etc/frontend/ for define plugin class. <?xml version="1.0"?> <config ...
Amit Bera's user avatar
  • 77.5k
3 votes
Accepted

Submit a form in Magento 2 custom module?

create a controller Save.php and copy paste in your module. <?php namespace [Namespace]\[ModuleName]\Controller\Index; class Save extends \Magento\Framework\App\Action\Action { /** * @...
Bojjaiah's user avatar
  • 4,002
3 votes

Magento2: How to validate form and display error message below input field

Form ID: #custom-register-form Before Submit the form Check the validation To Check All Fields & Display Error: $('#custom-register-form').on('submit', function (event) { var dataForm = jQuery('...
Renga's user avatar
  • 371
3 votes

Magento2: How to validate form and display error message below input field

Form Validation can be applied in three ways: 1) <script type="text/x-magento-init"> { "#custom-form": { "validation": {} } } </script> 2) <form data-mage-init='{"...
Ahmad Vaqas Khan's user avatar
3 votes

How to Validate the Google reCaptcha

To validate captcha, create a save controller for saving your form values and also the validation. namespace Mike\SampleModule\Controller; class Save extends \Magento\Framework\App\Action\Action { /*...
Mike's user avatar
  • 1,148
3 votes
Accepted

Add new custom field in magento 2 contact form

Open your form.phtml file. /magento_root/app/design/frontend/VENDER/YOUR_THEME/Magento_Contact/templates/form.phtml Then add mycustomfield field to this contact form: <div class="field ...
Nikunj Vadariya's user avatar
3 votes
Accepted

how to store contact us form details in database programmatically magento 2?

Magento does not have this functionality. So you have created a module which has Database table Model class ResoureModel Class Collection class Then for saving the data, you have to rewrite the ...
Amit Bera's user avatar
  • 77.5k
3 votes

how to store contact us form details in database programmatically magento 2?

Us this free extension to store data in database. By using observer can get all data This module will add a table to your Magento 2 database. As with any third party modules that do this, it is ...
Ketan Borada's user avatar
  • 2,613
3 votes
Accepted

Add custom field in contact form

For achieved this functinality We need to create source model. Dont used it inline in form First create source model <?php namespace Custom\Module\Model\Config\Source; use Magento\...
Vijay Khirade's user avatar
3 votes

How to submit contact us data to Magento 2 contact us form action using graphqL?

Since we don't have default contact us mutation in default magento graphql, I did this task with a custom module. For this we want to create the custom contact us Mutation. type Mutation { ...
Mujahidh's user avatar
  • 2,793
3 votes
Accepted

Implementation of sending selected items along with feedback form

Download module from here and install it. I have created example module i.e Warranty and there is a form with name, email and elements Elements contain 5 options : Element A, Element B, Element C, ...
Naresh Rupareliya's user avatar
3 votes

Unable to send emails. Could not acquire lock for cron job: sales_send_order_invoice_emails

I guess Magento cron job is stuck in "running" status. Need to kill the stuck cron job then it will continue as scheduled. Log in to your account using SSH. Run the following command to ...
Pratik Oza's user avatar
  • 3,992
2 votes
Accepted

Input value must contain number higher than 5

You can use custom validation class 'validate-value-greater-than-5' and add following script in form javascript. Validation.add('validate-value-greater-than-5', 'Please enter a value greater than 5.',...
Gulshan Maurya's user avatar
2 votes

Input value must contain number higher than 5

You have to just use type=number in input. <input type="number" name="quantity" min="6"> Now user have input 6 or higher than 6 to submit form otherwise display error with no form submit.
Rakesh Jesadiya's user avatar
2 votes

Contact form email template - Array

Magento doesn't allow to use array in email variable.So change checkbox html as below. <input type="checkbox" name="contact_method_tel" value="Telephone"> Telephone<br> <input type="...
himansu's user avatar
  • 224
2 votes
Accepted

Magento 1.9 Contact form

You have to create another custom form, like this Inchoo tuto, then you can include the form in your cms page according this tuto like this: {{block type="core/template" name="form.custom" ...
PЯINCƎ's user avatar
  • 11.7k

Only top scored, non community-wiki answers of a minimum length are eligible