Magento add hidden field in admin form field

Hi Friend's

Add hidden field in admin form field and get value in controller. first add hidden field in form.php file

$form->addField('created_date', 'hidden',
array(
'name'      => 'created_date',
'label'     => 'created_date',
'class'     => 'required-entry',
'required'  => true,
'readonly'  => true,
));

Get hidden field value in controller file

$this->getRequest()->getPost('created_date');

2 comments:

  1. Hi vithal, how do we set value for the hidden field?

    ReplyDelete
    Replies
    1. Hi Tùng Đào,

      You can put this code 'value' => 'Your value here'
      For Ex.

      $form->addField('created_date', 'hidden',
      array(
      'name' => 'created_date',
      'label' => 'created_date',
      'class' => 'required-entry',
      'required' => true,
      'readonly' => true,
      'value' => 'Your value here'
      ));

      Delete