1

Have the following fields in my from:

    protected function _prepareForm()
{
    $form = new Varien_Data_Form(array(
        'id' => 'edit_form',
        'action' => $this->getUrl('*/*/save'),
        '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('facebook', 'text', array(
        'name' => 'facebook',
        'label' => $helper->__('Facebook'),
        ));
    $fieldset->addField('google', 'text', array(
        'name' => 'google',
        'label' => $helper->__('Google'),
        ));
    $fieldset->addField('twitter', 'text', array(
        'name' => 'twitter',
        'label' => $helper->__('Twitter'),
        ));
    $fieldset->addField('linkedin', 'text', array(
        'name' => 'linkedin',
        'label' => $helper->__('Linkedin'),
        ));
    $fieldset->addField('yelp', 'text', array(
        'name' => 'yelp',
        'label' => $helper->__('Yelp'),
        ));


    if (Mage::registry('optfirst_reviewmycompany')) {
        $form->setValues(Mage::registry('optfirst_reviewmycompany')->getData());
    }

    return parent::_prepareForm();
}

Here is my Modal:

     class OptFirst_ReviewMyCompany_Model_Review extends       Mage_Core_Model_Abstract
     {
    public function _construct()
     {
     parent::_construct();
     $this->_init('optfirst_reviewmycompany/review');
    }
   }

And here is my controller function to save data:

public function saveAction()
    {

    $data = $this->getRequest()->getParams();
if ( $data ) {

    print_r($data);

    $this->_getSession()->setFormData($data);
    $model = Mage::getModel('reviewmycompany/review');
    $id = $this->getRequest()->getParam('id');
    try {
        if ( $id ) {
            $model->load($id);
        }
        $model->addData($data);
        //saves data
        $model->save();

        $this->_getSession()->addSuccess(
                $this->__('Data was saved'));

        $this->_getSession()->setFormData(false);

        if ( $this->getRequest()->getParam('back') ) {
            $params = array('id' => $model->getId());
            $this->_redirect('*/*/edit', $params);
        } else {
            $this->_redirect('*/*/list');
        }
    } catch ( Exception $e ) {
        $this->_getSession()->addError($e->getMessage());
        if ( $model && $model->getId() ) {
            $this->_redirect('*/*/edit', array(
                'id' => $model->getId()
            ));
        } else {
            $this->_redirect('*/*/new');
        }
    }

    return;
}

When I save form it gives following error:

Call to a member function addData() on boolean in C:\xampp\htdocs\magento-new\app\code\community\OptFirst\ReviewMyCompany\controllers\Adminhtml\AdminformController.php on line 77

I need help to solve this issue so the form successfully save data to database table

2

I think you should call your model this way:

$model = Mage::getModel('optfirst_reviewmycompany/review');

You can find correct model alias in the {Vendor}/{Module}/etc/config.xml file in the global -> models section.

Example, the model alias is test: example

Update:

If the $data is not an empty array after the $model->addData($data); your code print_r($model->getData()); should return at least the $data parameters (can be more, but not less).

  • Oh.. that was the issue too thanks for this.. but now when i print the model it gives empty array @Siarhey Uchukhlebau – Xabby Nov 24 '16 at 15:15
  • I did like this print_r($model->getData()); and it returns Array ( ) – Xabby Nov 24 '16 at 15:16
  • @Xabby On what line? – Siarhey Uchukhlebau Nov 24 '16 at 15:16
  • 1
    @Xabby. Don't mix the questions and dont spawn additional questions once you got a right answer. If this solved your problem mark the answer as accepted and ask a different question for your different problem. – Marius Nov 24 '16 at 15:16
  • Here i print the model and it returs the empty array $this->_getSession()->setFormData($data); $model = Mage::getModel('optfirst_reviewmycompany/review'); print_r($model->getData()); @Siarhey Uchukhlebau – Xabby Nov 24 '16 at 15:20

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.