在 Symfony 中为 sfValidatorOr 添加错误
我有:
$this->validatorSchema->setPostValidator(new sfValidatorOr(
array(
new sfValidatorSchemaCompare('email', '!=', ''),
new sfValidatorSchemaCompare('phone', '!=', ''),
),
array(),
array('invalid' => 'Campo obligatorio')
));
错误在 $form->getGlobalErrors() 中。我如何添加
array('throw_global_error' => true),
与此处相同:
$this->validatorSchema->setPostValidator(
new sfValidatorOr(
array(
new sfValidatorAnd(
array(
new sfValidatorSchemaCompare('date_from', sfValidatorSchemaCompare::EQUAL, 'date_to',
array('throw_global_error' => true),
array('invalid' => 'The start date ("%left_field%") must be equal the end date ("%right_field%")')),
new sfValidatorSchemaCompare('time_from', sfValidatorSchemaCompare::LESS_THAN, 'time_to',
array('throw_global_error' => true),
array('invalid' => 'The start time ("%left_field%") must be before the end time ("%right_field%")')),
)),
new sfValidatorSchemaCompare('date_from', sfValidatorSchemaCompare::LESS_THAN, 'date_to',
array('throw_global_error' => true),
array('invalid' => 'The start date ("%left_field%") must be before the end date ("%right_field%")')),
)
));
?
我将渲染这个:
<?php $form['email']->renderLabel() ?>
**<?php echo $form['email']->getError() ?>**
但是在 sfValidatorOr 中这不起作用
I have:
$this->validatorSchema->setPostValidator(new sfValidatorOr(
array(
new sfValidatorSchemaCompare('email', '!=', ''),
new sfValidatorSchemaCompare('phone', '!=', ''),
),
array(),
array('invalid' => 'Campo obligatorio')
));
Error is in $form->getGlobalErrors(). How can i add
array('throw_global_error' => true),
same as here:
$this->validatorSchema->setPostValidator(
new sfValidatorOr(
array(
new sfValidatorAnd(
array(
new sfValidatorSchemaCompare('date_from', sfValidatorSchemaCompare::EQUAL, 'date_to',
array('throw_global_error' => true),
array('invalid' => 'The start date ("%left_field%") must be equal the end date ("%right_field%")')),
new sfValidatorSchemaCompare('time_from', sfValidatorSchemaCompare::LESS_THAN, 'time_to',
array('throw_global_error' => true),
array('invalid' => 'The start time ("%left_field%") must be before the end time ("%right_field%")')),
)),
new sfValidatorSchemaCompare('date_from', sfValidatorSchemaCompare::LESS_THAN, 'date_to',
array('throw_global_error' => true),
array('invalid' => 'The start date ("%left_field%") must be before the end date ("%right_field%")')),
)
));
?
i will render this :
<?php $form['email']->renderLabel() ?>
**<?php echo $form['email']->getError() ?>**
but in sfValidatorOr this doesn't work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 throw_global_error 选项直接放在 sfValidatorSchemaCompare() 上。
无法将其放在 sfValidatorOr 上,因为它不是 sfValidatorSchema 对象。
You can put the throw_global_error option directly on sfValidatorSchemaCompare().
There is no way to put it on the sfValidatorOr as it's not a sfValidatorSchema object.