2011-06-26 96 views

回答

1

你需要使用一個回調來驗證表單...例如:

public function configure() 
{ 
    $this->widgetSchema['email'] = new sfWidgetFormInput(); 
    $this->validatorSchema['email'] = new sfValidatorEmail(array('required' => true)); 

    $this->validatorSchema->setPostValidator(
    new sfValidatorCallback(array('callback' => array($this, 'postValidate'))) 
); 
} 

public function postValidate($validator, $values)  
{ 
    // only run the post validator if the email has passed validation 
    // if it hasn't passed validation, it will be blank and we can skip this 
    if ($values['email']) 
    { 
    $v = new myPostValidator(); 
    $v->clean($values); 
    } 

    return $values; 
} 
0

這取決於你的意思是用「正常」和後驗證什麼:

在動作類,您可以使用條件:

if ($form->isValid()) { // code here before and after the save(); } 

還是你的動作使用postExecute?

+0

「正常」驗證程序是附加到每個窗口小部件的驗證程序,後驗證程序是使用setPostValidator()設置的驗證程序 – tamir