我正在创建一个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(); ?>" />