$ this-> getRequest() - > getPost()在magento后端表单提交中返回空数组

时间:2013-12-03 11:50:50

标签: forms magento magento-1.7

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

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

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

     }

我绑了一个很好的帖子。有什么想法吗?

2 个答案:

答案 0 :(得分:6)

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

<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()获取参数。

答案 1 :(得分:1)

你可以使用$ this-&gt; getRequest() - &gt; getParams();获取magento中的post和get方法的变量getParams()方法但是如果你想获得一些可变数据,那么使用getParam('id');

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

$this->getRequest()->getParams(); //get all get and post variables