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

2

8

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?

Garbo answered 3/12, 2013 at 11:50 Comment(5)
I cannot see any fields in your form. Add full code of _prepareForm() method to your question.Keary
I have been added the full code.Garbo
remove echo from the saveAction(), print_r is sufficient to print the array on browser, may be the array is there but echo is the culprit.Terti
I am also facing same issue. Has someone found solution for this?Nonpros
I have same issue @supravatSelfrighteous
S
6

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

Stiffnecked answered 9/4, 2014 at 7:13 Comment(3)
Kingshuk ,this form have already added form_key field automatically but not working .Selfrighteous
paste your form and also the controller you are usingStiffnecked
@AmitBera was you able to solve the issue. I am having the same issue. Formkey is automatically generated but the post is emptyMuch
D
1

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  
Declinature answered 4/5, 2017 at 6:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.