For Magento (1.9) how to set the value to the Magento form.

  $fieldset->addField('country_code', 'text', array(
          'label'     => Mage::helper('catalog')->__('Title3'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'country_code',
          'style'   => "border:10px",
          'value'  => 'hello !!',
          'disabled' => false,
          'readonly' => true,

I set the value is hello !! but it is not working.

enter image description here

  • try this $data['{field_name}'] = 'your_value';
    – Sathish
    Jul 17, 2015 at 7:31

1 Answer 1


Your problem is that values you set with addField() method are then overwritten with addValues() method which tries to set up a form fields values when form is used for editing existing entities or error occurred during submission.

Here is a workaround. Most likely you are getting values with a protected method like this:

protected function _getFormData()
    $data = Mage::getSingleton('adminhtml/session')->getFormData();

    if (!$data && Mage::registry('current_osmm_project')->getData()) {
        $data = Mage::registry('current_osmm_project')->getData();

    return (array) $data;

So inside of your _prepareForm() method you replace:



$_data = $this->__getFormData();
if (!empty($_data)) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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