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 ...
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:
<...
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>
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 ...
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 ...
23
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:...
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 ...
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;...
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(); ...
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:
...
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 ...
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 ...
17
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="...
15
votes
How to secure form from spam bot
I had the same problem and I solved it by installing this extension from the magento-hackaton: https://github.com/magento-hackathon/HoneySpam
This Magento Extension adds a field which is hidden ...
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-...
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=...
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\...
12
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
...
11
votes
Accepted
Invalid Form Key. Please refresh the page. error on product save
There is one more source for this error: a wrong cookie_domain in the configuration. As you can't login into the admin area, you can check it directly via mysql:
SELECT * FROM core_config_data WHERE ...
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....
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">...
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' => [
...
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 ...
9
votes
Accepted
Magento 2 backend form date time form field
Try following way:
$fieldset->addField(
'time',
'date',
[
'name' => 'time',
'label' => __('Time'),
'date_format' => ...
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"
...
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
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="...
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 ...
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 ...
8
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
forms × 707magento2 × 255
magento-1.9 × 144
admin × 68
adminhtml × 58
checkout × 48
adminform × 47
uicomponent × 46
database × 31
magento-2.1 × 29
magento-1.7 × 29
javascript × 29
form-validation × 29
controllers × 28
contact-us × 27
customer × 25
magento-1.8 × 24
grid × 24
module × 22
validation × 22
magento-1 × 19
contact-form × 19
magento2.2 × 18
php × 17
email × 17