I have created custom module with form in admin side. In a form, I have created two fieldset:
$fieldset = $form->addFieldset('base_fieldset', array(
'legend' => Mage::helper('checkout')->__('Baz Information'),
'class' => 'fieldset-wide',
));
$fieldsetdate = $form->addFieldset('date', array(
'legend' => Mage::helper('checkout')->__('Date Range'),
'class' => 'fieldset-date',
));
$fieldset's attribute values are stored in my DB table. But $fieldsetdate's attribute values are not saved. I dunno how to manage different fieldset attributes in a single form. Do I need to use two different custom table?
EDIT
// Bazcontroller.php
<?php
class Foo_Bar_Adminhtml_BazController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
// Let's call our initAction method which will set some basic params for each action
$this->_initAction()
->renderLayout();
}
public function newAction()
{
// We just forward the new action to a blank edit form
$this->_forward('edit');
}
public function editAction()
{
$this->_initAction();
// Get id if available
$id = $this->getRequest()->getParam('id');
$model = Mage::getModel('foo_bar/baz');
if ($id) {
// Load record
$model->load($id);
// Check if record is loaded
if (!$model->getId()) {
Mage::getSingleton('adminhtml/session')->addError($this->__('This baz no longer exists.'));
$this->_redirect('*/*/');
return;
}
}
$this->_title($model->getId() ? $model->getName() : $this->__('New Baz'));
$data = Mage::getSingleton('adminhtml/session')->getBazData(true);
if (!empty($data)) {
$model->setData($data);
}
Mage::register('foo_bar', $model);
$this->_initAction()
->_addBreadcrumb($id ? $this->__('Edit Baz') : $this->__('New Baz'), $id ? $this->__('Edit Baz') : $this->__('New Baz'))
->_addContent($this->getLayout()->createBlock('foo_bar/adminhtml_baz_edit')->setData('action', $this->getUrl('*/*/save')))
->_addLeft($this->getLayout()->createBlock('foo_bar/adminhtml_baz_edit_tabs'))
->renderLayout();
}
public function saveAction()
{
Zend_Debug::debug($this->getRequest()->getPost());
if ($postData = $this->getRequest()->getPost()) {
/// ---START code for save image attribute----
if($_FILES['fileinputname']['name'] != '') {
try {
$uploader = new Varien_File_Uploader('fileinputname');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media').'/foo/';
// move_uploaded_file( $_FILES['userFile']['tmp_name'], $path);
$uploader->save($path, $_FILES['fileinputname']['name']);
}
catch (Exception $e) {
echo 'Error Message: '.$e->getMessage();
}
}
if($_FILES['fileinputname1']['name'] != ''){
try {
$uploader_cat = new Varien_File_Uploader('fileinputname1');
$uploader_cat->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader_cat->setAllowRenameFiles(false);
$uploader_cat->setFilesDispersion(false);
$uploader_cat->save($path, $_FILES['fileinputname1']['name']);
} catch (Exception $e) {
echo 'Error Message: '.$e->getMessage();
}
$postData['fileinputname'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'foo/' .$_FILES['fileinputname']['name'];
$postData['fileinputname1'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'foo/' .$_FILES['fileinputname1']['name'];
//$data['popup_image'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'p_gallery/'. $_FILES['popup_image']['name'];
}
// --END---
$model = Mage::getSingleton('foo_bar/baz');
$model->setData($postData);
try {
$model->save();
Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The baz has been saved.'));
$this->_redirect('*/*/');
return;
}
catch (Mage_Core_Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while saving this baz.'));
}
Mage::getSingleton('adminhtml/session')->setBazData($postData);
$this->_redirectReferer();
}
}
public function messageAction()
{
$data = Mage::getModel('foo_bar/baz')->load($this->getRequest()->getParam('id'));
echo $data->getContent();
}
/**
* Initialize action
*
* Here, we set the breadcrumbs and the active menu
*
* @return Mage_Adminhtml_Controller_Action
*/
protected function _initAction()
{
$this->loadLayout()
// Make the active menu match the menu config nodes (without 'children' inbetween)
->_setActiveMenu('catalog/foo_bar_baz')
->_title($this->__('Catalog'))->_title($this->__('Baz'))
->_addBreadcrumb($this->__('Catalog'), $this->__('Catalog'))
->_addBreadcrumb($this->__('Baz'), $this->__('Baz'));
return $this;
}
/**
* Check currently called action by permissions for current user
*
* @return bool
*/
protected function _isAllowed()
{
return Mage::getSingleton('admin/session')->isAllowed('catalog/foo_bar_baz');
}
}
//baz.php ---model/baz.php
<?php
class Foo_Bar_Model_Baz extends Mage_Core_Model_Abstract
{
protected function _construct()
{
$this->_init('foo_bar/baz');
}
}