Thursday, September 6, 2012

Post Validator in Symfony

  public function configure()
  {
    $this->getValidator('day')->setOption('required', 'true');
    
    $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
      new sfValidatorCallback(array('callback' => array($this, 'checkFields'))),
    )));
  }
  
  public function checkFields($validator, $values)
  {
    if(empty($values['manufacturer']) && empty($values['category_apollo_kod']) && empty($values['product_apollo_kod']))
    {
      throw new sfValidatorErrorSchema($validator, array('manufacturer' => new sfValidatorError($validator, 'custom error')));
    }
     
    return $values;
  }

No comments:

Post a Comment