Magento: How to add checkbox field in Admin custom module form and populate the checkbox
How to add Checkbox field in Form:
Open app/code/local/Namespace/CustomModuleName/Block/Adminhtml/ CustomModuleName /Edit/Tab/Form.php and add the below code.
$fieldset->addField('checkbox_name', 'checkbox', array(
'name' => ' checkbox_name ',
'onclick' => 'this.value = this.checked ? 1 : 0;',
'tabindex' => 1
));
How to re-populate the checkbox on Edit page:
Just add the extra line in ablove code like below:
$fieldset->addField('checkbox_name', 'checkbox', array(
'name' => ' checkbox_name ',
'onclick' => 'this.value = this.checked ? 1 : 0;',
'tabindex' => 1
))->setIsChecked($model->getCheckboxName());
Thanks, Done...
=========================================================================
Open app/code/local/Namespace/CustomModuleName/Block/Adminhtml/ CustomModuleName /Edit/Tab/Form.php and add the below code.
$fieldset->addField('checkbox_name', 'checkbox', array(
'name' => ' checkbox_name ',
'onclick' => 'this.value = this.checked ? 1 : 0;',
'tabindex' => 1
));
How to re-populate the checkbox on Edit page:
Just add the extra line in ablove code like below:
$fieldset->addField('checkbox_name', 'checkbox', array(
'name' => ' checkbox_name ',
'onclick' => 'this.value = this.checked ? 1 : 0;',
'tabindex' => 1
))->setIsChecked($model->getCheckboxName());
Thanks, Done...
=========================================================================
Magento: How to add checkbox field in Admin custom module form and populate the checkbox
Reviewed by Web Technology Funda
on
3:34:00 AM
Rating:
What is the $model variable? You haven't defined it in your code sample.
ReplyDeleteSorry for delay ...
DeletePlease see the below example to understand the $model object.
Example:
$model = Mage::getModel('module/model_name')->load($edt_id);
Here in $model object we are loading the data to edit the content with respect to the ID from DB.
And $model->getCheckboxName();// getting the checkbox field value from db
The 'CheckboxName' is the field name of checkbox which is going to return the checkbox field value (i.e true or flase).
Do, let me know if you have further queries.
Thanks,