我创建了一个简单的上传表格,在提交数据时遇到了一些问题。
文件已正确上传,但我的小描述字段保持为空。
这是我的表格:
class Upload_Form_Uploadvideo extends Zend_Form{
public function init()
{
$this->setName('video')
->setAction('interface/videoupload')
->setMethod('post');
#id
$id = new Zend_Form_Element_Hidden('id');
$id->addFilter('Int');
#Textfield "Videofile"
$video = new Zend_Form_Element_File('videofile', array(
'label' => 'Videofile')
);
$video->setDestination(APPLICATION_PATH.'/upload/video/toConvert/');
#Textfield "Videofile"
$desc = new Zend_Form_Element_Text('videodescription', array(
'label' => 'Description')
);
$desc->setAttrib('value','The description is not optional!');
$desc->setAttrib('size','25');
#Submit
$submit = new Zend_Form_Element_Submit('submit', array('label' => 'Upload Video'));
$submit->setAttrib('id', 'submitbutton');
#bringing everything together
$this->addElements(array($id,$video,$desc,$submit));
}
}
控制器,将其提供给视图:
public function videouploadAction()
{
#in production this code goes to the index()
if(!$this->getRequest()->isPost()){
return $this->_forward('index');
}
$form = $this->getForm();
$this->view->via_getpost = var_dump($this->_request->getPost());
$this->view->via_getvalues= var_dump($form->getValues());
}
现在,我var_dump $ this-> _request-> getPost()和$ form-> getValues()。
输出如下:
array[$this->_request->getPost()]
'id' => string '0' (length=1)
'MAX_FILE_SIZE' => string '134217728' (length=9)
'videodescription' => string 'This is a test-video' (length=20)
'submit' => string 'Upload Video' (length=12)
array [$form->getValues()]
'id' => int 0
'videofile' => string 'swipeall.avi' (length=12)
'videodescription' => null
另外,我设置了“value”-attrib,没有任何影响。当用户加载网站时,我打算在框中写一些东西。
我是Zend的新手,所以我想我只是在监督一些愚蠢的事情,虽然我找不到它。
更新
我真的必须通过
获得$ _POST-Data$formdata = $this->getRequest()->getPost();
答案 0 :(得分:3)
使用
$desc->setValue('The description is not optional!');
而不是
$desc->setAttrib('value','The description is not optional!');