Skip to main content
53 votes

How to Create Custom Form in Magento2 Frontend?

Assuming you have the following module Company/Module. Create the frontend router /app/code/Company/Module/etc/frontend/routes.xml Create a route to manage : GET request wich going to display ...
Antoine Subit's user avatar
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
39 votes
Accepted

Add a note under a form field using ui components

You can achieve this using following tag. <item name="notice" xsi:type="string" translate="true">Some note here</item>
Sohel Rana's user avatar
35 votes

Invalid Form Key. Please refresh the page?

This bug arises due to php.ini variable "max_input_vars" Increase it to 10000 through below php function: ini_set('max_input_vars', 10000); OR Using linux command line cd /etc/php/7.0/apache2/ vi ...
Ahmad Vaqas Khan's user avatar
24 votes
Accepted

Magento 2 : How to add placeholder text to street fields in checkout?

Add these file in any of your custom module : app/code/Vendor/ModuleName/etc/module.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
Ashish Jagnani's user avatar
24 votes
Accepted

Magento 2 form field toggled type

This is checkbox form field. Which is included in UI Component library. You cannot use this toggle in $fieldset->addField(). You need to create a form with UI component to create this type of ...
Prince Patel's user avatar
  • 22.8k
21 votes

Magento 2 - How to affect street address in checkout forms with layout xml/ui arguments

The best solution for me was to base yourself in the same method mentioned above: (getMultilineFieldConfig) However creating a NEW MODULE. In your new or existing module, add Magento_Checkout in the ...
Rafael Ortega Bueno's user avatar
19 votes
Accepted

Magento 2 Form key

Try following way: protected $formKeyValidator; public function __construct ( \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator ) { $this->formKeyValidator = $formKeyValidator;...
Sohel Rana's user avatar
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
18 votes
Accepted

Magento 2 form validation: minimum/maximum length

Your code is totally right. Both minimum and maximum need to be set with minimum-length-[0-9]+$ and maximum-length-[0-9]+$ What you are missing is to update the data-validate attribute by replacing: ...
Raphael at Digital Pianism's user avatar
18 votes
Accepted

Checkout Form - How to wrap multiple elements in a class - Magento 2

Very interesting question. Let me answer the last assumption about the Checkout implementation. It might be over-engineered a bit since you have to add more than just 1 change in 1 file. The approach ...
Max Pronko's user avatar
  • 1,775
18 votes

Disable customer attribute in magento admin form

You need to create Namespace/Module/view/base/ui_component/customer_form.xml and add the following code <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="...
Shankar's user avatar
  • 442
17 votes

How to remove captcha in via terminal?

If you prefer to run commands instead of going to admin panel: Disable admin login captcha php bin/magento config:set admin/captcha/enable 0 Disable frontend captcha ( If form specific captcha is ...
Milan Chandro's user avatar
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
14 votes
Accepted

How to add a class to an admin form input?

You can use the additionalClasses : <item name="additionalClasses" xsi:type="string">my-custom-class</item> Side note: interestingly, it seems like it also handles arrays: <item name=...
Raphael at Digital Pianism's user avatar
13 votes
Accepted

Magento 2.1 image not uploading in edit form

you have to pass pass image array that contain image url,name for passing it to ui component you can use dataprovider <argument name="class" xsi:type="string">Namespace\Modulen\Model\Modelname\...
Qaisar Satti's user avatar
  • 32.5k
13 votes
Accepted

Magento 2 : How to know "used_in_forms" param of eav attribute for a form?

You can get all used_in_forms in magento by typing below query, Used in form customer attribute: SELECT DISTINCT form_code FROM customer_form_attribute WHERE 1 adminhtml_checkout ...
Rakesh Jesadiya's user avatar
11 votes

Invalid Form Key. Please refresh the page?

This problem is occurred after adding more custom options and categories in the product so because php.ini file not allowed to add more custom options. So, we need to change default settings of php....
Baharuni Asif's user avatar
11 votes
Accepted

Magento 2 admin form not loading

here sum mistake in your ui component hello_world_edit.xml <item name="provider" xsi:type="string">test_form.test_form_data_source</item> <item name="deps" xsi:type="string">...
Deexit Sanghani's user avatar
10 votes
Accepted

Magento 2 - It is possible to create a select with optgroup using \Magento\Framework\Data\Form\Element\::addField?

Try this solution: $fieldset->addField( 'test', 'select', [ 'label' => __('Test'), 'name' => 'test', 'required' => true, 'values' => [ ...
Siarhey Uchukhlebau's user avatar
10 votes

Magento 2 : Form values save in db and grid

For save record in Database : => Create a /app/code/Company/Blog/Setup/InstallSchema.php file : <?php namespace Company\Blog\Setup; use Magento\Framework\Setup\InstallSchemaInterface; use ...
Emipro Technologies Pvt. Ltd.'s user avatar
9 votes
Accepted

Magento 2 backend form date time form field

Try following way: $fieldset->addField( 'time', 'date', [ 'name' => 'time', 'label' => __('Time'), 'date_format' => ...
Sohel Rana's user avatar
9 votes
Accepted

How do I create date input field with calendar in Magneto2? [SOLVED]

Here I got the solution: <div class="control customer-dob"> <input type="text" class="input-text required-entry hasDatepicker" id="calendar_inputField" ...
Manish's user avatar
  • 3,116
9 votes
Accepted

What are the "source" Items in UI Component Files

Went to "the source" (groan) for this one and it looks like these <item name="source"/> nodes are, indeed, redundant. Or, the Magento engineer currently in charge of them thinks they're ...
Alana Storm's user avatar
  • 44.4k
8 votes
Accepted

Admin form redirect to dashboard - Magento2

You form must have form key to allow submit data. See formkey.phtml that used in core forms
KAndy's user avatar
  • 20.9k
8 votes

Magento 2.1 image not uploading in edit form

As stated by Qaisar, the idea is to use the data provider to add those information to the data. So in your form ui_component you first need to specify a data source: <dataSource name="...
Raphael at Digital Pianism's user avatar
8 votes

Add email field to Review Form - Magento 2

Seeing as how there's no clear answer on this yet, this might help some people. To add an e-mail field (or any other field) to the frontend review form and display it in the admin we have to create a ...
sduif's user avatar
  • 975
8 votes

What are the "source" Items in UI Component Files

The source is, or should be, the data provider. From what I can tell, however, the <item name="source"> node in the XML example you gave makes no measurable difference and can be removed without ...
bassplayer7's user avatar
  • 2,216
8 votes

Invalid Form Key. Please refresh the page?

If you are running this Magento site on a local machine (local host) as your question seems to indicate, you may have trouble using the: http://localhost/ syntax, as Magento 2 doesn't fully know how ...
Jeff Finkelstein's user avatar
8 votes
Accepted

Magento 2 - change the form fields sort order in checkout

1) XML Layout: We should use <item name="sortOrder" xsi:type="string">20</item> app/code/Vendor/Checkout/view/frontend/layout/checkout_index_index.xml <?xml version="1.0"?> <...
Khoa TruongDinh's user avatar

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