Zend_Form无效但没有错误消息

时间:2013-04-16 13:07:35

标签: zend-framework validation zend-form

我的一个Zend_Forms出现了一个奇怪的问题:isValid()正确地说明我的表单无效但我没有收到任何错误消息。怎么会发生这种情况?

这是代码,这里没什么特别的。 $data是一组帖子数据。没有文件被发送时会出现问题。

    $form = $this->getForm('Foto');
    if(!$form->isValid($data)) {
        var_dump( $form->getErrors() ); die;
        return false;
    }
如果还没有完成,

getForm()会初始化表单。表格本身非常直接。

class Media_Forms_Foto extends Zend_Form
{
    /**
     * Initializer function. Setup forms fields.
     */
    public function init()
    {
        $this->setName('add Image');
        $this->setAction('media/gallery/addImage');

        $this->addElement('Hidden', 'gallery', array(
            'filters'    => array(),
            'validators' => array('Digits'),
            'required'   => false,
            'label'      => '',
        ));

        $this->addElement('File', 'foto', array(
            'required'      => true,
            'destination'   => ROOT_PATH .'public/upload/tmp/',
            'label'         => 'Foto',
            'validators'    => array(
                new Zend_Validate_File_IsImage(array(
                    'image/jpeg', 'image/gif', 'image/png'
                ))
            ),
            'maxFileSize'   => 2097152,
        ));

        $this->addElement('Submit', 'add', array(
            'required' => false,
            'ignore'   => true,
            'label'    => 'add Foto',
        ));

        $this->setAttrib('enctype', 'multipart/form-data');
    }
}

输出:

array(3) {
    ["gallery"]=>
        array(0) {
        }
    ["foto"]=>
        array(0) {
        }
    ["add"]=>
        array(0) {
        }
}

1 个答案:

答案 0 :(得分:-4)

您是否有机会使用jquery表单插件?如果是这样,请尝试使用iframe模式上传文件:

var options = {
    url: '/test/upload',
    success: function(response) {
    },
    beforeSubmit: disableSubmitButtons,
    iframe: true,
    dataType : 'json'
};

$('#testForm').ajaxForm(options);