如何在嵌入式表单的后验证器(sfForm)中抛出错误
使用 Symfony 1.4 的 Forms,如何在嵌入表单的后验证器中抛出 sfValidatorError ?
我的父表单调用以下内容:
public function configure(){
$this->embedForm('page', $pageLinkForm);
}
我的嵌入表单:
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.');
}
后验证器运行 validateLink ,它会抛出 sfValidatorError 但它不会显示为全局错误,并且表单 isValid() ,但它不应该是。
为什么错误会被忽略?怎样才能让它不被忽视呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恕我直言,最好抛出一个 sfValidatorSchemaError ,如下所示:
如果您想在嵌入表单中抛出错误,只需嵌入 sfValidatorSchemaError :
IMHO it's better to throw a sfValidatorSchemaError, like this :
And if you want to throw an error inside an embedded form, just embed the sfValidatorSchemaError :
在sf1.1中我是这样做的:
我希望它对你有帮助。
in sf1.1 I do it like this:
I hope it helps you.