问题描述
有一个Magento模块,它接受一个输入并创建一个新的输入项。一切工作正常,我想添加一个领域,将输入一个图像的项目。我一定要添加相应的数据库列,并确保在每个需要的地方进行更改,但是当我通过新的输入上载图像时,图像字段不会发送到我的发布数据中。我仍然从我的表单中获得所有字段和值的对象,但File字段总是被省略。使用 $ _ FILE
试图访问它也不会产生任何结果。
这里是表单:
$ form = new Varien_Data_Form(array(
'id'=>'edit_form',
'action'=> ; $ this-> getUrl('* / * / edit',array('embroidery_id'=> $ this-> getRequest() - > getParam('embroidery_id'))),
' '=>'post',
'enctype'=>'multipart / form-data'
));
$ form-> setUseContainer(true);
$ this-> setForm($ form);
$ b $ fieldset = $ form-> addFieldset(
'general',
array(
'legend'=> $ this-> __('详情')
)
);
以下是字段:
<$ p ($ b $ name'=> array(
'label'=> $ this-> __($ field); $ this $> _addFieldsToFieldset '$ name'),
'input'=>'text',
'required'=> true,
),
'file_t'=> array(
'label'=> $ this-> __('File path'),
'required'=> false,
'class'=>'disable',
'input'=>'file',
'name'=>'file_t',
'value'=>'file_t',
),
));
任何帮助或指导将不胜感激。我已经做了一些谷歌搜索,并查看所有顶部的结果添加在一个文件上传领域,我复制了一些代码,但文件输入后栏仍是空的。
澄清:
$ b $ _addFieldsToFieldset
函数只是循环遍历字段数组,并填充它们与数据或将该字段添加到 $ fieldset
变量。我也尝试用下面的代码直接添加字段到变量,但它也不起作用。 addField('file_t','file',array(
'label'=> $ this-> __('File path'),
'required'=> false,
'name'=>'file_t',
));
这是处理保存的函数。这个函数可以工作,当我提交其他表单时,它已经被多次尝试和测试过,并且所有的字段都被成功的保存了,并且所有的东西都被发送过来了,但是每当我添加文件字段的时候,而且一切仍然有效,它只是不通过文章发送文件字段。
if(isset($ _ FILES ['file_t '] ['name'])){
echo'TRUE';
}
var_dump($ this-> getRequest() - > getPost());出口();
$ em-> addData($ postData);
$ em-> save();
$ this-> _getSession() - > addSuccess(
$ this-> __('刺绣已被保存。')
);
//重定向从请求中删除$ _POST数据
返回$ this-> _redirect(
'mu_em_admin / embroidery / edit',
array(' embroidery_id'=> $ em-> getID())
);
我简化了很多代码,只包含了重要的部分。我还有 var_dump
函数来解决代码问题。 var_dump
的结果是发送的整个post数组,除了文件字段外。
你使用什么网页浏览器,以及哪个版本的php?
have a Magento module that takes an input and creates a new item off that input. Everything works fine, and I wanted to add a field that would input an image with the item. I made sure to add the corresponding database column, and made sure to make the change every where it would be needed, but when i upload an image through the new input the image field does not send in my post data. I still get an object with all the fields and values from my form but the File field is always omitted. Using $_FILE
to try to access it yields nothing also.
Here is the form:
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/edit', array('embroidery_id' => $this->getRequest()->getParam('embroidery_id'))),
'method' => 'post',
'enctype' => 'multipart/form-data'
));
$form->setUseContainer(true);
$this->setForm($form);
$fieldset = $form->addFieldset(
'general',
array(
'legend' => $this->__('Details')
)
);
And here are the fields:
$this->_addFieldsToFieldset($fieldset, array(
'name' => array(
'label' => $this->__('Name'),
'input' => 'text',
'required' => true,
),
'file_t' => array(
'label' => $this->__('File path'),
'required' => false,
'class' => 'disable',
'input' => 'file',
'name' => 'file_t',
'value' => 'file_t',
),
));
Any help or guidance would be appreciated. i already did some googling and looked at all the top results for adding in a file upload field, and I copied some of the code exactly but the post field for the file input is still empty.
For Clarification:
The _addFieldsToFieldset
function just loops through the fields array and either fills them in with data or adds the field onto the $fieldset
variable. I also tried adding the field straight onto the variable with the following code but it did not work also.
$fieldset->addField('file_t', 'file', array(
'label' => $this->__('File path'),
'required' => false,
'name' => 'file_t',
));
Here is the function that handles the saving. This function does work, it has been tried and tested multiple times when I submitted other forms, and all the fields were successfully saved, and everything was sent through, but whenever I add the file field on, the post data looks exactly the same, and everything still works, it just does not send the file field through the post.
if(isset($_FILES['file_t']['name'])){
echo 'TRUE';
}
var_dump($this->getRequest()->getPost()); exit();
$em->addData($postData);
$em->save();
$this->_getSession()->addSuccess(
$this->__('The embroidery has been saved.')
);
// redirect to remove $_POST data from the request
return $this->_redirect(
'mu_em_admin/embroidery/edit',
array('embroidery_id' => $em->getID())
);
I simplified alot of the code down to only include the important parts. I also have the var_dump
function there to troubleshoot the code. The results of var_dump
were the whole post array that was sent, except for the file field.
please try to put this form before body end and then submit.
what web browser do you use, and which version of php?
这篇关于Magnento模块文件上传不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!