0

私はこれについて本当に混乱しています。本当にあなたの助けが必要です。ここに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));
    }
    }

これは非常に一般的な形式であり、次にアクション add を持つコントローラー 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->isValid($this->_request->getPost())) が false を返すことです。

$addForm->getMessages,$addForm->getErrors をダンプしようとしましたが、それらは空ですが、それでも false が返されます! 何か案は?

4

0 に答える 0