0

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');
}  
 }
  • could you show us the code that is actually processing this information, the controller and model should be enough. – David Manners Oct 15 '13 at 8:25
  • @DavidManners i have shown my controller and model files – DRAJI Oct 15 '13 at 9:04
1

the fieldsets are only a way to organize the fields visually. Thy shouldn't have an impact in saving the data from them. There shouldn't be any difference if the fields are all in one fieldset or in 10. There is something else that's preventing the fields from being saved.
If you added the table columns corresponding to the second fieldset by altering the table, you should clear the cache. Even if the cache is disabled ZF still caches the table schema.
Also make sure that the field names are the same as the column columns.
If the fields in the second fieldset are date fields maybe there is a problem with the date format you are using.
Add this in the controller on the save action

Zend_Debug::dump($this->getRequest()->getPost()) 

and see how the values are sent to the controller.

  • Thank you for give me the clearance about form fieldsets. when i have put this "Zend_Debug::debug($this->getRequest()->getPost()) " in save action method, i got an error like "Call to undefined method Zend_Debug::debug() " – DRAJI Oct 15 '13 at 8:57
  • @DRAJI. Sorry, my bad. It should be Zend_Debug::dump(). I've edited the answer. – Marius Oct 15 '13 at 9:01
  • Thank you Marius. but i dunno where to see that action stream? – DRAJI Oct 15 '13 at 9:06
  • still now i didn't get result. please help. I dunno how to use it Zend_Debug::dump()! – DRAJI Oct 15 '13 at 10:07
  • "Cannot send headers; headers already sent" i got this error – DRAJI Oct 15 '13 at 10:17

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.