1

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. enter image description here

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.

18
  • Show _registryObject function definition?
    – Sohel Rana
    Jan 10 '17 at 11:29
  • @Sohel Rana Here it is in my controller: protected function _registryObject() { $id=$this->getRequest()->getParam('id'); $data=Mage::getModel('optfirst_reviewmycompany/review')->load($id); Mage::register('optfirst_reviewmycompany', $data); }
    – Xabby
    Jan 10 '17 at 11:31
  • @SohelRana I ve updated the question with registry object function
    – Xabby
    Jan 10 '17 at 11:35
  • @Xabby check the values of this echo $id=$this->getRequest()->getParam('id'); you are getting value of it? Jan 10 '17 at 11:38
  • @QaisarSatti sure let me check it ...
    – Xabby
    Jan 10 '17 at 11:38
2

add this function in your grid and check

public function getRowUrl($row)
  {
      return $this->getUrl('*/*/edit', array('id' => $row->getId()));
  }
6
  • Still printing the same : Array ( [key] => 69800f0ed12699da01a60f605385a683 ) I have added it after -> return parent::_prepareColumns();
    – Xabby
    Jan 10 '17 at 13:17
  • @Xabby use this for getting current id echo $id=$this->getRequest()->getParam('id'); Jan 10 '17 at 14:46
  • But my primary_key is id_optfirst_reviewmycompany in my DB table
    – Xabby
    Jan 10 '17 at 16:43
  • Can u share your edit url? Jan 10 '17 at 17:08
0

Okay. What if you change in Form.php:

$form = new Varien_Data_Form(array(
        'id' => 'edit_form',
        'action' => $this->getUrl('*/*/edit'),
        'method' => 'post',
        ));

to:

$form = new Varien_Data_Form(array(
        'id' => 'edit_form',
        'action' => $this->getUrl('*/*/edit', array('id' => $this->getRequest()->getParam('id'))),
        'method' => 'post',
        ));

if the form needs to be saved, then the 'action' array element should be:

'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id')))

Let me know if this helps

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.