Hot answers tagged

56

You need to create a new extension to make it clean. Let's call the extension StackExchange_Customer. You will need the following files: app/etc/modules/StackExchange_Customer.xml - the declaration file <?xml version="1.0"?> <config> <modules> <StackExchange_Customer> <active>true</active> ...


51

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 HTML form template POST request wich going to send form data to Action Controller Class. <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http:/...


42

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') ?></...


35

You can achieve this using following tag. <item name="notice" xsi:type="string" translate="true">Some note here</item>


33

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 php.ini (Open for edit and set max_input_vars=10000) :wq(Press esc and write the mentioned command to save and exit) sudo /etc/init.d/apache2 restart(Restart ...


25

Your button contains onclick="document.location.href='http://www.labwise.in/devel/vaccination-details';". This means that when clicking on it, you will get redirected to http://www.labwise.in/devel/vaccination-details. If you want to submit the form at a specific page you have to wrap your form and button in a <form> tag. <form action="your url ...


24

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

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:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Vendor_ModuleName" setup_version="2.0.0" /> </config> app/code/...


21

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 node sequence (VendorName/ModuleName/etc/module.xml): <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&...


18

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=...


18

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: {required:true} With: {required:true, 'validate-length':true} Also you'll have to ensure that your custom form is validated via JavaScript with one of the ...


18

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 does not require performing modifications in the Magento 2 core modules. In order to achieve your goal and wrap checkout shipping address fields into a custom ...


18

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 toggle. <field name="status"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="...


17

Probably nothing because the form key is random, so it has to be different each time. So it should not make a difference, but the best practice, how you should add the form key input to your template, is this: <?php echo $this->getBlockHtml('formkey') ?> Update: I have to admit, I was wrong in one point: The form key stays the same during a ...


17

Try following way: protected $formKeyValidator; public function __construct ( \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator ) { $this->formKeyValidator = $formKeyValidator; } And then if (!$this->formKeyValidator->validate($this->getRequest())) { // invalid request }


16

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="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> <fieldset name="customer"> <field name="is_institution" formElement="input"> ...


15

In php this type of work implement on session variable. Magento is doing by set success message using ->addSuccess('YOUR MSG');. and set error message using ->addError('YOUR ERROR MSG') Those magento functions are Object of Mage::getSingleton('core/session') Mage::getSingleton('customer/session') Mage::getSingleton('catalog/session') So ...


15

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 with JavaScript to the Customer Register and the Product Review Form which looks like the URL Field of a Wordpress Comment Form. If this field gets filled and ...


14

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="additionalClasses" xsi:type="array"> <item name="my-custom-class" xsi:type="boolean">true</item> </item>


13

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\DataProvider</argument> pass array like below. $categoryData['image'][0]['name'] = $category->getData('image'); $categoryData['...


12

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\...


11

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 path LIKE '%cookie_domain%'; You can change the value in mysql directly as well. Don't forget to clear the cache afterwards.


10

Try this solution: $fieldset->addField( 'test', 'select', [ 'label' => __('Test'), 'name' => 'test', 'required' => true, 'values' => [ [ 'label' => 'optgroup 1', 'value' => [ [ 'label' => 'in opt group 1-...


10

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.ini file. If php version 7.1 then, /etc/php/7.1/apache2/php.ini If php version 7.0 then, /etc/php/7.0/apache2/php.ini If php version 7.2 then, /etc/php/7.2/...


10

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">test_form.test_form_data_source</item> Change above lines as per below <item name="provider" si:type="string">hello_world_edit.test_form_data_source</...


9

You can specify a frontend model to your field like this: <field_name translate="label"> <label>Field name</label> <frontend_type>select</frontend_type> <frontend_model>module/field_name_renderer</frontend_model><!-- this is it --> <source_model>adminhtml/system_config_source_yesno</...


9

Try following way: $fieldset->addField( 'time', 'date', [ 'name' => 'time', 'label' => __('Time'), 'date_format' => 'yyyy-MM-dd', 'time_format' => 'hh:mm:ss' ] );


9

Here I got the solution: <div class="control customer-dob"> <input type="text" class="input-text required-entry hasDatepicker" id="calendar_inputField" name="dob" aria-required="true" /> <script> require([ "jquery", "mage/calendar" ], function ($)...


9

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 adminhtml_customer adminhtml_customer_address checkout_register customer_account_create customer_account_edit customer_address_edit ...


9

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 Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Framework\DB\Ddl\Table; class InstallSchema ...


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