2013-10-10 39 views
0

我在symfony 1.4中創建了一個丟失的密碼錶單,並且遇到了即使小部件約束失敗也會調用post驗證器的問題。Symfony 1.4 - 強制symfony在到達驗證器之前停止執行

段:

$this->validatorSchema['email_address'] = new sfValidatorEmail(
    array(
     'max_length' => 254, // http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690 
     'min_length' => 4, 
     'required'  => true, 
     'trim'   => true 
    ), 
    array(
     'invalid'  => 'Email address entered is malformed', 
     'max_length' => 'Email Address cannot contain more than %max_length% characters', 
     'min_length' => 'Email Address must be at least %min_length% characters', 
     'required'  => 'Please enter an email address' 
    ) 
); 

$this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'emailValidate')))); 
$this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'throttleCheck')))); 

的問題是「emailValidate」回調呈現出良好形成的電子郵件地址已輸入,像[email protected],但如果我進入垃圾,像「fdadfaa」,當它不應該的時候,表單仍然繼續嘗試執行驗證器。如果數據不好,沒有理由發出查詢。

我一個'halt_on_error'標誌可以傳遞給模式驗證器的構造函數,但並不適用於我。其他人穿過這座橋?

回答

0

的Symfony是一個瘋狂之旅......能得到它來工作,這樣的:

$this->validatorSchema['email_address'] = new sfValidatorAnd(
    array(
     new sfValidatorEmail(
      array(
       'max_length' => 254, // http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690 
       'min_length' => 4, 
       'required'  => true, 
       'trim'   => true 
      ), 
      array(
       'invalid'  => 'Email address entered is malformed', 
       'max_length' => 'Email Address cannot contain more than %max_length% characters', 
       'min_length' => 'Email Address must be at least %min_length% characters'       
      ) 
     ), 
     new sfValidatorCallback(array('callback' => array($this, 'emailValidate'))), 
     new sfValidatorCallback(array('callback' => array($this, 'throttleCheck'))) 
    ), 
    array('halt_on_error' => true), 
    array('required' => 'Please enter an email address') 
); 

這裏唯一的問題,postValidators直接連到電子郵件字段,所以你必須改變任何參考文獻$values['email']$values。但它似乎在敲擊驗證器之前停止執行流程。