2
votes

As I know I could create form using form type: $form = $this->createForm(new RegistrationType(), $user);

And here is form type:

class RegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', 'text');
        $builder->add('email', 'email');

        $builder->add('terms', 'checkbox', array(
            'mapped' => false
        ));
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'App\UsersBundle\Entity\User'
        ));
    }

    public function getName()
    {
        return 'user_registration';
    }

}

So I could add field term and don't map it to entity. But what is the way to validate this field? Sure I can do something like if ($form->get('terms')->getData()) in my controller but I want to use one function $form->isValid() to validate all fields (mapped and don't mapped)? May be any validate hooks or events exists?

1

1 Answers