tôi đã và Zend Form mà thực hiện điều này:Zend Form Validator File Upload đi không hợp lệ
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)'
));
Sau đó một điều khiển mà kiểm tra bài dữ liệu:
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());
}
Và một điều gì đó giao diện tùy chỉnh điều khiển như thế này :
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
);
Khi tôi chỉ nhập một số thông tin vào trường văn bản và đăng, $ form-> isValid() không đúng. Khi tôi xóa các phần tệp khỏi biểu mẫu và chế độ xem tùy chỉnh, nó hoạt động hoàn hảo.
Formelement là 'required' false. Ngoài phần sai của bộ điều khiển -> getErrors(), getMessages() và getErrorMessages() không trả về lỗi nào ?!
Có ai biết điều gì đang xảy ra ở đây không?
Phần điều khiển không có bất kỳ tác dụng , bởi vì $ form-> isValid() trả về false. Khung nhìn là một khung nhìn tùy chỉnh và không thể được thực hiện thông qua 'echo $ this-> form'. – frgtv10