I have created a custom module to save fields in database now want to get all the fields value into the form so they will be shown in admin:
Here is my adminform:
<?php
class OptFirst_ReviewMyCompany_Block_Adminhtml_Form_Edit_Form extends
Mage_Adminhtml_Block_Widget_Form
{
/**
* Preparing form
*
* @return Mage_Adminhtml_Block_Widget_Form
*/
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'),
'value' => 'facebook.com'
));
$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();
}
}
This is the form in admin: enter image description here I want to create a view where all the form fields will be shown there database value.. is that can be done?
Thanks!
1 Answer 1
Try this,
<?php
class OptFirst_ReviewMyCompany_Block_Adminhtml_Form_Edit_Form extends
Mage_Adminhtml_Block_Widget_Form
{
{
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
)
);
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
Create on more file Block/Adminhtml/ReviewMyCompany/Edit/Tab/Form.php
<?php
class OptFirst_ReviewMyCompany_Block_Adminhtml_ReviewMyCompany_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('modulename_form', array('legend'=>Mage::helper('proxelle')->__('Item information')));
$fieldset->addField('facebook', 'text', array(
'label' => Mage::helper('modulename')->__('Facebook'),
'class' => 'required-entry',
'required' => true,
'name' => 'facebook',
));
}
I guess you missed folder structure for more Follow this http://kamleshkamble.blogspot.in/2013/02/custom-module-in-magento-with-custom.html
-
its giving error at this line $form = new Varien_Data_Form();Xabby– Xabby2016年11月29日 17:46:44 +00:00Commented Nov 29, 2016 at 17:46
-
Update your full errorMagento 2– Magento 22016年11月29日 17:54:49 +00:00Commented Nov 29, 2016 at 17:54
-
it is some type of syntax error in IDEXabby– Xabby2016年11月29日 18:01:27 +00:00Commented Nov 29, 2016 at 18:01
-
screencast.com/t/dsHYYVOOn check hereXabby– Xabby2016年11月29日 18:03:03 +00:00Commented Nov 29, 2016 at 18:03
-
change modulename into your modulename and change proxelle into your modulenameMagento 2– Magento 22016年11月29日 18:51:57 +00:00Commented Nov 29, 2016 at 18:51