0

I am trying create an custom module and it have multiple tabs in admin section like product module .

Issue i did not showing any tabs content from second tab ,like second tab content data is shows blank.

enter image description here

enter image description here Here some code is

class Amit_Cellpeople_Block_Adminhtml_List_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('cellpeople_tabs');
        $this->setDestElementId('edit_form');
        $this->setTitle(Mage::helper('cellpeople')->__('Manage cellpeople'));
    }

    protected function _beforeToHtml()
    {
        $this->addTab('form_section', array(
            'label' => Mage::helper('cellpeople')->__('cellpeople Information'),
            'title' => Mage::helper('cellpeople')->__('cellpeople Information'),
            'content' => $this->getLayout()->createBlock('cellpeople/adminhtml_list_edit_tab_form')->toHtml(),
        ));
    $this->addTab('cellpeople_details',array(
                'label'=>Mage::helper('cellpeople')->__('cellpeople Store  Details'),
                'title'=>Mage::helper('cellpeople')->__('cellpeople Store  Details'),
                'content'=>$this->getLayout()->createBlock('cellpeople/adminhtml_list_edit_tab_storedetails')->toHtml(),

    ));

        return parent::_beforeToHtml();
    }
}

and code of Form.php (Amit>Cellpeople>Block>Adminhtml>List>Edit>Tab)

<?php

class Amit_Cellpeople_Block_Adminhtml_List_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $cellpeople = Mage::registry('cellpeople_data');
        $form = new Varien_Data_Form(); 
        $fieldset = $form->addFieldset('cellpeople_form', array(
            'legend' => Mage::helper('cellpeople')->__('cellpeople Registration')
        ));

        $fieldset->addField('name', 'text', array(
            'name' => 'cellpeople[name]',
            'label' => Mage::helper('cellpeople')->__('Name'),
            'required' => 'true',
        ));

        $fieldset->addField('email', 'text', array(
            'name'    => 'cellpeople[email]',
            'label'   => Mage::helper('cellpeople')->__('Email'),
            'required' => 'true',

        ));
        $fieldset->addField('password', 'password', array(
            'name'     => 'cellpeople[password]',
            'class' => 'required-entry',
            'label'    => Mage::helper('cellpeople')->__('Password'),
            'required' => 'true',
        ));
        $fieldset->addField('confirm_password', 'password', array(
            'name'     => 'cellpeople[confirm_password]',
            'class'     => 'required-entry',
            'label'    => Mage::helper('cellpeople')->__('Confirm Password'),
            'required' => 'true',
        ));

        $fieldset->addField('mobile_no', 'text', array(
            'name' => 'cellpeople[mobile_no]',
            'label' => Mage::helper('cellpeople')->__('Mobile No'),
            'required' => 'true',
        ));

        $fieldset->addField('phone_no', 'text', array(
            'name' => 'cellpeople[phone_no]',
            'label' => Mage::helper('cellpeople')->__('Phone No'),

        ));

        $this->setForm($form);
        $form->setValues($cellpeople->getData());

        return parent::_prepareForm();
    }

}

anthor form file Storedetails.php code are

class Amit_Cellpeople_Block_Adminhtml_List_Edit_Tab_Storedetails extends Mage_Adminhtml_Block_Widget_Form
{
   protected function _prepareForm(){ 
$cellvendor = Mage::registry('vendordetails_data');// new registry for different module


    $form = new Varien_Data_Form(); 
    $fieldset = $form->addFieldset('vendor_form', array(
        'legend' => Mage::helper('cellpeople')->__('Vendor deatsilsn')
    ));

    $fieldset->addField('name_a', 'text', array(
        'name' => 'vendor_h[name]',
        'label' => Mage::helper('cellpeople')->__('Name'),
        'required' => 'true',
    ));


    $fieldset->addField('email', 'text', array(
        'name'    => 'vendor_h[email]',
        'label'   => Mage::helper('cellpeople')->__('Email'),
        'required' => 'true',

    )); 
}
}

Please help.... After marius help i have modify code of second form data in Storedetails.php

protected function _prepareForm(){ 
    $cellvendor = Mage::registry('vendordetails_data');// new registry for different module
echo "<pre>";
    print_r($cellvendor ->getData());
    echo "</pre>";

        $form = new Varien_Data_Form(); 
        $fieldset = $form->addFieldset('vendor_form', array(
            'legend' => Mage::helper('cellpeople')->__('Vendor deatsilsn')
        ));

        $fieldset->addField('company', 'text', array(
            'name' => 'company',
            'label' => Mage::helper('cellpeople')->__('company'),
            'required' => 'true',
        ));


        $fieldset->addField('bank_ifsc', 'text', array(
            'name'    => 'bank_ifsc',
            'label'   => Mage::helper('cellpeople')->__('bank_ifsc'),
            'required' => 'true',

        ));
    $this->setForm($form);
    $form->setValues($cellvendor>getData());
    return parent::_prepareForm();

}

but data is empty in fields of second tabs.Plese check the in imageenter image description here.**Issue is that registry have data but in not showing fields**

  • 2
    and what is your question? – Marius Feb 6 '14 at 20:44
  • Marius, i have clarify my question ,please check again and help mw – Amit Bera Feb 6 '14 at 21:05
2

Make sure the block from the second tab returns something.
You are missing this code at the end of _prepareForm() method:

$this->setForm($form); //set the form object to the block
return parent::_prepareForm(); //this is not mandatory but it is nice to keep a consistency.  

And an other tip, off topic.
Don't declare the names of the fields like this. You might get into trouble.

'name' => 'vendor_h[name]',

You can add this at the top of _prepareForm after $form = new Varien_Data_Form();

$form->setFieldNameSuffix('vendor_h');

This will transform the names of the fields from field_name to vendor_h[field_name].
In a similar way you can add a prefix for the ids of the field with this line

$form->setHtmlIdPrefix('some_prefix_');

This will transform the id of the fields from field_id to some_prefix_field_id.

| improve this answer | |
  • Thanks Marius for your reply but i have new issue the field cannot showing value that has been already in registry... – Amit Bera Feb 7 '14 at 7:56
  • @AmitBera then add this also $form->setValues($cellpeople->getData()); – Marius Feb 7 '14 at 7:58
  • Thanks but it is not working.... please check again the question i have modify according to your process...but show blanks – Amit Bera Feb 7 '14 at 8:10
  • @AmitBera try with $form->addValues instead of getValues. But this is strange. I think it should work. – Marius Feb 7 '14 at 8:15
  • ,it is not working,please review the code ... – Amit Bera Feb 7 '14 at 8:19
1

in your second tab you dont call

$this->setForm($form);
$form->setValues($cellvendor->getData());
return parent::_prepareForm();

and as Marius said Dont declare the fieldnames in this way.

| 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.