2022 Developer Survey is open! Take survey.
33 votes
Accepted

Magento 2 Add new field to Magento_User admin form

For adding image field, you can try using plugin and always try to avoid overwrite whole class. Vendor/Module/etc/adminhtml/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/...
user avatar
  • 34.1k
26 votes
Accepted

How to make a form field readonly using ui-components?

Try to add the disabled parameter to the element like this: <field name="is_active"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> ...
user avatar
17 votes
Accepted

Add WYSIWYG Editor to Block Form in Magento 2

Discovered I was missing the Config setting: /** * @var \Magento\Cms\Model\Wysiwyg\Config */ protected $_wysiwygConfig; /** * @param \Magento\Backend\Block\Template\Context $context * @param \...
user avatar
  • 823
16 votes
Accepted

Magento 2: how to delete image or file

Very important question as in my experience, when submitting an extension for marketplace, the validation generated errors regarding using of such method directly. I've researched and found following ...
user avatar
  • 1,297
14 votes
Accepted

How to use custom html element in admin form field?

Renderer file: class NameSpace]_[ModuleName]_Block_Adminhtml_Review_Renderer_Images extends Varien_Data_Form_Element_Abstract { public function getElementHtml() { $html = ...
user avatar
  • 5,041
14 votes
Accepted

How to get all list of customer group?

I was able to get solution using the below code: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $groupOptions = $objectManager->get('\Magento\Customer\Model\ResourceModel\...
user avatar
14 votes

Magento Add Condition Rule In A Custom Form in magento 2

To add a conditional field to the default model (and further utilize it for validating purposes), you will need to create a new model (or modify the existing one) that contains these fields. app/...
user avatar
  • 3,718
13 votes
Accepted

How to remove save and reset button from edit form?

Add this in the method you mentioned $this->_removeButton('save'); $this->_removeButton('delete'); $this->_removeButton('reset');
user avatar
  • 195k
13 votes
Accepted

$_File array empty in Magento 2 while Uploading file at admin form

It was my bad !! I forgot to add enctype'=>'multipart/form-data You have to add following code while creating formFactory $form = $this->_formFactory->create( ['data' => ...
user avatar
12 votes
Accepted

How to set the default value of "Is Active" to "yes" on a new category

I would advise never editing core code as it will create issues for you down the road. This is a database change. 0 comes before 1 and no default value is set for that attribute so 0 will always be ...
user avatar
  • 3,363
12 votes
Accepted

Magento 2: How to submit custom html content from ui_form to controller?

In your block create protected $_template = 'Company_Module::labelposition.phtml'; now, make labelposition.phtml and add your html field with attribute data-form-part="formname". Here the formname ...
user avatar
11 votes
Accepted

Field comments in ui_component form

You should use notice: <item name="notice" xsi:type="string" translate="true"> Full example: <field name="name"> <argument name="data" xsi:type="array"> ...
user avatar
11 votes
Accepted

Magento 2.2.6 How to add TAB structure in admin UI component form

I found my problem, i used argument item <item name="template" xsi:type="string">templates/form/collapsible</item> it is used to display for collapsible structure. After remove this line ...
user avatar
  • 5,848
10 votes
Accepted

Show thumbnail image and delete image in custom module admin form

Add the code in your controller file public function saveAction() { ... if (!empty( $_FILES['main_image']['name'] )) { $data['main_image'] = $_FILES['main_image']['name'] ; ...
user avatar
10 votes

Magento 2:Store View in Ui Component Form

Add following code into your ui_component form <field name="storeviews"> <argument name="data" xsi:type="array"> <item name="options" xsi:type="object">Magento\Cms\Ui\Component\...
user avatar
  • 34.1k
9 votes

How to get all list of customer group?

You can use the following class: Magento\Customer\Model\Customer\Source\Group. It provides a toOptionArray method that you can use to get an array of customer groups
user avatar
9 votes
Accepted

Magento 2 : Could not save admin form contents into the DB

Add the following code in your execute function of Save Controller (Module/Controller/Adminhtml/Example/Save.php) public function execute() { $resultRedirect = $this->...
user avatar
9 votes
Accepted

How to add a color picker field in Admin form?

Never mind guys, I resolved the problem. Step 1: app/code/Vendor/Module/Block/Adminhtml/Module/Edit/Tab/Main.php //Replace your db field name with "color" $field = $fieldset->addField( ...
user avatar
9 votes
Accepted

Input type number in admin edit form Magento 2

Try this code :- $fieldset->addField( 'sorting_order', 'text', array( 'name' => 'sorting_order', 'label' => __('Sort Order'...
user avatar
  • 16.5k
9 votes
Accepted

Magento 2 How to set value to UI component hidden field using Jquery or Javascript

You need to use change() function after val() called. When you used val() of jquery in knockout context at that time you need to use below syntax, $('input[name="image_data"]').val(Data).change();
user avatar
9 votes

Magento 2.3.0 While edit UI component form data not filled up in custom module

If you use setting tags in ui-component. You need to add data return include fieldset. Example field "priority" will show "name='general['priority']' " Your loadedData in function getData() should ...
user avatar
  • 650
8 votes
Accepted

Start and End Date Validation

Try using Magento's validator's validate-date-range class on your fields. If you add this to both fields then it will get the to date and compare the two values. If get the to date value using the ...
user avatar
8 votes
Accepted

Admin form save date format, month and day wrong way around

Found the problem, was missing a step in my controller. $postData = $this->getRequest()->getPost(); $postData = $this->_filterDates($postData, array("date")); After using _filterDates it ...
user avatar
  • 662
8 votes
Accepted

Magento Admin Form Post Data Missing

On your latest screenshot I see that the fields you are submitting don't have a name. Look at the input with the id product_id for example. the name attribute is empty. I think the problem comes ...
user avatar
  • 195k
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
user avatar
  • 20.1k
8 votes
Accepted

Magento 2: How add dropdown in admin form?

Change Category class by following code: namespace Book\Flip\Model\Source; class Category implements \Magento\Framework\Option\ArrayInterface { /** * Retrieve options array. * * @...
user avatar
  • 34.1k
8 votes
Accepted

How to create and add Backend form to Custom admin grid in magento 2

If you just need to create an admin form, have a look at here. https://www.pierrefay.com/magento2-training/form-component-backend-crud-admin.html To create our Form, we will first create the ...
user avatar
  • 6,159
8 votes
Accepted

How to set default text field value in form Magento 2

Try this $fieldset->addField( 'customer_id', 'text', [ 'label' => __('Customer Id'), 'title' => __('Customer Id'), 'name' => 'customer_id', ...
user avatar
  • 6,159
8 votes
Accepted

Magento2 admin grid ui component form hide multiple fields based on php condition

Override getMeta function in your dataprovider and set value like this. my form.xml <fieldset name="fieldset_name"> <field name="attribute_id"> ...
user avatar
7 votes
Accepted

Admin form field button

It should work with value: $fieldset->addField('register', 'button', array( 'value' => Mage::helper('module')->__('Button Caption'), 'onclick' => 'test()' )); Just make sure ...
user avatar
  • 195k

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