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

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

这里我的
保存 Action ()
      public function saveAction() {
             echo print_r( $this->getRequest()->getPost());

     }

我已经绑定(bind)了verious post。有任何想法吗?

最佳答案

所有人的共同错误。 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()获取参数.

关于forms - $this->getRequest()->getPost() 在magento后端表单提交中返回空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20350387/

相关文章:

php - 在 2 个服务器节点(1 个前端,1 个后端)上运行 Magento CE 1.7

PHP\MYSQL\AJAX(?) - 挣扎于如何在不调用页面刷新的情况下动态更新表单

javascript - 带有提交按钮的表单内的 onClick 函数会导致错误

Magento 所有链接都以/index.php/开头,而不仅仅是/- 为什么?

css - 如何左对齐来 self 的 Magento 商店页脚处的 cms block 的 IMG 元素

Magento 1.7 - 在网格中显示订单数量,不带小数

mysql - 除了html之外我一无所知。我如何使该表格发挥作用?

forms - 如何在 magento 2 结帐、街道地址字段上添加工具提示?

magento - 您的凭据不允许访问此资源 [code] => 220

Magento 自定义排序选项