$ this-> getRequest()-> getPost()返回magento后端表单提交中的空数组 [英] $this->getRequest()->getPost() return empty array in magento back end form submission

查看:114
本文介绍了$ this-> getRequest()-> getPost()返回magento后端表单提交中的空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个magento定制管理模块和一个表单.我要更新此表单,但不更新.在Controller中的SaveAction()下,我打印$this->getRequest()->getPost()并获取空数组.请帮我.下面的代码表示格式偏斜..

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();
}

然后从

         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;
}

这是我的 SaveAction()

Here my SaveAction()

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

     }

我被绑得很厉害.有什么想法吗?

I have tied verious post. Any ideas?

推荐答案

所有人的常见错误. You just need to add form key to your form. 只需在表单声明下方添加此行即可.

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(); ?>" />

<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(); ?>" />

添加它.现在您可以通过$this->getRequest()->getPost()获取参数.

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

这篇关于$ this-&gt; getRequest()-&gt; getPost()返回magento后端表单提交中的空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆