简体   繁体   中英

Retrieve unmapped data from eventlistener in symfony form

I am currently creating a form that is supposed to retrieve the unmapped data to treat them before they are added to the database. How can I retrieve the unmapped data in the eventlistener? Here is my formtype code:

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {

        $builder
            ->add('currentState', ChoiceType::class, [
                'choices'  => [
                    'Disponible' => 1,
                    'Hors service' => 2,
                    'Réservé' => 3
                ],
            ])
            [...
            ->add('combination_reference', TextType::class, [
                'label'=>'Référence de la déclinaison',
                'mapped'=>false,
                'attr'=>[
                    'class'=>'form-control mb-2',
                    'placeholder'=>'Référence de la déclinaison'
                ]
            ])
            ->addEventListener(FormEvents::SUBMIT, function(FormEvent $formEvent){
                [retrieve unmapped data (combination_reference) here]
            })
        ;
     }
    public function configureOptions(OptionsResolver $resolver): void
    {

        $resolver->setDefaults([
            'data_class' => PhysicalProduct::class,
            "allow_extra_fields" => true
        ]);
    }




You can access underlying unmapped data as follows

$form = $formEvent->getForm();
$combinationReference = $form->get('combination_reference')->getData();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM