/* Here, Created Multiple field for this module form */
A) This is a Form.php files Where you can create your Custom Field's as per Requirement
Path for your File is "app\code\local\[Namespace]\[Module Name]\Block\Adminhtml\[Modele Name]\Edit\Tab\Form.php"
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('beautygirl_form', array('legend'=>Mage::helper('beautygirl')->__('Item information')));
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('beautygirl')->__('Title'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
));
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('beautygirl')->__('Status'),
'name' => 'status',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('beautygirl')->__('Enabled'),
),
array(
'value' => 2,
'label' => Mage::helper('beautygirl')->__('Disabled'),
),
),
));
$fieldset->addField('startdate', 'date', array(
'name' => 'startdate',
'title' => Mage::helper('beautygirl')->__('Start Date'),
'label' => Mage::helper('beautygirl')->__('Start Date'),
'image' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'/adminhtml/default/default/images/grid-cal.gif',
//'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
//'format' => 'dd-MM-yyyy',
'format' => 'yyyy-MM-dd',
//'format' => Varien_Date::DATE_INTERNAL_FORMAT,
'required' => true,
));
$fieldset->addField('enddate', 'date', array(
'name' => 'enddate',
'title' => Mage::helper('beautygirl')->__('End Date'),
'label' => Mage::helper('beautygirl')->__('End Date'),
'image' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'/adminhtml/default/default/images/grid-cal.gif',
//'format' => 'MM-dd-yyyy',
'format' => 'yyyy-MM-dd',
'required' => true,
));
$fieldset->addField('filename', 'file', array(
'label' => Mage::helper('beautygirl')->__('File'),
'required' => true,
'name' => 'filename',
));
$fieldset->addField('girlone', 'text', array(
'label' => Mage::helper('beautygirl')->__('Girl One'),
'class' => 'required-entry',
'required' => true,
'name' => 'girlone',
));
$fieldset->addField('girlonecontent', 'editor', array(
'name' => 'girlonecontent',
'label' => Mage::helper('beautygirl')->__('Content'),
'title' => Mage::helper('beautygirl')->__('Content'),
'style' => 'width:700px; height:500px;',
'wysiwyg' => false,
'required' => true,
));
if ( Mage::getSingleton('adminhtml/session')->getBeautygirlData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getBeautygirlData());
Mage::getSingleton('adminhtml/session')->setBeautygirlData(null);
} elseif ( Mage::registry('beautygirl_data') ) {
$form->setValues(Mage::registry('beautygirl_data')->getData());
}
return parent::_prepareForm();
}
}
B) This is the Second Step ::: app\code\local\[Namespace] \[Module Name]\controller/Adminhtml/yourcontrollerfile.php
/* For save your Module Item open controller file of module */
/* path = controller/Adminhtml/yourcontrollerfile.php*/
/* Here change two functions ""editAction"" and ""SaveAction"" */
In EditAction
/* Here I Use Example for create 2 extra tabs Mean I have Tabs Like this */
/* 1. Form[Default] 2. Form1 3. Form2 */
public function editAction() {
$id = $this->getRequest()->getParam('id');
$model = Mage::getModel('beautygirl/beautygirl')->load($id);
if ($model->getId() || $id == 0) {
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
if (!empty($data)) {
$model->setData($data);
}
$data1 = Mage::getSingleton('adminhtml/session')->getForm1Data(true);
if (!empty($data1)) {
$model->setData($data1);
}
$data2 = Mage::getSingleton('adminhtml/session')->getForm2Data(true);
if (!empty($data2)) {
$model->setData($data2);
}
}
In SaveAction
/* Here I Use Example for create 2 extra tabs Mean I have Tabs Like this */
/* 1. Form[Default] 2. Form1 3. Form2 */
/* In Save Action, We Save Data of Forms Which are created By us */
public function saveAction() {
if ($data = $this->getRequest()->getPost()) {
if(isset($_FILES['filename']['name']) && ($_FILES['filename']['name'] != '') &&
(isset($_FILES['filename1']['name']) && ($_FILES['filename1']['name'] != '')) &&
(isset($_FILES['filename2']['name']) && ($_FILES['filename2']['name'] != ''))) {
try {
/* Starting upload */
/* This is Upload Image of Forms FileUpload Field */
$uploader = new Varien_File_Uploader('filename');
$uploader1 = new Varien_File_Uploader('filename1');
$uploader2 = new Varien_File_Uploader('filename2');
// Any extention would work
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
// Any extention would work
$uploader1->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader1->setAllowRenameFiles(false);
// Any extention would work
$uploader2->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader2->setAllowRenameFiles(false);
// Set the file upload mode
// false -> get the file directly in the specified folder
// true -> get the file in the product like folders
// (file.jpg will go in something like /media/f/i/file.jpg)
$uploader->setFilesDispersion(false);
$uploader1->setFilesDispersion(false);
$uploader2->setFilesDispersion(false);
// We set media as the upload dir
$path = Mage::getBaseDir('skin') . DS.('frontend').DS.('default').DS.('beautydem').DS.('images').DS.('Beautygirl').DS ;
$uploader->save($path, $_FILES['filename']['name'] );
// We set media as the upload dir
$path1 = Mage::getBaseDir('skin') . DS.('frontend').DS.('default').DS.('beautydem').DS.('images').DS.('Beautygirl').DS ;
$uploader1->save($path1, $_FILES['filename1']['name']);
$path2 = Mage::getBaseDir('skin') . DS.('frontend').DS.('default').DS.('beautydem').DS.('images').DS.('Beautygirl').DS ;
$uploader2->save($path2, $_FILES['filename2']['name']);
}
catch (Exception $e)
{
}
//this way the name is saved in DB
$data['filename'] = $_FILES['filename']['name'];
$data['filename1'] = $_FILES['filename1']['name'];
$data['filename2'] = $_FILES['filename2']['name'];
}
/* If you use multiselection then for insert value as comm seperated in database use below lines */
$data['girloneproductid']=implode(',',$data['girloneproductid']);
$data['girltwoproductid']=implode(',',$data['girltwoproductid']);
$data['girlthreeproductid']=implode(',',$data['girlthreeproductid'])
$model = Mage::getModel('beautygirl/beautygirl');
$model->setData($data)
->setId($this->getRequest()->getParam('id'));
try
{
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL)
{
$model->setCreatedTime(now())
->setUpdateTime(now());
}
else
{
$model->setUpdateTime(now());
}
$model->save();
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('beautygirl')->__('Item was successfully saved'));
Mage::getSingleton('adminhtml/session')->setFormData(false);
Mage::getSingleton('adminhtml/session')->setForm1Data(false);
Mage::getSingleton('adminhtml/session')->setForm2Data(false);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('beautygirl')->__('Unable to find item to save'));
$this->_redirect('*/*/');
}
/* Must add thoes fiels in SQL file of Module form*/
/* path = sql/../sqlfile */
No comments:
Post a Comment