How to set value of checkbox in magento custom module
How do I set the value of a checkbox in a magento custom module? Also, how do I set the name of the checkbox to the value in an array?
Here is the code开发者_开发问答 I use to put the checkbox in a magento module:
$fieldset->addField($entity_id['colorcode'], 'checkbox', array(
'label' => Mage::helper('selectcolorforimage')->__($entity_id['colorcode']),
'name' =>'assign_color_new[]',
'values' =>$entity_id['colorcode']
));
values
(ending with 's') is for a select field: try value (singular)
sorry about that, try this instead:
Assuming $entity
is the object you're working with, after the $fieldset
declaration:
$entity->setData('assign_color_new[]', $entity_id['colorcode']);
Check out Mage_Adminhtml_Block_Customer_Edit_Tab_Account (line 142) to see how the core do it.
Check this code:
$this->addColumn('myname', array(
'type' => 'checkbox',
'name'=> 'myname',
'values' => $this->_getid(),
'align' => 'center',
'index' => 'entity_id'
));
Replace myname with your required field name. Also getid
is your code for dynamic values in this array.
精彩评论