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/...
  • 34.6k
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"> ...
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 \...
  • 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 ...
  • 1,307
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 = ...
  • 5,081
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\...
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/...
  • 3,738
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');
  • 196k
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' => ...
13 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 ...
12 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 ...
  • 5,916
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"> ...
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'] ; ...
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\...
  • 34.6k
10 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();
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
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->...
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( ...
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'...
  • 16.7k
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 ...
  • 660
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 ...
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 ...
  • 682
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 ...
  • 196k
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
  • 20.4k
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. * * @...
  • 34.6k
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 ...
  • 6,239
8 votes
Accepted

Magento 2 ui component form without database table

For this, Your Data Provider should be like <dataSource name="coupon_email_data_source"> <argument name="dataProvider" xsi:type="configurableObject"> <argument name=...
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', ...
  • 6,239
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"> ...
7 votes

Show thumbnail image and delete image in custom module admin form

Add 'enctype'’ ⇒ 'multipart/form-data' That should help to get something in $_FILES in /app/code/local/Chilly/ModName/Block/Adminhtml/ModName/Edit/Form.php You should have something looking like ...

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