Zend framework Zend表单验证程序文件上载无效

Zend framework Zend表单验证程序文件上载无效,zend-framework,zend-form,zend-validate,Zend Framework,Zend Form,Zend Validate,我得到了Zend表格,它可以: class Products_AddForm extends Zend_Form { public function init() { $ProductImage1 = $mainform->addElement('file', 'Productimage1', array( 'validators' => array(

我得到了Zend表格,它可以:

 class Products_AddForm extends Zend_Form {
  public function init() {

    $ProductImage1 = $mainform->addElement('file', 'Productimage1',     array(
                               'validators' => array(
                                    array('Count', false, '1' ),
                                    array('Size', false, '10MB'),
                                    array('Extension', false, 'jpg,jpeg,tif,eps'),
                                ),
                                'required'   => false,
                                'label' => 'Product Image1 (jpg/tif/eps)'
            ));
然后是检查post数据的控制器:

public function addAction()
{

    $form = $this->getAddForm();

    if($this->getRequest()->isPost()){

        $post =  $this->getRequest()->getPost();

        // check post data
        if($form->isValid($post) )
        { 
        }
        else {
            print_r($form->getErrors());
            print_r($form->getErrorMessages());
            print_r($form->getMessages());
        }
还有一个自定义视图控制器,如下所示:

echo '<form method="post" action="'.$this->baseUrl('products/add').'" enctype="multipart/form-data">';

            $image1 = $form->getElement('Productimage1');

            $helper1 = $image1->helper;
            echo '<br/>'.$this->translate('Productimage').' (jpg/tif):<br/>'.$bild1->getView()->$helper1(
            $image1->getName(),
            $image1->getValue(),
            $image1->getAttribs(),
            $image1->options
            );
echo';
$image1=$form->getElement('Productimage1');
$helper1=$image1->helper;
回显“
”。$this->translate('Productimage')。(jpg/tif):
”。$bild1->getView()->$helper1( $image1->getName(), $image1->getValue(), $image1->getAttribs(), $image1->选项 );
当我只是在文本字段中键入一些信息并发布时,$form->isValid()变为false。 当我从表单和自定义视图中删除文件部分时,它可以完美地工作

Formelement处于“必需”状态。错误。 此外,控制器->getErrors()、getMessages()和getErrorMessages()的false部分没有返回错误

有人知道这里发生了什么吗?

试试这样: 这是您的表格:

   $image = $this->createElement('file','image');
            $image->setLabel('Product Image1 (jpg/tif/eps) ')
                  ->setRequired(false)
                  ->setDestination(??)
                  ->addValidator('Count',false,1)
                  ->addValidator('Size',false,10MB)
                  ->addValidator('Extension',false,'jpg,tif,eps');
            $this->addElement($image);
这是您的控制器:

$form = new Application_Form_YOURFORM(array('action' => '', 'method' => 'POST'));
        if($this->_request->isPost() && $form->isValid($this->_request->getPost()))
        {
            if($form->image->isUploaded())
            {
                $form->image->receive();
                $this->image = 'destination' . basename($form->image->getFileName());
            }
            $this->_helper->redirector('..');
        }
        else
        {
            $this->view->form = $form;
        }
你的看法:

<?php echo $this->form ?>

控制器部分没有任何效果,因为$form->isValid()返回false。该视图是自定义视图,无法通过
echo$this->form
完成。