Beginners guide to Admin Forms.
If you are a beginner in Magento, and just start exploring how you can create your own extension, you may encounter following problem – how to set default value for the field in a form.
Mainly, this topic covers issues related with “select” and “checkbox” field types.
So, just use the following snippet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | //Lets make field Status, that will show/hide our content on Frontend $fieldset->addField('status', 'select', array( 'label' => Mage::helper('carousel')->__('Status'), 'name' => 'status', 'values' => array( array( 'value' => '1', //Here you specify some value 'label' => Mage::helper('carousel')->__('Active'),//Here comes the label ), array( 'value' => '0', 'label' => Mage::helper('carousel')->__('Inactive'), ), ), 'value' => 1 //Specify default value here )); |
You can also use this sql upgrade snippet to upgrade your existing database:
1 2 3 4 5 6 7 8 | <php $installer = $this; /* @var installer Mage_Core_Model_Resource_Setup */ $installer->startSetup(); $installer->run(" ALTER TABLE {$installer->getTable('your_table')} MODIFY COLUMN status smallint(6) NOT NULL default '1'; "); $installer->endSetup(); |
Hope that helped you on first steps learning Magento!