0

When I open the edit form in admin, the fields are empty, the data is not loaded from DB. Loading still work.

Files:

Form.php https://pastebin.com/8TJ54KSi

StoreController.php https://pastebin.com/utZ0ydHR

Edit.php https://pastebin.com/WHTCQ03c

Grid.php https://pastebin.com/MrxfYpTc

1 Answer 1

1

Please try the below changes that I have made:

1.) Put below edit function in your store controller

public function editAction()
{
    $id = $this->getRequest()->getParam("store_id");
    $model = Mage::getModel("store/block")->load($id);
    if ($model->getStoreId()) {
        Mage::register("store_block", $model);
        $this->loadLayout();
        $this->_addContent($this->getLayout()->createBlock("store/adminhtml_store_edit"));
        $this->_addLeft($this->getLayout()->createBlock("store/adminhtml_store_edit_tabs"));
        $this->renderLayout();
    } else {
        Mage::getSingleton("adminhtml/session")->addError(Mage::helper("store")->__("Item does not exist."));
        $this->_redirect("*/*/");
    }
}

2.) add below code in Tabs.php within Offline/Store/Block/Adminhtml/Store/Edit/

<?php
class Offline_Store_Block_Adminhtml_Store_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
    public function __construct()
    {
        parent::__construct();
        $this->setId("store_tabs");
        $this->setDestElementId("edit_form");
        $this->setTitle(Mage::helper("store")->__("Item Information"));
    }

    protected function _beforeToHtml()
    {
        $this->addTab("form_section", array(
        "label" => Mage::helper("store")->__("Item Information"),
        "title" => Mage::helper("store")->__("Item Information"),
        "content" => $this->getLayout()->createBlock("store/adminhtml_store_edit_tab_form")->toHtml(),
        ));
        return parent::_beforeToHtml();
    }
}

3.) add below code in Form.php within Offline/Store/Block/Adminhtml/Store/Edit/

<?php
class Offline_Store_Block_Adminhtml_Store_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $form = new Varien_Data_Form(array(
            "id" => "edit_form",
            "action" => $this->getUrl("*/*/save", array("id" => $this->getRequest()->getParam("store_id"))),
            "method" => "post",
            "enctype" =>"multipart/form-data",
        ));
        $form->setUseContainer(true);
        $this->setForm($form);
        return parent::_prepareForm();
    }
}

4.) add below code in Form.php within Offline/Store/Block/Adminhtml/Store/Edit/tab/

<?php
class Offline_Store_Block_Adminhtml_Store_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $form = new Varien_Data_Form();
        $this->setForm($form);
        $fieldset = $form->addFieldset("store_form", array("legend"=>Mage::helper("store")->__("Item information")));
        $fieldset->addField('store_id', 'hidden', array(
            'name'      => 'store_id',
        ));

        $fieldset->addField('name', 'text', array(
            'name'      => 'name',
            'label'     => Mage::helper('store')->__('Name'),
            'title'     => Mage::helper('store')->__('Name'),
            'required'  => true,
        ));

        $fieldset->addField('short_description', 'textarea', array(
            'name'      => 'short_description',
            'label'     => Mage::helper('store')->__('Short description'),
            'title'     => Mage::helper('store')->__('Short description'),
            'style'     => 'height:16em',
            'required'  => true,
        ));

        $fieldset->addField('description', 'textarea', array(
            'name'      => 'description',
            'label'     => Mage::helper('store')->__('Description'),
            'title'     => Mage::helper('store')->__('Description'),
            'style'     => 'height:16em',
            'required'  => true,
        ));

        $fieldset->addField('position', 'text', array(
            'name'      => 'position',
            'label'     => Mage::helper('store')->__('Position'),
            'title'     => Mage::helper('store')->__('Position'),
            'required'  => true,
        ));

        $fieldset->addField('status', 'select', array(
            'label'     => Mage::helper('store')->__('Status'),
            'title'     => Mage::helper('store')->__('Status'),
            'name'      => 'status',
            'required'  => true,
            'options'   => Mage::getModel('store/source_status')->toArray(),
        ));

        $fieldset->addField('country', 'text', array(
            'name'      => 'country',
            'label'     => Mage::helper('store')->__('Country'),
            'title'     => Mage::helper('store')->__('Country'),
            'required'  => true,
        ));

        $fieldset->addField('state_province', 'text', array(
            'name'      => 'state_province',
            'label'     => Mage::helper('store')->__('State/Province'),
            'title'     => Mage::helper('store')->__('State/Province'),
            'required'  => false,
        ));

        $fieldset->addField('city', 'text', array(
            'name'      => 'city',
            'label'     => Mage::helper('store')->__('City'),
            'title'     => Mage::helper('store')->__('City'),
            'required'  => false,
        ));

        $fieldset->addField('street', 'text', array(
            'name'      => 'street',
            'label'     => Mage::helper('store')->__('Street'),
            'title'     => Mage::helper('store')->__('Street'),
            'required'  => false,
        ));

        $fieldset->addField('zip_code', 'text', array(
            'name'      => 'zip_code',
            'label'     => Mage::helper('store')->__('Zip Code'),
            'title'     => Mage::helper('store')->__('Zip Code'),
            'required'  => false,
        ));

        $fieldset->addField('telephone', 'text', array(
            'name'      => 'telephone',
            'label'     => Mage::helper('store')->__('Telephone'),
            'title'     => Mage::helper('store')->__('Telephone'),
            'required'  => false,
        ));

        if (Mage::getSingleton("adminhtml/session")->getStoreBlock()) {
            $form->setValues(Mage::getSingleton("adminhtml/session")->getStoreBlock());
            Mage::getSingleton("adminhtml/session")->setStoreBlock(null);
        }  elseif(Mage::registry("store_block")) {
            $form->setValues(Mage::registry("store_block")->getData());
        }
        return parent::_prepareForm();
    }
}

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.