G
G
gmark2015-10-21 03:54:30
symfony
gmark, 2015-10-21 03:54:30

How to implement custom field validation with mapped false in symfony2?

Symfony version 2.7 In my form class inherited from AbstractFormType, a field is added
in the buildForm(FormBuilderInterface $builder, array $options) method

$builder->add('passport_media', new OrderPassportMediaType(), [
            'label' => 'Скан паспорта', 'mapped' => false, 'required' => true, 'property_path' => null
        ]);

This is a picture. I validate the entire form with the help of a licener
$builder->addEventListener(FormEvents::POST_SUBMIT, array($this, 'orderListener'));

This of course does not work for the passport_media field. How can I validate so that the field behaves like fields with mapped true? I just want to display an error if the user hasn't uploaded a file.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2015-10-21
@gmark

Lots of options...
1. mapped true (Just adding a field to the entity)
2. Listener (PRE_SUBMIT and other events)
3. As Aleksey Romanenko
suggested 4. ...
In general, file uploads should not intersect with the entity. That is, the entity and the loading process must exist separately. This will make it easier to both work with the entity and work with the file. (But these are the details)

G
gmark, 2015-10-21
@gmark

Thanks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question