36

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: <div class="field subject required"> <label class="label" for="subject"><span><?php /* @escapeNotVerified */ echo __('Subject') ?></...


23

Change this line from the contact from var contactForm = new VarienForm('contactFormNew', true); with var contactForm = new VarienForm('contactFormNew', false); The second parameter means "focus on first field". That's why you get the down scroll.


22

In order to add CAPTHA to a Contact Us form you have to go to Stores -> Configuration -> Customers -> Customers Configuration page and Enable CAPTCHA. Make sure to select Contact Us value in Forms field. Once you update configuration, clean cache. Hope it helps.


17

You need to do add data-mage-init='{"validation":{}}' inside form declaration as following: <form class="form contact" action="<?php /* @escapeNotVerified */ echo $block->getFormAction(); ?>" id="contact-form" method="post" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>" data-mage-init=...


14

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"}}


10

It's happening because the action attribute of form gets set by the controller file of the module, which is not being called as you are placing it on a custom page. You'll need to add that action to the form for proper submit behavior of contact form. For a quick fix, if you have your form.phtml file in theme folder, you can change the form action in it as : ...


9

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-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> <preference for="Magento\Contact\...


9

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 = true; recaptcha.oninvalid = function(e) { alert("Please complete the captcha"); } } </script>


7

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> <input type="hidden" class="validate-reCAPTCHA"> </form> <script src="https://www.google.com/recaptcha/api.js?onload=...


6

I used recaptcha in contact form.. <form action="<?php echo Mage::getUrl('mcrecaptcha/index/save'); ?>" id="contactForm" method="post" onSubmit="return checkcaptcha() ;"> <ul class="form-list"> <li class="fields"> <div class="field"> <div class="input-box"> ...


5

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-key'); in file vendor/magento/module-contact/Controller/Index/Post.php Code for controller override is as follows : app/code/Custom/Contact/registration.php &...


5

{{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}


5

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 spam you're trying to block. Always always always validate on the server. JS validation is just a UX first step. Anyway, there are multiple solutions, but here's ...


4

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 field is not empty. Robots are used to fill every input tag of the form, including hidden input tags. If that field is not empty, that means a robot has ...


4

If you look at the contacts controller used in the form action, you will find that the transactional template is taken directly from the configuration all POST data is passed to the template (as template variable data), so that you can add any additional fields to the form template and use them in the email template. But validation is hard coded for "name", ...


4

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 email problem of Magento on localhost, which enables you debug and test email. Link to download: https://github.com/aschroder/Magento-SMTP-Pro-Email-Extension ...


4

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 other content to show in the content tab, then you can use &nbsp; in the Content tab. Steps to show captcha in contact form in CMS page are listed below: ...


3

Form Validation can be applied in three ways: 1) <script type="text/x-magento-init"> { "#custom-form": { "validation": {} } } </script> 2) <form data-mage-init='{"validation": {}}' class="form" id="custom-form" method="post" autocomplete="off"> 3) <script type="text/javascript"> require([ 'jquery', 'mage/mage' ]...


3

You'll need a custom module but it does not take much work if you know some basics of module development: create a controller action that does nothing more than $this->loadLayout(); $this->renderLayout(); Create a layout handle for this controller and include the predefined page_empty layout handle (this removes header, footer and sidebars, using ...


3

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 { /** * @var Google reCaptcha Options */ private static $_siteVerifyUrl = "https://www.google.com/recaptcha/api/siteverify?"; private $_secret; private static $...


3

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 class module-contact/controller/index/Post.php


3

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 recommended that you backup your database before installation.


3

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\Framework\Option\ArrayInterface; class Contact implements ArrayInterface { public function toOptionArray() { $loadedData =...


3

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, Element D, Element E(you can set option as per your requirement) please type in url : yoursitepath/warranty/registration/index to open below form(you can change ...


2

Use the below code in your CMS page in Magento. {{block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"}} Let me know if you face any further query with this.


2

try this i think it " problem.. {{block type="core/template" name="contactForm" form_action="{{store url='contacts'}}/index/post" template="contacts/form.phtml"}}


2

You have to override postAction(): app/etc/modules/SeStro_Contacts.xml <?xml version="1.0" encoding="UTF-8" ?> <config> <modules> <SeStro_Contacts> <active>true</active> <codePool>local</codePool> </SeStro_Contacts> </modules> </config> app/...


2

You can do something like this $bccRecipients = array( 'extra@domain.com' => 'Extra · Domain' ); $mailTemplate->addRecipients($bccRecipients, array(), Mage_Core_Model_Email_Queue::EMAIL_TYPE_BCC); Or just try $mailTemplate->addBcc("some@email.com");


2

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.


2

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('#custom-register-form'); if(dataForm.validation('isValid') === false){ return false; }}); To Single Fields & Display Error: $("#custom-register-form ...


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