views:

132

answers:

1

With Symfony 1.4's Forms, how can I throw a sfValidatorError in the post validator of an embedded form?

My parent form calls the following:

public function configure(){
    $this->embedForm('page', $pageLinkForm);
}

And my embedded form:

public function configure(){
    $this->validatorSchema->setPostValidator(new sfValidatorCallback(array(
        'callback' => array($this, 'validateLink')
    )));
}

public function validateLink($validator, $values) {
    if (!empty($values['link']) && !empty($values['outside_link']))
        throw new sfValidatorError($validator, 'Only specify either an internal link or an external link, but not both.');

}

The post validator runs validateLink which throws sfValidatorError but it does not show up as a global error and the form isValid(), but it shouldn't be.

Why is the error ignored? How can I make it not ignored?

A: 

Hi,

in sf1.1 I do it like this:

 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
   sfLoader::loadHelpers(array('I18N'));
   parent::bind($taintedValues, $taintedFiles);
   if($taintedValues["password"])
   {
     if(!$taintedValues["pwd_verify"])
     {
       $this->getErrorSchema()->addError(new sfValidatorError(new sfValidatorSchema(), __('Please reenter the new password.')), 'password');
     }
   }
 }

I hope it helps you.