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.

Fabian Schmengler
66.2k25 gold badges191 silver badges422 bronze badges
asked Mar 27, 2015 at 2:11

2 Answers 2

7

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

answered Mar 27, 2015 at 2:27
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();
}
answered Oct 20, 2017 at 7:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.