0

I created a form in the adminhtml, all other fields are working well (ie., text, select, etc). However, I tried adding a button in the list of fields but it seems it's not picking up the value:

$fieldset->addField('test_button', 'button', array(
            'name'      => 'test_button',
            'value'     => 'Test Me',
            'label'     => 'Click the button to test',
));

Output is just:

<input id="test_button" name="test_button" value="" type="button">

Note that the value is empty, thus button is just a blank button.

7

I got it now, instead of using $form->setValues(), I used $form->addValues() as the former overrides the value of the fields.

4

If we want to show the provided value for the button than we have to change the function _prepareForm() used to load the admin form to use function addValues() instead of setValues().

protected function _prepareForm()
{
    //create form structure
    $this->_form = new Varien_Data_Form();
    $this->setForm($this->_form);
    $this->model = Mage::registry('Namespace_Module');

    $this->_prepareRegularForm();

    //set form values
    $data = Mage::getSingleton('adminhtml/session')->getFormData();

    if ($data) {
        $this->_form->addValues($data);
        Mage::getSingleton('adminhtml/session')->setFormData(null);
    }
    elseif ($this->model) {
        //Using addValues() instead of setValues()
        $this->_form->addValues($this->model->getData());
    }

    return parent::_prepareForm();
}

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.