0

I am adding custom admin module for magento 1.8. I have joined two table one is core_store_group and another one is my custom flat table Its working fine, In new form I have 2 fields select box and file field, I am adding store_group_id and CSV file content to my custom flat table by iterating each time for CSV content.

Yes Now also its working fine. I am facing problem in edit. I am using same form to edit the product. That I don't want. I need to display all the content while editing in two fields one is select That is showing correct answer, second field while editing instead of file field I need to display text area to display data.

Following is my form code which display one select field and file field for both while edit and new

protected function _prepareForm()
    {
        $foundation = Mage::registry('foundation_data');
        $form = new Varien_Data_Form();

        $fieldset = $form->addFieldset('foundation_form', array('legend'=>Mage::helper('foundation')->__('Foundation Members')));

        $fieldset->addField('store_id', 'select', array(
          'label'     => Mage::helper('foundation')->__('Select Store'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'store_id',
          'values'   => Mage::helper('foundation')->getStoreOptionValues(true),
          ));
        $fieldset->addField('file', 'file', array(
          'label'     => Mage::helper('foundation')->__('CSV'),
          'class'     => 'desable',
          'required'  => true,
          'name'      => 'file',
        ));
        $this->setForm($form);
        $form->setValues($foundation->getData());
        if (Mage::getSingleton('adminhtml/session')->getFoundationData()) {
            $form->setValues(Mage::getSingleton('adminhtml/session')->getFoundationData());
            Mage::getSingleton('adminhtml/session')->setFoundationData(null);
        } elseif (Mage::registry('foundation_data')) {
            $form->setValues(Mage::registry('foundation_data')->getData());
        }
        return parent::_prepareForm();
    }

My question is how to display different form while edit and new?

  • I suggest you to add piece of code, that you are using – TBI Infotech Jun 10 '14 at 13:42
2

I am not sure, But you can try something like this:

protected function _prepareForm()
    {
        $foundation = Mage::registry('foundation_data');
        $form = new Varien_Data_Form();

        $fieldset = $form->addFieldset('foundation_form', array('legend'=>Mage::helper('foundation')->__('Foundation Members')));

        $fieldset->addField('store_id', 'select', array(
          'label'     => Mage::helper('foundation')->__('Select Store'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'store_id',
          'values'   => Mage::helper('foundation')->getStoreOptionValues(true),
          ));
          if(($this->getRequest()->getParam('id'))!=''){
          $fieldset->addField('textarea', 'textarea', array(
          'label'     => Mage::helper('form')->__('TextArea'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'title',
          'onclick' => "",
          'onchange' => "",
          'value'  => '<b><b/>',
          'disabled' => false,
          'readonly' => false,
          'after_element_html' => '<small>Comments</small>',
          'tabindex' => 1
        ));
}
else{

$fieldset->addField('file', 'file', array(
          'label'     => Mage::helper('foundation')->__('CSV'),
          'class'     => 'desable',
          'required'  => true,
          'name'      => 'file',
        ));
}
 $this->setForm($form);
        $form->setValues($foundation->getData());
        if (Mage::getSingleton('adminhtml/session')->getFoundationData()) {
            $form->setValues(Mage::getSingleton('adminhtml/session')->getFoundationData());
            Mage::getSingleton('adminhtml/session')->setFoundationData(null);
        } elseif (Mage::registry('foundation_data')) {
            $form->setValues(Mage::registry('foundation_data')->getData());
        }
        return parent::_prepareForm();
    }
| improve this answer | |
0

You can identify the form is on edit mode by using below code $this->getRequest()->getParam('id');

It should return you the 'id', when you will edit any entry . On the basis of this id, you can make checks in "_prepareForm()" and can show the textarea and set values in 'values' tag of that field . But first be sure that when you are uploading CSV file, you are saving its content in database as text, not it as a file.

| improve this answer | |

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.