hi Guys I have a problem with form action of a form generated by admin panel of magento for a custom module.
This is the structure of my files under app/code/local/Namespace/Zipcodes/Block
Block
|
|____Adminhtml
|
|____ Importblock
|
|__Edit
| |__Form.php
| |__Tabs.php
| |
| |__Tab
| |___Form.php
|
|__Edit.php
|
|
Zipcodes
|
|__Edit
| |__Form.php // << this file is getting called in importblock form
| |__Tabs.php
| |
| |__Tab
| |___Form.php
|
|__Edit.php
This is my action method of ZipcodesController.php
public function importAction()
{
if ($data = $this->getRequest()->getPost() && isset($_FILES['csv_file']['name']) )
{
echo '<br> hi ! we uploaded the file';
}
$this->_initAction();
$this->_addContent($this->getLayout()->createBlock('zipcodes/adminhtml_importblock_edit'))
->_addLeft($this->getLayout()->createBlock('zipcodes/adminhtml_importblock_edit_tabs'));
$this->renderLayout();
}
This is my Block/Adminhtml/Importblock/Edit.php
<?php
class Namespace_Zipcodes_Block_Adminhtml_Importblock_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
public function __construct()
{
parent::__construct();
$this->_objectId = 'id';
$this->_blockGroup = 'zipcodes';
$this->_controller = 'adminhtml_zipcodes';
$this->_updateButton('save', 'label', Mage::helper('zipcodes')->__('Upload file'));
}
public function getHeaderText()
{
return Mage::helper('zipcodes')->__('Import Zipcode data');
}
}
This is my Block/Adminhtml/Importblock/Edit/Tab/Form.php
class Namespace_Zipcodes_Block_Adminhtml_Importblock_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/import'),
'method' => 'post',
'enctype' => 'multipart/form-data'
)
);
$this->setForm($form);
//echo '<br>form.php bahar<pre>';print_r(get_class_methods(get_class($form))); echo '</pre>';
$fieldset = $form->addFieldset('zipcodes_form', array('legend'
=> Mage::helper('zipcodes')->__('Provide data file')));
$fieldset->addField('csv_file', 'file', array(
'label' => Mage::helper('zipcodes')->__('CSV File'),
'class' => 'required-entry',
'required' => true,
'name' => 'csv_file',
));
return parent::_prepareForm();
}
}
this is my Block/Adminhtml/Importblock/Edit/Tabs.php
class Namespace_Zipcodes_Block_Adminhtml_Importblock_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
public function __construct()
{
parent::__construct();
$this->setId('zipcode_import_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(Mage::helper('zipcodes')->__('Import Zipcodes'));
}
protected function _beforeToHtml()
{
$this->addTab('form_section', array(
'label' => Mage::helper('zipcodes')->__('Zipcode Info'),
'title' => Mage::helper('zipcodes')->__('Zipcode Info'),
'content' => $this->getLayout()
->createBlock('zipcodes/adminhtml_importblock_edit_tab_form')->toHtml(),
'active' => true
));
return parent::_beforeToHtml();
}
}
& last this is my Block_Adminhtml_Importblock_Edit_Form.php
class Namespace_Zipcodes_Block_Adminhtml_Importblock_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/import'),
'method' => 'post',
)
);
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
when I run the code The last file doesn't gets called. as I am using $this->_addContent($this->getLayout()->createBlock('zipcodes/adminhtml_importblock_edit')) in code due to this when form gets rendered I see the form action action as /save instead of /import
So I changed the Block_Adminhtml_Importblock_Edit_Tab_Form & wrote
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/import'),
'method' => 'post',
'enctype' => 'multipart/form-data'
)
);
But still its showing form action as /save not /import. Can anybody help me with this
Guys I have found one more clue
the file under Adminhtml/Zipcodes/Edit/Form.php is getting called in importblock's form thats why the action is not getting set at runtime. Now can anyone help me how to remove this error & make the correct reference to Adminhtml/Importblock/Edit/Form.php
Thanks Please its so close help me