gpt4 book ai didi

zend-framework - Zend_Form 无效但没有错误消息

转载 作者:行者123 更新时间:2023-12-04 06:47:37 26 4
gpt4 key购买 nike

我的 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) {
}
}

最佳答案

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

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

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

关于zend-framework - Zend_Form 无效但没有错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16037913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com