Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$this->getRequest()->getPost() return empty array in magento back end form submission

I am creating a magento custom admin module and a form. I want update this form but not updating. In Controller, under SaveAction() I print $this->getRequest()->getPost() and get empty array. please help me. Below code for form declination..

     protected function _prepareForm() {
    $form = new Varien_Data_Form(array(
                'id' => 'edit_form1',
                'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
                'method' => 'post',
                'enctype' => 'multipart/form-data'
                    )
    );

    $form->setUseContainer(true);
    $this->setForm($form);
    return parent::_prepareForm();
}

And Create a from filed set like

         protected function _prepareForm() {
    $form = new Varien_Data_Form();
    $this->setForm($form);
    $fieldset = $form->addFieldset('qbanner_form', array('legend' => Mage::helper('qbanner')->__('Art  information')));

    $fieldset->addField('name', 'text', array(
        'label' => Mage::helper('catalog')->__('Product'),
        'required' => false,
        'name' => 'name',
    ));
    $fieldset->addField('artist_name', 'text', array(
        'label' => Mage::helper('catalog')->__('Artist Name'),
       // 'name' => 'artist_name',
        'value' => Mage::helper('catalog')->__('Art Name value'),
    ));
    $fieldset->addField('bca_status', 'select', array(
        'label' => Mage::helper('catalog')->__('Art status'),
        'name' => 'bca_status',
        'values' =>$this->_getAttributeOptions('bca_status'),
    ));
    $fieldset->addField('reason', 'editor', array(
      'name'      => 'reason',
      'label'     => Mage::helper('catalog')->__('Reason'),
      'title'     => Mage::helper('catalog')->__('Reason'),
      'style'     => 'width:440px; height:300px;',
      'wysiwyg'   => true,
      'required'  => false,
  ));
  $fieldset->addField('thumbnail', 'text', array(
        'label' => Mage::helper('catalog')->__('Art status'),
        'name' => 'thumbnail',
        //'values' =>$this->_getAttributeOptions('thumbnail'),
        //'renderer' => 'Qaz_Qbanner_Block_Adminhtml_Qbanner_Grid_Renderer_Image'
    ));

    if (Mage::getSingleton('adminhtml/session')->getQbannerData()) {
        $form->setValues(Mage::getSingleton('adminhtml/session')->getQbannerData());
        Mage::getSingleton('adminhtml/session')->setQbannerData(null);
    } elseif (Mage::registry('qbanner_data')) {
        $form->setValues(Mage::registry('qbanner_data')->getData());
    }
    return parent::_prepareForm();
}
    protected function _getAttributeOptions($attribute_code)
{
    $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute_code);
    $options = array();
    foreach( $attribute->getSource()->getAllOptions(true, true) as $option ) {
        $options[$option['value']] = $option['label'];
    }
    return $options;
}

Here my SaveAction()

      public function saveAction() {
             echo print_r( $this->getRequest()->getPost());

     }

I have tied verious post. Any ideas?

like image 983
Supravat Mondal Avatar asked Dec 03 '13 11:12

Supravat Mondal


2 Answers

Common error for all. You just need to add form key to your form. Just add this line below your form declaration.

<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />

Like this

<form action="<?php echo Mage::helper("adminhtml")->getUrl("demo/adminhtml_demo/demo");?>" method="post" id="custom-payment-form" enctype="multipart/form-data">
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />

Add this. Now you can get parameters by $this->getRequest()->getPost().

like image 143
Kingshuk Deb Avatar answered Sep 17 '22 16:09

Kingshuk Deb


you can get variable of post and get method in magento with $this->getRequest()->getParams(); getParams() method But if you want to get exactly some variable data then use getParam('id');

/magento/catalog/product/view/id/406/category/14
 $this->getRequest()->getParam('id')    // 406

$this->getRequest()->getParams(); //get all get and post variables  
like image 23
Savoo Avatar answered Sep 18 '22 16:09

Savoo