Create Own Module in Magento – Part – 6 – How to Call my custom form in admin

How to Call my custom form in admin:
Here there is a way to call you custom form in admin section. Here am going to show one button in above the admin grid. This button visible in admin grid section.
Jute\Travelinfo\Block\Travelinfo.php
class Jute_Travelinfo_Block_Adminhtml_Jute_Travelinfo extends Mage_Adminhtml_Block_Widget_Grid_Container
{
   public function __construct()
   {
       $this->_blockGroup = ‘jute_travelinfo’;
       $this->_controller = ‘adminhtml_jute_travelinfo’;
       $this->_headerText = Mage::helper(‘jute_travelinfo’)->__(‘Jute Travelinfo’);
                        $data = array(
               ‘label’ => ‘Import Travelinfo Code’,
               ‘onclick’   => “setLocation(‘”.$this->getUrl(‘*/*/import’).”‘)”
               );
                        $this->addButton (‘Import Travelinfo Code’, $data, 0, 100, ‘header’, ‘header’);
        parent::__construct();
       $this->_removeButton(‘add’);
   }
}
 When admin onclick on this button the page redirect to another one page, there my custom form will be visible. We have to mention the this block from my controller
class Jute_Travelinfo_Adminhtml_TravelinfoController extends Mage_Adminhtml_Controller_Action
{
            public function importAction(){
                        $this->loadLayout();
       $this->_addContent($this->getLayout()->createBlock(‘jute_travelinfo/travelinfo’));
                        $this->renderLayout();
            }
}
 
Jute\Travelinfo\Block\Travelinfo.php
class Jute_Travelinfo_Block_Travelinfo extends Mage_Adminhtml_Block_Template
{
            public function _construct() {    
       parent::_construct();
       $this->setTemplate(‘travelinfo/travelinfoimport.phtml’);    
   }
            public function getButtonHtml()
   {
       $button = $this->getLayout()->createBlock(‘adminhtml/widget_button’)
            ->setData(array(
               ‘id’       => ‘travelinfoimport_button’,
               ‘name’       => ‘travelinfoimport_button’,
               ‘label’     => $this->helper(‘adminhtml’)->__(‘Import Code’),
               ‘onclick’   => “setLocation(‘”.$this->getUrl(‘*/*/importpost’).”‘)”
           ));
       return $button->toHtml();
   }
}
Above file am declare my form file . Also i have mention my form action. Once form submit where should go the controller
 app\design\adminhtml\default\jute\template\travelinfo\travelinfo.phtml
<div class=”content-header”>
   <table cellspacing=”0″>
       <tr>
           <td><h3 class=”icon-head head-tax-rate-importExport”><?php echo Mage::helper(‘jute_travelinfo’)->__(‘Travelinfo detail’) ?></h3></td>
       </tr>
   </table>
</div>
<div class=”entry-edit”>
   <div class=”box-left”>
       <form id=”import_form” action=”<?php echo $this->getUrl(‘*/*/importPost’) ?>” method=”post” enctype=”multipart/form-data”>
            <?php echo $this->getBlockHtml(‘formkey’)?>
           <div class=”entry-edit-head”>
               <h4 class=”icon-head head-edit-form fieldset-legend”><?php echo Mage::helper(‘jute_travelinfo’)->__(‘Import Travelinfo’) ?></h4>
           </div>
           <fieldset>
               <legend><?php echo Mage::helper(‘jute_travelinfo’)->__(‘Import Travelinfo’) ?></legend>
               <input type=”text” name=”travelinfo_name” class=”input-file required-entry”/>
               <input type=”text” name=”travelinfo_package” class=”input-file required-entry”/>
               <input type=”text” name=”place_to_visit” class=”input-file required-entry”/>
                                                <input type=”submit” value=”Import Travelinfocode” name=”import_travelinfo” id=”import_travelinfo” />
           </fieldset>
       </form>
       <script type=”text/javascript”>
           var importForm = new varienForm(‘import_form’);
       </script>
   </div>
   <div class=”clear”></div>
</div>
Yes now your form is ready to submit. Once the form is submitted then form redirect to your importpost action from the controller

………………………………………………………………………………………………………………………………………………………………………

Corner of Blog:

“save power save future”

………………………………………………………………………………………………………………………………………………………………………