How to Link dropzone with form widget?

How can I link dropzone with form_widget?

Simply what I want to do is to fill {{form_widget(form.picture) }} with the content of the dropzone!
or Link them together!

If that’s not possible, then How can I Retrieve/get the content of dropzone on the controller?

Here is the view (twig page)

{{ form_start(form, {attr: {novalidate: 'novalidate'}}) }}  
     <div class="row clearfix">
        <div class="col-lg-12 col-md-12 col-sm-12">
            <div action="/"  class="dropzone" >
                <div class="dz-message">
                    <div class="drag-icon-cph"> <i class="material-icons">touch_app</i> </div>
                    <h3>Drop files here or click to upload.</h3>
                <div class="fallback">
                     {{ form_widget(form.picture) }}        
                </div>
            </div>
        </div>
    </div>
{{ form_rest(form) }}
{{ form_end(form) }}

When I do Ctrl+U to check the view-source Its like this :

 <div class="row clearfix">
    <div class="col-lg-12 col-md-12 col-sm-12">
        <div action="/"  class="dropzone" >
            <div class="dz-message">
                <div class="drag-icon-cph"> <i class="material-icons">touch_app</i> </div>
                <h3>Drop files here or click to upload.</h3>
            <div class="fallback">
                 <input type="file" id="user_picture" name="user[picture]" />       
            </div>
        </div>
    </div>
</div>

The controlleur

/**
 * @Route("/new_doctor", name="doctor_new", methods={"GET","POST"})
 */
public function new(Request $request,UserPasswordEncoderInterface $encoder): Response
{
    $doctor = new User();
    $form = $this->createForm(UserType::class, $doctor);
    $form->handleRequest($request);
    if ($form->isSubmitted() && $form->isValid()) {
        $this->get('session')->getFlashBag()->clear();
        $file=$doctor->getPicture();
        dump($file);
        die(); 

When i do dump($file); I get NULL
Here are some of the dropzone Options

Dropzone.prototype.defaultOptions = {
  url: null,
  method: "post",
  withCredentials: false,
  parallelUploads: 1,
  uploadMultiple: false,
  maxFilesize: 256,
  paramName: "user[picture]",
  createImageThumbnails: true,
  maxThumbnailFilesize: 10,
  thumbnailWidth: 120,
  thumbnailHeight: 120,
  filesizeBase: 1000,
  maxFiles: 1,
  params: {},
  clickable: true,
  ignoreHiddenFiles: true,
  acceptedFiles: null,
  acceptedMimeTypes: null,
  autoProcessQueue: true,
  autoQueue: true,

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *