I'm having problems when trying to get fieldset in existing admin form in observer. I'm getting the form but when I try to get fieldset I'm getting nice error: Fatal error: Call to a member function addField() on a non-object When I add this new field straight to form everything is fine except that it is outside fieldset.
$form = $observer->getBlock()->getForm();
$fieldset = $form->getFieldset('fieldset_id');
$fieldset->addField('some_field', 'text', array(
'name' => 'some_field',
'label' => Mage::helper('cms')->__('Some Field'),
'title' => Mage::helper('cms')->__('Some Field')
)
);
Ok I did it. It was my bad. I took wrong block type. Here is the code:
public function onAdminhtmlBlockHtmlBefore(Varien_Event_Observer $observer)
{
$block = $observer->getBlock();
if (!isset($block)) return;
switch ($block->getType()) {
case 'adminhtml/some_edit_tab_main':
$form = $block->getForm();
$fieldset = $form->getElement('base_fieldset');
$fieldset->addField('some_field', 'text', array(
'name' => 'some_field',
'label' => Mage::helper('cms')->__('Some Field'),
'title' => Mage::helper('cms')->__('Some Field')
)
);
break;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With