I am creating an admin module with admin form but its gives an error when i save the form data. please have a look and check where i am wrong
Ii have following form fields
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 model configuration in config.xml
<models>
<optfirst_reviewmycompany>
<class>OptFirst_ReviewMyCompany_Model</class>
<resourceModel>optfirst_reviewmycompany_resources</resourceModel>
</optfirst_reviewmycompany>
<optfirst_reviewmycompany_resources>
<class>OptFirst_ReviewMyCompany_Model_Resources</class>
<entities>
<review>
<table>optfirst_reviewmycompany_icons</table>
</review>
</entities>
</optfirst_reviewmycompany_resources>
</models>
Following is my model:
class OptFirst_ReviewMyCompany_Model_Review extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('optfirst_reviewmycompany/review');
}
}
And finally here is my controller method to save the data:
public function saveAction()
{
//$data = $this->getRequest()->getParams();
if ( $data = $this->getRequest()->getParams() ) {
print_r($data);
$this->_getSession()->setFormData($data);
$model = Mage::getModel('optfirst_reviewmycompany/review')->load(3);
//$model = Mage::getModel('optfirst_reviewmycompany/review');
print_r($model->getData());
$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;
}
Help me in solving the issue.
Thanks!