Symfony2 custom field & validator
Uses:
use Symfony\Component\Form\CallbackValidator;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormError;
... some code
$builder ->add('custom_field', 'text', array(
'mapped' => false,
));
$callback = function(FormInterface $form) {
if ($form['custom_field']->getData() == 'something' )
{
$form->addError(new FormError('Oops ! Error Message'));
}
};
$builder->addValidator(new CallbackValidator($callback));
some code...
symfony v. 2.1
Written by Isaac Limon G.
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#