Php zend验证在填充(编辑表单)中不起作用

Php zend验证在填充(编辑表单)中不起作用,php,zend-framework,Php,Zend Framework,问题 UserController.php ------------- editAction (method) ---------- $UserInfo = array( 'hdn_uid'=>$UserResult['user_id'], 'username'=>$UserResult['user_name'], 'firstname'=>$UserResult

问题

    UserController.php
    -------------

    editAction (method)
    ----------

    $UserInfo = array(
            'hdn_uid'=>$UserResult['user_id'],
            'username'=>$UserResult['user_name'],
            'firstname'=>$UserResult['first_name'],

        );

    $form->populate($UserInfo);
    $this->view->form = $form;


    Forms/userEdit.php
    ------------------

    $elementDecoration = array(
                'ViewHelper',
                'Description',
                'Errors',
                array(array('data'  => 'HtmlTag'), array('tag' => 'td')),
                array('Label', array('tag' => 'td', 'placement' => 'prepend')),
                array(array('row'   => 'HtmlTag'), array('tag' => 'tr')),
            );

    $hdn_id = new Zend_Form_Element_Hidden('hdn_uid');
            $hdn_id->addFilter('Int')
                   ->removeDecorator('label')
                       ->removeDecorator('HtmlTag');        

            $this->setName('login');
            $this->setDecorators($formDecoration);

            $username = new Zend_Form_Element_Text('username'); //Note this username and in conroller  $UserInfo arr 'username' matched so in the text fields existing username is populated from table.
            $username->setLabel('Username')
                    ->setDecorators($elementDecoration)
                    ->setRequired(true)
                    ->addFilter('StripTags')
                    ->addFilter('StringTrim');

$submit = new Zend_Form_Element_Submit('submit');
$submit->setDecorators($buttonDecoration);
$this->addElements(array($hdn_id,$username,$submit));
详细信息

   Server side validation not working, due to some mistake in the above snippet
注意
此代码适用于用户添加表单。但它无法用于编辑表单。

这里有一个在Zend Framework 1中处理表单的标准工作流:

 Server side validation not working in the above code, when i clear the username and if i submited the button then program does not validated the field, instead it updated the empty value into table.

我希望这能有所帮助。

这句话解决了我的问题


如果($form->isValid($this->getRequest()->getPost())

您可以发布完整的代码吗?在form类中,您在哪里执行向表单添加元素的代码?不要尝试节省空间。让我们看看代码。尤其是编辑操作。数据流很重要。根据您的代码片段,您根本没有验证代码。表单的setRequire中甚至只有一个验证程序d()'并且控制器操作中没有任何内容。@RockyFord,很抱歉,我已经在装饰中添加了此错误而不是viewHelper,但我仍然没有得到验证,上面是否有我遗漏的任何具体内容,请告知plzis,编辑操作的所有代码都是正确的?
public function editAction(){
    //set up the form
    $form = new Application_Form_UserEdit();
    $form->setMethod('post');
    $form->setAction('/user/edit');
    //test for POST array
    if ($this->getRequest()->isPost()) {
        //validate form
        if ($form->isValid($this->getRequest()->getPost()) {
            //get validated and filtered form values
            $data = $form->getValues();
            //do some stuff
        } // if form not valid it should redisplay with current data automatically
    } else {
        //if not POST display empty form
        $this->view->form = $form;
    }
}