0

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.

<?php
    class Karaokeshop_Banner_Block_Adminhtml_Banner_Edit_Tab_Image extends Mage_Adminhtml_Block_Widget_Form
    {

        protected function _prepareForm()
        {
            $form = new Varien_Data_Form();
            $this->setForm($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

<?php
    class Karaokeshop_Banner_Block_Adminhtml_Banner_Edit_Tab_Field_Custom extends Varien_Data_Form_Element_Abstract
    {
public function __construct($attributes=array())
{
    parent::__construct($attributes);
}
public function getElementHtml()
{              
    $value = $this->getTitle();
    $onclick=$this->getOnclick();
    $class=$this->getClass();
    $id=$this->getId();
    $style=$this->getStyle();
    $type=$this->getType();
    $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">
                //<![CDATA[

                    var banner =  
                    {                                                       
                            add : function(obj) 
                            {                                    

                            },

                    };
                //]]>
                </script>
            </p>';
    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

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

1 Answer 1

0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.