1

I'm trying to set up a form with a FileType field with the multiple option enabled, but if I upload one by one, when submited it only sends the last one to the controller.
I would like to send every file that has been added to the input when submitted. Is there any way to send them?

My form field

class AnadirBarcoFotosForm extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {   
        $builder              
        ->add('imagenes', FileType::class,[
            'label' => false,
            'multiple' => true,
            'required' => false
        ])
        ->add('Guardar', SubmitType::class, [
            'attr'  =>  [
                'class' => 'btn btn-secondary float-right boton-marron'
            ]
        ])
        ;
    }
   
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([

        ]);
    }
}

Controller


$paramAnadirBarcoFotos = array();
$anadirBarcoFotosForm = $this->createForm(AnadirBarcoFotosForm::class, $paramAnadirBarcoFotos);
$anadirBarcoFotosForm->handleRequest($request);

if ($anadirBarcoFotosForm->isSubmitted() && $anadirBarcoFotosForm->isValid()){
    $datosAnadirBarcoFotos = $anadirBarcoFotosForm->getData();
...
6
  • Can you show your controller method and (relevant parts of) the data class? I think we're missing some details to answer this question. Commented Jul 22, 2021 at 14:45
  • What do you mean the data class, in the form code you can see it has no data class, and in the controller I create the form with an empty array because it doesn't use any entity as data class. When I dump what ->getData() returns, if uploaded one by one, it only returns the last one, when the field has multiple enabled. I think I'm not missing any important detail, but I can be wrong of course. Thank you for your time anyway :) Commented Jul 22, 2021 at 18:43
  • This is a matter of debugging. Are you seeing multiple files when dumping $request? Commented Jul 22, 2021 at 18:46
  • When dumping, I see only the last upload, that means, if i upload 1 file and then 5 files at once, I see those last 5 files, but if I upload 3 files one by one, I only recieve the 3rd one Commented Jul 25, 2021 at 19:27
  • And what is the result of $datosAnadirBarcoFotos? Commented Jul 25, 2021 at 20:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.