javascript - Dropzone.js and symfony formbuilder - Stack Overflow

I'm trying to handle dropzone.js to work correct with my entity symfony formbuilder.Everything wor

I'm trying to handle dropzone.js to work correct with my entity symfony formbuilder.

Everything works properly if I'm using simple <input type="file" id="form_file" name="form[file]">

BUT if I'm using dropzone.js I get this difference in my POST:

How I can handle it?

This is my js for it:

Dropzone.options.myAwesomeDropzone = { 
                autoProcessQueue: false,
                uploadMultiple: true,
                parallelUploads: 25,
                maxFiles: 25,

                init: function() {
                    var myDropzone = this;

                    $("#submit-all").click(function (e) {
                                e.preventDefault();
                                e.stopPropagation();
                                myDropzone.processQueue();
                            }
                    );

                }

            }

My form file looks like:

    <form id="my-awesome-dropzone" class="wizard-big dropzone" action="{{ path('add') }}" method="post"  {{ form_enctype(form) }}>
    {{ form_widget(form.name, {'attr': { 'class': 'form-control' } }) }}
    <div class="row">
        <div class="dropzone-previews"></div>
        <div class="fallback"> 
         {{ form_widget(form.file, {'attr': { 'class': 'cotam' } }) }}
        </div>
        </div>
<button type="submit" id="submit-all" class="btn">Upload the file</button>
    {{ form_rest(form) }}
    </form>

And my controller:

public function addAction(Request $Request) {

        $photo = new Photo();

        $form = $this->createFormBuilder($photo)
            ->add('name')
            ->add('file')
            ->getForm();

        $form->handleRequest($Request);

        if ($form->isValid() && $Request->isMethod('POST')) {

            $em = $this->getDoctrine()->getManager();

            $em->persist($photo);
            $em->flush();

            $this->redirect($this->generateUrl('add'));
        }



        return $this->render('MyBundle::add.html.twig', array(
            'form' => $form->createView()
        ));
    }

Could You help me?

I'm trying to handle dropzone.js to work correct with my entity symfony formbuilder.

Everything works properly if I'm using simple <input type="file" id="form_file" name="form[file]">

BUT if I'm using dropzone.js I get this difference in my POST:

How I can handle it?

This is my js for it:

Dropzone.options.myAwesomeDropzone = { 
                autoProcessQueue: false,
                uploadMultiple: true,
                parallelUploads: 25,
                maxFiles: 25,

                init: function() {
                    var myDropzone = this;

                    $("#submit-all").click(function (e) {
                                e.preventDefault();
                                e.stopPropagation();
                                myDropzone.processQueue();
                            }
                    );

                }

            }

My form file looks like:

    <form id="my-awesome-dropzone" class="wizard-big dropzone" action="{{ path('add') }}" method="post"  {{ form_enctype(form) }}>
    {{ form_widget(form.name, {'attr': { 'class': 'form-control' } }) }}
    <div class="row">
        <div class="dropzone-previews"></div>
        <div class="fallback"> 
         {{ form_widget(form.file, {'attr': { 'class': 'cotam' } }) }}
        </div>
        </div>
<button type="submit" id="submit-all" class="btn">Upload the file</button>
    {{ form_rest(form) }}
    </form>

And my controller:

public function addAction(Request $Request) {

        $photo = new Photo();

        $form = $this->createFormBuilder($photo)
            ->add('name')
            ->add('file')
            ->getForm();

        $form->handleRequest($Request);

        if ($form->isValid() && $Request->isMethod('POST')) {

            $em = $this->getDoctrine()->getManager();

            $em->persist($photo);
            $em->flush();

            $this->redirect($this->generateUrl('add'));
        }



        return $this->render('MyBundle::add.html.twig', array(
            'form' => $form->createView()
        ));
    }

Could You help me?

Share Improve this question asked Jun 12, 2015 at 23:06 GemmiGemmi 1,2422 gold badges13 silver badges26 bronze badges 3
  • Have you tried setting of uploadMultiple to false? – Vadim Ashikhman Commented Jun 13, 2015 at 8:35
  • When I set i up I have: files] => Symfony\Component\HttpFoundation\FileBag Object ( [parameters:protected] => Array ( [file] => Symfony\Component\HttpFoundation\File\UploadedFile Object .... But I would like to get [files] => Symfony\Component\HttpFoundation\FileBag Object ( [parameters:protected] => Array [form] => Array ( [file] => Symfony\Component\HttpFoundation\File\UploadedFile Object .... – Gemmi Commented Jun 13, 2015 at 10:28
  • I think I need to connect it somehow with formbuilder, but I don't know how... – Gemmi Commented Jun 13, 2015 at 10:29
Add a ment  | 

1 Answer 1

Reset to default 6

Ok I found the answer... It was simple as possible..

You need to just add a option:

paramName: "form[file]"

To Your dropzone configuration.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742284071a4415011.html

相关推荐

  • javascript - Dropzone.js and symfony formbuilder - Stack Overflow

    I'm trying to handle dropzone.js to work correct with my entity symfony formbuilder.Everything wor

    23小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信