I have a custom module 'banner' and in which I have added a button in its second tab(only two tabs for the module). when click on that button, it is submitting my banner automatically and then go to the grid page(i e it acts as just another save button). But the function of this button is to add an uploading image field.ie whenever the button is clicked, it should add an image form field to my tab file. This is my tab file.

    class Karaokeshop_Banner_Block_Adminhtml_Banner_Edit_Tab_Image extends Mage_Adminhtml_Block_Widget_Form

        protected function _prepareForm()
            $form = new Varien_Data_Form();
            $fieldset = $form->addFieldset('banner_image', array('legend'=>Mage::helper('banner')->__('Banner Image')));
            //declaring a new custom form field and adding
            $fieldset->addType('add_button', 'Karaokeshop_Banner_Block_Adminhtml_Banner_Edit_Tab_Field_Custom'); 
            $fieldset->addField('banner_img_add_button', 'add_button', array(
                'title' => Mage::helper('banner')->__('Add Banner Image'),
                'id' => 'add_banner_img_button',
                'class' => 'scalable save',
                'style' => '',
                'onclick' => 'banner.add(this)',
                'type' => 'button',                    

             return parent::_prepareForm();                                                    


this is my button defining file

    class Karaokeshop_Banner_Block_Adminhtml_Banner_Edit_Tab_Field_Custom extends Varien_Data_Form_Element_Abstract
public function __construct($attributes=array())
public function getElementHtml()
    $value = $this->getTitle();
    $html='<button id="'.$id.'" class="'.$class.'" style="'.$style.'" onclick="'.$onclick.'" type="'.$type.'" title="'.$value.'">'.$value.' </button>';
    $html .= '<p id="' . $this->getHtmlId() . '"'. $this->serialize($this->getHtmlAttributes()) .'>
                <script type="text/javascript">

                    var banner =  
                            add : function(obj) 


    return $html;

what should i do to change my button to an add button? what should I do to avoid this submitting functionality of the button. Please help me. Thanks in advance

  • Did you check the value of $onclick?
    – Sukeshini
    Commented Dec 30, 2013 at 6:36

1 Answer 1


I got the answer for this. That was a small javascript error. I just need to add retun false; in my banner.add() function. It will prevent submitting the form and hence stay in the same page

  • @DavidManners : your suggestion accepted !! Commented May 20, 2014 at 12:52

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.