I have a form that saved the value in DB and then i have retrieve that values in an admin Grid Now on Grid view i have Edit button that suppose to be take the user to edit form and after some changes save the edit form. But in my case it showing empty forms.
I have Controller function for edit action is as like follows:
public function editAction()
{
$this->_registryObject();
$this->getResponse()->setBody(
$this->getLayout()->createBlock('optfirst_reviewmycompany/adminhtml_edits_edit')
->toHtml()
);
}
Here is the Edit.php code
public function __construct()
{
parent::__construct();
$this->_blockGroup = 'optfirst_reviewmycompany';
$this->_controller = 'adminhtml_edits';
$this->_headerText = Mage::helper('optfirst_reviewmycompany')->__('Social Icons');
}
And this is my Edit action from my Grid:
public function __construct()
{
$this->_controller = 'adminhtml_review';
$this->_blockGroup = 'optfirst_reviewmycompany';
$this->_headerText = Mage::helper('optfirst_reviewmycompany')->__('Social Icon Manager');
$this->_addButton('add_new', array(
'label' => Mage::helper('optfirst_reviewmycompany')->__('Edit Social Icons'),
'onclick' => "setLocation('{$this->getUrl('/adminform/edit')}')",
'class' => 'edit'
));
parent::__construct();
}
And here is the form.php code that have to show the edit input fields:
protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/edit'),
'method' => 'post',
));
$form->setUseContainer(true);
$this->setForm($form);
$helper = Mage::helper('optfirst_reviewmycompany');
$fieldset = $form->addFieldset('display', array('legend' => $helper->__('Select Social Icons'),
'class' => 'fieldset-wide'));
$fieldset->addField('google', 'text', array(
'name' => 'google',
'label' => $helper->__('Google'),
));
$fieldset->addField('twitter', 'text', array(
'name' => 'twitter',
'label' => $helper->__('Twitter'),
));
$fieldset->addField('yelp', 'text', array(
'name' => 'yelp',
'label' => $helper->__('Yelp'),
));
$fieldset->addField('linkedin', 'text', array(
'name' => 'linkedin',
'label' => $helper->__('LinkedIn'),
));
$fieldset->addField('pintrest', 'text', array(
'name' => 'pintrest',
'label' => $helper->__('Pintrest'),
));
$fieldset->addField('gmaps', 'text', array(
'name' => 'gmaps',
'label' => $helper->__('Google Map'),
));
$fieldset->addField('bing', 'text', array(
'name' => 'bing',
'label' => $helper->__('Bing'),
));
$fieldset->addField('coc', 'text', array(
'name' => 'coc',
'label' => $helper->__('Chamber of Commerce'),
));
$fieldset->addField('city_search', 'text', array(
'name' => 'city_search',
'label' => $helper->__('City Search'),
));
$fieldset->addField('ezlocal', 'text', array(
'name' => 'ezlocal',
'label' => $helper->__('EZLocal'),
));
$fieldset->addField('local', 'text', array(
'name' => 'local',
'label' => $helper->__('Local'),
));
$fieldset->addField('mcircle', 'text', array(
'name' => 'mcircle',
'label' => $helper->__('MerchantCircle'),
));
$fieldset->addField('show_me_local', 'text', array(
'name' => 'show_me_local',
'label' => $helper->__('ShowmeLocal'),
));
$fieldset->addField('superpages', 'text', array(
'name' => 'superpages',
'label' => $helper->__('Superpages'),
));
$fieldset->addField('topix', 'text', array(
'name' => 'topix',
'label' => $helper->__('Topix'),
));
$fieldset->addField('uscity', 'text', array(
'name' => 'uscity',
'label' => $helper->__('USCity'),
));
$fieldset->addField('where_to_app', 'text', array(
'name' => 'where_to_app',
'label' => $helper->__('Wheretoapp'),
));
$fieldset->addField('yahoo', 'text', array(
'name' => 'yahoo',
'label' => $helper->__('Yahoo'),
));
$fieldset->addField('yellow_bot', 'text', array(
'name' => 'yellow_bot',
'label' => $helper->__('Yellowbot'),
));
$fieldset->addField('yellow_wise', 'text', array(
'name' => 'yellow_wise',
'label' => $helper->__('Yellowise'),
));
if (Mage::registry('optfirst_reviewmycompany')) {
$form->setValues(Mage::registry('optfirst_reviewmycompany')->getData());
}
return parent::_prepareForm();
}
}
Registry form object
protected function _registryObject()
{
$id=$this->getRequest()->getParam('id');
$data=Mage::getModel('optfirst_reviewmycompany/review')->load($id);
Mage::register('optfirst_reviewmycompany', $data);
}
Here is the Grid.php
<?php
class OptFirst_ReviewMyCompany_Block_Adminhtml_Review_Grid extends
Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('reviewGrid');
$this->setDefaultSort('id_optfirst_reviewmycompany');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getModel('optfirst_reviewmycompany/review')->getCollection();
//print_r($collection);
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('facebook', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Facebook'),
'align' => 'right',
'width' => '10px',
'index' => 'facebook',
));
$this->addColumn('google', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Google'),
'align' => 'left',
'index' => 'google',
'width' => '50px',
));
$this->addColumn('linkedin', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Linkedin'),
'width' => '150px',
'index' => 'linkedin',
));
$this->addColumn('twitter', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Linkedin'),
'width' => '150px',
'index' => 'twitter',
));
$this->addColumn('yelp', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Linkedin'),
'width' => '150px',
'index' => 'yelp',
));
$this->addColumn('pintrest', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Pintrest'),
'width' => '150px',
'index' => 'pintrest',
));
$this->addColumn('gmaps', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Google Maps'),
'width' => '150px',
'index' => 'gmaps',
));
$this->addColumn('bing', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Bing'),
'width' => '150px',
'index' => 'bing',
));
$this->addColumn('coc', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Chamber of Commerce'),
'width' => '150px',
'index' => 'coc',
));
$this->addColumn('city_search', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('City Search'),
'width' => '150px',
'index' => 'city_search',
));
$this->addColumn('ezlocal', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('EZLocal'),
'width' => '150px',
'index' => 'ezlocal',
));
$this->addColumn('local', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Local'),
'width' => '150px',
'index' => 'city_search',
));
$this->addColumn('mcircle', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('MerchanCicle'),
'width' => '150px',
'index' => 'mcircle',
));
$this->addColumn('show_me_local', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Show Me Local'),
'width' => '150px',
'index' => 'show_me_local',
));
$this->addColumn('superpages', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Superpages'),
'width' => '150px',
'index' => 'superpages',
));
$this->addColumn('topix', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Topix'),
'width' => '150px',
'index' => 'topix',
));
$this->addColumn('uscity', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('USCity'),
'width' => '150px',
'index' => 'uscity',
));
$this->addColumn('where_to_app', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Where To App'),
'width' => '150px',
'index' => 'where_to_app',
));
$this->addColumn('yahoo', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Yahoo'),
'width' => '150px',
'index' => 'yahoo',
));
$this->addColumn('yellow_bot', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('YellowBot'),
'width' => '150px',
'index' => 'yellow_bot',
));
$this->addColumn('yellow_wise', array(
'header' => Mage::helper('optfirst_reviewmycompany')->__('Yellowwise'),
'width' => '150px',
'index' => 'yellow_wise',
));
return parent::_prepareColumns();
}
}
And showing the edit form like the image attached not proper layout.
Please Look at the code and find out the mistake that i have made, why it is showing the blank form instead of values in it.
Best Answer
add this function in your grid and check