Symfony form event POST_SUBMIT

I’m trying to understand how event listeners in symfony forms actually work. I tried different things and I really don’t know where I’m wrong…

Here’s my form :

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('user', EntityType::class, [
            'class' => User::class,
            'label' => 'User',
            'choice_label' => 'email',
            'attr' => ['class' => 'form-control']
        ->add('submit', SubmitType::class, [
            'label' => 'Select',
            'attr' => ['class' => 'btn-primary btn-block']
        ]);
    ;
    $builder->get('user')->addEventListener(
        FormEvents::POST_SUBMIT,
        function(FormEvent $event) {
            dump($event->getData());
            dump($event->getForm());
    });
}

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults([
    ]);
}

My guess was that it would dump me some data whenever I submitted the form but it’s not dumping anything.

I tried changing the event type but only PRE_SET_DATA and POST_SET_DATA is dumping informations (null for $event->getData() though)…

Thanks for your help !

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *