Magento: How to get magento fieldset from existing form in admin within observer
magento, magento-1.7
Solution
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;
}
}
Problem
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') ) ); ```