zend表单验证返回false

时间:2013-02-08 22:18:14

标签: forms validation zend-framework return

我真的很困惑这个,真的需要你的帮助。 这是 AddsummonerForm.php

<?php
class Form_AddsummonerForm extends Zend_Form{
    public function __construct($options = null){
        $this->setMethod('post')
             ->setAttrib('id','standard-form')
             ->setAction($options['action'])
             ->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
        $user = Zend_Auth::getInstance()->getIdentity();

        $name = new Zend_Form_Element_Text('name');
        $name->setAttribs(array(
                                'placeholder' => "Enter the Summoner's name")
                                )
                 ->setRequired()
                 ->addErrorMessage("Please check the name.")
                 ->addValidator('StringLength',false,array(4,15))
                 ->addValidator('Alnum')
                 ->removeDecorator('label')
                 ->removeDecorator('Errors')
                 ->removeDecorator('htmlTag')
                 ->removeDecorator('DtDdWrapper');

        $regions = array("euw" => "EUW", 
                        "eune" => "EUNE", 
                        "na"=>"NA", 
                        "brazil" => "Brazil", 
                        "turkey" => "Turkey");

        $region = new Zend_Form_Element_Select('region');
        $region->addMultiOptions($regions)
                ->addErrorMessage('Please check the region.')
                ->removeDecorator('label')
                ->removeDecorator('Errors')
                ->removeDecorator('htmlTag')
                ->removeDecorator('DtDdWrapper');

        $validate = new Zend_Form_Element_File('validate');
        $validate->setDestination(APPLICATION_PATH . '/../public/images/users/'.$user->getId())
        ->addValidator('Count', false, 1)
        ->addValidator('Extension',false,'jpg,gif,png')
        ->addValidator('Size',false,1024000)
        ->addErrorMessage('Please check the file.')
        ->removeDecorator('label')
        ->removeDecorator('Errors')
        ->removeDecorator('htmlTag')
        ->removeDecorator('DtDdWrapper');

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Add')
               ->removeDecorator('DtDdWrapper');

        $this->setDecorators(array(
                                array(
                                    'ViewScript', array(
                                            'viewScript' => '_form_add_summoner.phtml'
                                            )
                                    )
                                )
                            );

        $this->addElements(array($name, $region, $validate, $submit));
    }
    }

这是一个非常常见的形式,然后控制器SummonerController与动作添加,即:

        $errors = array();
    $addForm = new Form_AddsummonerForm(array(
            'action'=> '/summoner/add')
    );

    if($this->getRequest()->isPost()){
        if($addForm->isValid($this->_request->getPost())){

            // .... code ....

        }else{
            $errorArray = $addForm->getErrors();
            foreach($errorArray as $error){
                $errors[] = $error;
            }
            $this->view->errors = $errors;
        }
    }
    $this->view->form = $addForm;

事情是,当我提交表单时,$ addForm-&gt; isValid($ this-&gt; _request-&gt; getPost()))返回false。

我尝试转储$ addForm-&gt; getMessages,$ addForm-&gt; getErrors并且它们是空的,但它仍然返回false! 有什么想法吗?

0 个答案:

没有答案
相关问题