Symfony 1.4中是否有一种简单的方法可以知道提交的表单在表单类中是否有任何错误?我熟悉$form['some_field']->hasErrors()
模板,但在这种情况下,我只想在表单没有标准验证器的任何错误的情况下运行后验证器。我基本上喜欢这样的事情:
public function configure() {
// widgets
// standard validators
if (!this->hasErrors()) {
// run post-validator
}
}
API文档与往常一样神秘。提前谢谢。
答案 0 :(得分:2)
由于bind
调用验证已经完成,我没有看到错误地发布验证的其他位置,而不是bind
函数。所以,在你的表单类中:
public function bind(array $taintedValues = null, array $taintedFiles = null)
{
parent::bind($taintedValues, $taintedFiles);
if ($this->hasErrors())
{
// do post validate
// you can access values from your form using $taintedValues
}
}
但是你必须手动调用验证器而不是仅仅定义一个验证器(因为绑定过程已经完成)。