1

Here's my folder structure for my block:

Product
| - Form.php
Product.php

My product form is a Form Container which is supposed to launch the Form stored within Product -> Form.php

However, although Product.php is loading fine, the Product -> Form.php does not seem to be appearing. I have a simple form setup, with a simple field on there asking for a Product SKU. The Fieldset nor the form it's contained within are loading on the page.

<?php
/**
 * Form for Warehouse Products.
 * Loads individual items that make up the form itself.
 *
 * @author Dan Hanly
 **/
class Company_Module_Block_Adminhtml_Warehouse_Edit_Product_Form extends Mage_Adminhtml_Block_Widget_Form
{
    public $_id;        // Identifier of the block
    public $_title;     // Title of the block
    public $_form;      // Varien_Data_Form

    /**
     * Init class
     */
    public function __construct()
    {
        parent::__construct();

        $this->_id = 'product_form';
        $this->_title = $this->__('Product Information');
    }

    /**
     * Setup form fields for inserts/updates
     *
     * @return Mage_Adminhtml_Block_Widget_Form
     * @author Dan Hanly
     */
    public function _prepareForm()
    {
        $model = Mage::registry('module_warehouse');
        $request = $this->getRequest();

        $this->_form = $this->createForm($this->getUrl('*/*/save', $this->getUrlParameters($request)));
        $this->setForm($this->_form);

        $fieldset = $this->_form->addFieldset('base_fieldset', array(
            'legend' => $this->_title,
            'class' => 'fieldset-wide',
        ));

        if ($this->isEdit($request)) {
            $fieldset->addField('id', 'hidden', array(
                'name' => 'id',
            ));
        }

        $fieldset->addField('warehouse_id', 'hidden', array(
            'name' => 'warehouse_id',
            'value' => Mage::registry('module_warehouse')->getId()
        ));

        $fieldset->addField('product_id', 'text', array(
            'name' => 'product_id',
            'label' => $this->__('Choose Product'),
            'value' => $this->__('Choose Product'),
        ));

        return parent::_prepareForm();
    }

There's nothing relevant in the logs that would allude to this.

EDIT
I clarified my question to strip out parts that were irrelevant.

  • show your layout file ? – Rajeev K Tomy Aug 28 '14 at 16:12
  • I'm not using one. This is all instantiated through code. For reference, every other edit form on the site works as expected, except when trying to load this one. It's something specific about this block. – Dan Hanly Aug 28 '14 at 16:13
  • I think it's something to do with the fact that it's an edit form, effectively within another edit form. – Dan Hanly Aug 28 '14 at 16:13
  • I am not getting your point. A form has tabs. YouR tab working, but form is not working. how? – Rajeev K Tomy Aug 28 '14 at 16:17
  • Within the Product (Edit->Tabs->Product) tab, there is a button to 'Add Products' to the Warehouse. That button launches a modal view which loads the Edit Product block. It's a standard Form Container which in-turn, loads Edit Product Form. I know the Edit Product Block is working, as it's displaying the title etc. However, the Edit Product Form Block isn't displaying at all. – Dan Hanly Aug 29 '14 at 7:01
2

I have resolved the issue.

Essentially, Magento automatically looks for a Form Container's Form within an Edit folder. So as my Form was stored within the Product folder, it wasn't displaying.

There is a class variable in the Mage_Adminhtml_Block_Widget_Form_Container class called $this->_mode. This variable defaults to 'edit' - this alone influences the form container's search for a class in the Edit folder.

Within my form container class, I was able to override the _mode variable, providing 'product' as it's value. Now, everything is connected up as it should be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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