Magento addField doesn't use 'value'

Nate H picture Nate H · Jun 11, 2012 · Viewed 7.5k times · Source

Setting up a custom form. Magento doesn't use the 'value' attribute of addField. Suggestions?

Code:

$form = new Varien_Data_Form(array(
    'id' => 'edit_form',
    'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
    'method' => 'post',
    'enctype' => 'multipart/form-data',
));

$form->setUseContainer(true);
$this->setForm($form);

$fieldset = $form->addFieldset('example_form', array(
     'legend' =>Mage::helper('categoryrules')->__('Example Information')
));

...

$entityType = Mage::getModel('eav/config')->getEntityType('test_category_rule');
$entityTypeId = $entityType->getEntityTypeId();

...

$fieldset->addField('entity_type_id', 'hidden', array(
      'name'               => 'entity_type_id',
      'value'              => $entityTypeId
));

Output:

<input id="entity_type_id" name="entity_type_id" value="" type="hidden">

EDIT:

results of print_r($entityType->debug());

Array ( 
    [entity_type_id] => 11 
    [entity_type_code] => rogue_category_rule 
    [entity_model] => categoryrules/rules 
    [attribute_model] => 
    [entity_table] => categoryrules/rules 
    [value_table_prefix] => 
    [entity_id_field] => 
    [is_data_sharing] => 1 
    [data_sharing_key] => default 
    [default_attribute_set_id] => 0 
    [increment_model] => 
    [increment_per_store] => 0 
    [increment_pad_length] => 8 
    [increment_pad_char] => 0 
    [additional_attribute_table] => 
    [entity_attribute_collection] => 
)

Answer

vikcherniy picture vikcherniy · Jun 12, 2012

Try to write here any constant like:

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

Or:

$fieldset->addField('entity_type_id', 'hidden', array(
      'name'               => 'entity_type_id'
));
$form->setValues($entityType->getData());