2013-03-27 48 views
0
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)); 

問題Zend的驗證中填入(編輯表格)不工作

Server side validation not working, due to some mistake in the above snippet 

詳細信息

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. 

注意 此相同的代碼爲用戶的工作添加表單。但它無法用於編輯表單。

+1

你能發佈完整的代碼你在哪裏執行的代碼?在窗體類中添加元素? – 2013-03-27 07:10:18

+1

不要嘗試和節省空間讓我們來看看代碼,尤其是編輯操作數據流是很重要的根據你的代碼片段,你根本沒有驗證代碼。只有一個驗證器甚至出現在你的表單中'setRequired()',在你的控制器動作中什麼也沒有。 – RockyFord 2013-03-28 11:29:32

+0

@RockyFord,對不起,我已經添加這個錯誤,而不是viewHelper裝飾,仍然沒有得到驗證,有什麼spec我錯過了上面,建議plz – Bharanikumar 2013-03-28 11:42:28

回答

0

這是相當多的在Zend框架1處理的形式標準的工作流程:

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; 
    } 
} 

我希望這有助於一些。

0

該行固定我的問題

如果($形式 - >的isValid($這個 - > Request()方法 - >的getPost())