How to call custom form in magento admin section

How to call custom form in magento admin section:

We can call our customer form in magento admin section by

1. Call html file as template

2. Call html file from your xml/controller file

First How to call our Controller by as Template::

$this->getUrl(‘mymodule/adminhtml_editform/index’);

Here mymodule is my own module, adminhtml_editform in an my admin controller

index is on my action

1. Call html file as template

Step:1

Create Admin controller

app\code\local\Jute\mymodule\controllers\Adminhtml\EditformController.php

class Jute_MyModule_Adminhtml_EditformController extends Mage_Adminhtml_Controller_Action

{

          public function indexAction()

    {

             $this->loadLayout();

             $this->_title($this->__(“Edit Form”));

             $this->_addContent($this->getLayout()->createBlock(‘mymodule/adminhtml_myblock’))

                ->_addLeft($this->getLayout()->createBlock());

             $this->renderLayout();

    }

}

Step:2

Load into xml file add below code into your xml file

<admin>

        <routers>

            <adminhtml>

                <args>

                    <modules>

                        <jute_mymodule before=”Mage_Adminhtml”>Jute_MyModule_Adminhtml_Editform</jute_mymodule>

                    </modules>

                </args>

            </adminhtml>

        </routers>

    </admin>

Path:: app\code\local\Jute\MyModule\etc\config.xml

Step:3

Create Block file (adminhtml_myblock)

app\code\local\Jute\MyModule\Block\Adminhtml\myblock.php

class Jute_MyModule_Block_Adminhtml_Myblock extends Mage_Adminhtml_Block_Template

{

          public function __construct() {

                   parent::__construct();

                   $this->setTemplate(‘mymodule/edit_form.phtml’);

                   //$this->setFormAction(Mage::getUrl(‘*/*/post’));  // If you want we can set the .html form action here

          }

}

Step:4

Create html form

app\design\adminhtml\default\jute\template\mymodule\edit_form.phtml

That’s it clear cache and check it from admin. Your form will display. If your are getting any 404 Page issue then try to set ACL for that module. Then cleare cache, logout admin. Again login and check.

 

2. Call html file from your xml/controller file

app\design\adminhtml\default\jute\layout\mymodule.xml

XML base

<?xml version=”1.0″?>

<layout version=”0.1.0″>

            <mymodule_adminhtml_editform_index>

                   <reference name=”content”>

                     <block type=”mymodule/adminhtml_myblock” name=”adminhtml_myblock” template=”mymodule/edit_form.phtml”/>

                   </reference>

            </mymodule_adminhtml_editform_index>

</layout>

Here,<mymodule_adminhtml_editform_index>

mymodule is your -> Module like Jute

adminhtml_editform -> is editformController file which one is located inside the controller/adminhtml folder

index -> is an your Action of the controller.

Leave a Reply