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',
));
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);
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"
));
1
  • default attribute didn't work in my case. – YKJ Oct 22 '14 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.