2

I am working on custom module. I want to set default value to text field but failed. I have visited some links for solution but didnt working. Link1 and Link2

$this->setForm($form);
$fieldset = $form->addFieldset('home_form', array('legend'=>Mage::helper('home')->__('Section Information')));
$fieldset->addField('section_name', 'text', array(
      'label'     => Mage::helper('home')->__('Section Name'),
      'required'  => false,
      'name'      => 'section_name',
      'value' => 'asdf',
));
YKJ
  • 387
  • 7
  • 16

2 Answers2

2

I assume that somewhere in the code you call $form->setValues($somethingHere).
Replace that line with:

$form->addValues(array('section_name'=> 'asdf'));
$form->addValues($somethingHere);
Marius
  • 197,939
  • 53
  • 422
  • 830
2

You should use default attribute for this. Like,

$this->setForm($form);
$fieldset = $form->addFieldset('home_form', array('legend'=>Mage::helper('home')->__('Section Information')));
$fieldset->addField('section_name', 'text', array(
      'label'     => Mage::helper('home')->__('Section Name'),
      'required'  => false,
      'name'      => 'section_name',
      "default" => "asdf"
));
Elavarasan
  • 888
  • 1
  • 11
  • 27