Magento: Admin form action not correct

Go To StackoverFlow.com

0

I want to add a new form to the edit customer page, so far so good, using rewrites to customer_edit_tabs i was able to add a tab and my admin form to the page. Code looks like this.

protected function _beforeToHtml()
{

        $this->addTab('extraoptions', array(
                'label'     => Mage::helper('customer')->__('Extra options'),
                'class'     => 'ajax',
                'url'       => $this->getUrl('module/adminhtml_tabs/info', array('_current' => true)),
        ));  

This adds my tab corrently. From there the link on the tabs controller:

    public function infoAction()
{
    $this->_init();
    $this->getResponse()->setBody(
    $this->getLayout()->createBlock('module/adminhtml_tabs_edit')->toHtml()
    );;
}  

This links to my form container on Block/Adminhtml/Tabs/Edit.php

class Namespace_Module_Block_Adminhtml_Tabs_Edit extends Mage_Adminhtml_Block_Widget_Form_Container{public function __construct()
{
    parent::__construct();

    $this->_objectId = 'id';
    $this->_mode = 'edit';
    $this->_blockGroup = 'module';
    $this->_controller = 'adminhtml_tabs';
    $this->_updateButton('save', 'label', Mage::helper('module')->__('Save'));

}

public function getHeaderText()
{
    return Mage::helper('module')->__('Extra Options');
}

}

My Block/Adminhtml/Tabs/Edit/Form.php

class Namespace_Module_Block_Adminhtml_Tabs_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
    {
public function __construct()
{
    parent::__construct();
}
protected function _prepareForm()
{
    $form = new Varien_Data_Form(array(
'id' => 'info_form',
                       'action' => $this->getUrl('module/adminhtml_tabs/save', array('id' => $this->getRequest()->getParam('id'))),
                       'method' => 'post',
                       'enctype' => 'multipart/form-data'
                               )
    ); 

    $fieldset = $form->addFieldset('extra_options', array('legend' => Mage::helper('module')->__('Extra Options Fieldset')));

    $fieldset2->addField('extra', 'text', array(
            'name'      => 'zip',
            'title'     => Mage::helper('module')->__('extra'),
            'label'     => Mage::helper('module')->__('extra data'),
            'maxlength' => '250',
            'required'  => false,
));
    $form->setUseContainer(true);

    }
protected function _prepareLayout()
{
    return parent::_prepareLayout();
}  

Everything is fine, I have a new button below the default save customer buttons, but this save button does not update the action, so if i click it, it goes to the default customer/edit/save action, it does not tell me the method does not exist which it should. My guess is that there is something wrong with the container but i have tried three tutorials with little differences to no avail, hope someone can help and even maybe someone will find my code helpful.

2012-04-04 17:43
by changeling


0

I decided to create a new button to save with a custom action. On the container:

$this->_addButton('save', array(
        'label'     => Mage::helper('adminhtml')->__('Save Extras'),
        'onclick'   => 'document.myform.submit();',
        'class'     => 'save',
    ),-1,5);  

This did the trick.

2012-04-06 17:48
by changeling


0

In this line of code:

'action' => $this->getUrl('module/adminhtml_tabs/save')

You are telling Magento to look for a module named module, a controller aliased adminhtml_tabs, and a saveAction() method within that file.

You need to figure out where you want to send the user when a save needs to be performed, and then place it there (e.g. the route to your controller->saveAction() method).

2012-04-04 19:13
by Nick McCormack
yes i have made an action there but the button is still defaulting to the one from save customer. I have two save buttons one should go to the default action customeredit/save and the one i created should go to module/adminhtmltabs/save but the one i created goes to customer_edit/save so i don't know what im doing wrong exactly, especially since i've done this before, i tried to replicate it exactly but it did not work - changeling 2012-04-04 20:32
Ads