I have a block that extends Mage_Adminhtml_Block_Widget_Form_Container.

I also have two blocks of type core/template that use template files that I'd like to include within my main form.

Is it possible to add these templates as children of the form and render them after everything else?

I'm trying to prevent having to write a bunch of html when I can use the blocks form building functions.

Here's my layout section:

    <reference name="head">
        <action method="addJs"><file>darkhorse/simplemde/simplemde.min.js</file></action>
        <action method="addCss"><file>darkhorse/onsite/simplemde/simplemde.min.css</file></action>
    <reference name="content">
        <block type="onsite/adminhtml_purchaseOrder_edit">
            <block type="core/template" template="darkhorse/purchaseOrder/items.phtml" name="purchaseOrder_items" as="purchaseOrder_items" />
            <block type="core/template" template="darkhorse/purchaseOrder/notes.phtml" name="purchaseOrder_notes" as="purchaseOrder_notes" />


class Darkhorse_Onsite_Block_Adminhtml_PurchaseOrder_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
    public function __construct()
        $this->_objectId = 'id';
        $this->_controller = 'adminhtml_purchaseOrder';
        $this->_blockGroup = 'onsite';
        $this->_updateButton('save', 'label', Mage::helper('onsite')->__('Save Purchase Order'));

        $this->_formScripts[] = '
            function saveAndContinueEdit(){

     * Retrieve text for header element depending on loaded page
     * @return string
    public function getHeaderText()
         if (Mage::registry('current_purchaseOrder')->getId()) {
            return $this->escapeHtml(Mage::registry('current_purchaseOrder')->getName());
        } else {
            return Mage::helper('onsite')->__('New PurchaseOrder');

     * Prepare layout
     * @return Mage_Core_Block_Abstract
    protected function _prepareLayout()
        $this->_addButton('save_and_continue', array(
            'label'     => Mage::helper('onsite')->__('Save and Continue Edit'),
            'onclick'   => 'saveAndContinueEdit(\''.$this->_getSaveAndContinueUrl().'\')',
            'class'     => 'save'
        ), 10);

        return parent::_prepareLayout();

    protected function _getSaveAndContinueUrl()
        return $this->getUrl('*/*/save', array(
            '_current'  => true,
            'back'      => 'edit',
            'tab'       => '{{tab_id}}',
            'active_tab'=> null,

1 Answer 1


Finally... I've come up with a solution and so far it seems to work fairly well.

What I did was changed setUseContainer(true) to setUseContainer(false).

Doing that allowed me to remove the <form> tags. Now I on the form block I can override the function _toHtml()

Here's that function now:

protected function _toHtml()
    $html = '<form ' . $this->_form->serialize($this->_form->getHtmlAttributes()) . '>';
    $html .= '<div>';
    if (strtolower($this->_form->getData('method')) == 'post') {
        $html .= '<input name="form_key" type="hidden" value="'.Mage::getSingleton('core/session')->getFormKey().'" />';
    $html .= '</div>';
    return $html.parent::_toHtml().$this->getChildHtml('items').'</form>';

As you can see I added a protected variable named $_form. This variable is set to the form that I created in _prepareForm().

I'm not sure if this is the best way to do this, but for me it works fantastically. It allows me to insert templates straight into a single page admin form.

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.