Question

POST_SET_DATA is supposed to be used to add or modify values to a form after submitting it, but I dont know exactly how to use it..

I have this code: http://pastebin.com/E9V9QHFn but I get NULL end, and it is for sure that data form is being submitted.

Here the code:

        //CustomerType.php
        $builder->addEventListener(
            FormEvents::POST_SET_DATA,
            function(FormEvent $event) {
                $form = $event->getForm();
                $data = $event->getData();
                var_dump($data);
                die("end");
            }
        );

Im following this.

My target this time is to set the value of a foreign key defined in the entity but not shown in the form, exactly the id of the logged user.

Was it helpful?

Solution

you have to try this

  $builder->addEventListener(
        FormEvents::POST_SUBMIT,
        function(FormEvent $event) {
            $form = $event->getForm();
            $data = $form->getData();
            var_dump($data);
            die("end");
        }
    );

you've called getData() into the FormEvent. to get data you have to make $form->getData().

sorry im talking about your EventListener:

            $data = $form->getData();

not

            $data = $event->getData();

To get submitted data use PRE_SUBMIT/POST_SUBMIT instead of POST_SET_DATA

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top