Passing post data back to form
1. Add the following to the file: Vendorname/Modulename/controllers/Adminhtml/Modulename/IndexController.php
<?php ... public function saveAction() { if ( $this->getRequest()->getPost() ) { try { $postData = $this->getRequest()->getPost(); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::getSingleton('adminhtml/session')->setFormData($postData); $this->_redirect('*/*/edit'); return; } ... |
2. Add this parts of code to IndexController.php as well
<?php ... public function editAction() { if ($data = Mage::getSingleton('adminhtml/session')->getFormData()) { Mage::register('modulename_data', $modulename->addData($data)); Mage::getSingleton('adminhtml/session')->setFormData(null); } $this->loadLayout(); $this->renderLayout(); } |
3. Then add the following to this file: Vendorname/Modulename/Block/Adminhtml/Modulename/Form.php
<?php ... protected function _prepareForm() { $form = new Varien_Data_Form(); $vendor = Mage::registry('modulename_data'); $formValues = $vendor->getData(); $form->setValues($formValues); return parent::_prepareForm(); } |