I have added a field using below code, hidden field appeared but value is not showing.

$fieldset->addField('entity_type_id', 'hidden', 
      'name'               => 'entity_type_id',
      'value'              => 11

NOTE : I have tried 'value' instead of 'values' but not working

Can anyone suggest how can I set the field value in Magento 2 admin form.


custom field with field value


NOTE : I got reference from this answer and it is working perfectly fine for me for hidden field as well for text field.


Try This :-

Reference :- vendor/magento/module-sales/Block/Adminhtml/Order/Status/NewStatus/Form.php

Line no. 40

$fieldset->addField('entity_type_id', 'hidden', 
      'name' => 'entity_type_id',
      'value' => 11
  • Hi @RkRathod it's not working. Value is not displaying in inspect element. – Aditya Shah Sep 9 '19 at 11:54
  • +1 for the efforts. – Aditya Shah Sep 9 '19 at 11:54
  • if I add value using inspect element, even tho it is not showing in text field :D – Aditya Shah Sep 9 '19 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.