5

I have added a field as per Magento standard structure, hidden field appeared but value is not showing.

$fieldset->addField('entity_type_id', 'hidden', 
 array(
 '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.

asked Sep 9, 2019 at 10:12

2 Answers 2

2
$this->setForm($form);

custom field with field value

$data=array('entity_type_id'=>11); 
$form->setValues($data);

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

answered Sep 10, 2019 at 5:59
1

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
 ]);
answered Sep 9, 2019 at 11:09
4
  • 1
    Hi @RkRathod it's not working. Value is not displaying in inspect element. Commented Sep 9, 2019 at 11:54
  • if I add value using inspect element, even tho it is not showing in text field :D Commented Sep 9, 2019 at 11:55
  • @AdityaShah have you got solution? Commented Sep 13, 2021 at 13:57
  • magento.stackexchange.com/a/288169/63138 Commented Sep 16, 2021 at 7:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.