Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3928

How to prefill form values with Symfony 4 form listeners?

$
0
0

I would like to prefill form values from a form event listener.

I tried this, but nothing happens:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    /* ...*/

    $builder->addEventListener(
        FormEvents::PRE_SET_DATA,
        [$this, 'onPreSetData']
    );
}

public function onPreSetData(FormEvent $event)
{
   $event->getForm()->get('myfield')->setData('my value');
}

Thanks all!

Alexander


Viewing all articles
Browse latest Browse all 3928

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>