0

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!

0

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

5
  • its giving error at this line $form = new Varien_Data_Form();
    – Xabby
    Nov 29 '16 at 17:46
  • Update your full error
    – Magento 2
    Nov 29 '16 at 17:54
  • it is some type of syntax error in IDE
    – Xabby
    Nov 29 '16 at 18:01
  • screencast.com/t/dsHYYVOOn check here
    – Xabby
    Nov 29 '16 at 18:03
  • change modulename into your modulename and change proxelle into your modulename
    – Magento 2
    Nov 29 '16 at 18:51

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.