我有个问题.我需要在表单类型类中验证不在实体中的字段.以前我用过这段代码:
$builder->addValidator(new CallbackValidator(function(FormInterface $form){ if (!$form['t_and_c']->getData()) { $form->addError(new FormError('Please accept the terms and conditions in order to registe')); } }))
但是,因为不推荐使用Symfony 2.1方法addValidator和类CallbackValidator.有谁知道我应该用什么呢?
我这样做了:
add('t_and_c','checkBox',array( 'property_path' => false,'constraints' => new True(array('message' => 'Please accept the terms and conditions in order to register')),'label' => 'I agree'))