微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在创建一个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',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','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());

     }

我已经捆绑了很好的帖子.有任何想法吗?

解决方法

所有人的常见错误.您只需要在表单中添加表单密钥即可.
只需在表单声明下方添加此行即可.
<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()获取参数.

原文地址:https://www.jb51.cc/html/227226.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐