symfonydev avatar

MultiUpload of files in Symfony 3.2

symfonydev

Published: 19 Jan 2018 › Updated: 19 Jan 2018MultiUpload of files in Symfony 3.2

MultiUpload of files in Symfony 3.2

This helped tremendously:

https://github.com/marekz/example_symfony_multiply_files_example
This repo above mentioned here: https://stackoverflow.com/questions/41551183/upload-multiple-files-using-symfony-form/41551288

Only had to add this to config.yml:

# Doctrine Configuration
doctrine:
  dbal:
    server_version: '5.7'

otherwise I got:

[Doctrine\DBAL\Exception\DriverException]              
An exception occured in driver: could not find driver  



Removing __name__label__ from the data-prototype generated html code:

'entry_options' => array('label' => false)

which removes this __name__label__ from data-prototype which is then handled by the attached js to the symfony docs, which produces labels for added forms:

0label__
1label__
2label__

Form with CollectionType:

   public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->setAction($options['action'])
            ->add('comment', TextareaType::class, [
                'label' => 'request.form.labels.comment',
                'required' => false
            ])
            ->add('swFiles', CollectionType::class, [
                'entry_type' => FilesType::class,
                'entry_options' => array('label' => false),
                'label' => false,
                'label' => 'request.form.labels.files',
                'allow_add' => true,
                'by_reference' => false
            ])
     }

Form with what was entry_type above:

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('file', FileType::class, [
            'label' => false
        ]);
    }

Leave MultiUpload of files in Symfony 3.2 to:

Written by

Read more #symfony posts


Best Posts From symfonydev

We have not curated any of symfonydev's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From symfonydev