2014-09-11 183 views
2

我使用dropzone創建了一個表單,但我遇到了將文件傳遞到服務器的問題。我創建了一個自定義預覽模板,類似於引導演示中的模板,但是當我單擊表單上的提交時,這些文件未被傳遞到服務器。任何幫助,將不勝感激。以下是代碼。Dropzone JS的自定義預覽模板

<form action="<?php the_permalink(); ?>" method="post" class="dropzone" id="my-awesome-dropzone" enctype="multipart/form-data"> 
<div class="dropzoner dropzone-previews" id="dropzoner2"> 
      <div class="dz-preview dz-file-preview" id="template"> <!-- template for images --> 
      <div class="dz-details dztemplate"> 
       <div class="dz-filename" style="display:none;"><span data-dz-name></span></div> 
       <div class="dz-size" style="display:none;" data-dz-size></div> 
       <img data-dz-thumbnail /><br/><input type="text" class="dzinput" placeholder="Type Caption" style="font-style:italic;" /> 
      </div> 
      <div class="dz-progress" style="display:none;"><span class="dz-upload" data-dz-uploadprogress></span></div> 
      <div class="dz-success-mark" style="display:none;"><span>✔</span></div> 
      <div class="dz-error-mark" style="display:none;"><span>✘</span></div> 
      <div class="dz-error-message" style="display:none;"><span data-dz-errormessage></span></div> 
      </div> 
     </div> <!-- Drop Zone Area --> 
     <div class="flrt"><a href="#" class="dz-message" style="font-weight:bold; font-size:18px;">Or use the basic uploader</a></div><br/> 
     <label for="exampletitle">Title<span class="required">*</span></label><br/> 
     <input type="text" name="exampletitle" id="exampletitle" class="fullwidth" required>  <br/><br/> 
<input type="submit" class="btn btn-primary mypanoramabtn" style="background-color:#3ebede" value="Publish" id="submitter"/> 
</form> 

我的javascript:

//getting thumbnail template 
    var previewNode = document.querySelector("#template"); 
    previewNode.id = ""; 
    var previewTemplate = previewNode.parentNode.innerHTML; 
    previewNode.parentNode.removeChild(previewNode); 

//script to handle dropzone 
    jQuery("#my-awesome-dropzone").dropzone = { // The camelized version of the ID of the form element 

    // The configuration we've talked about above 
    autoProcessQueue: false, 
    uploadMultiple: true, 
    thumbnailWidth: 180, 
    thumbnailHeight: 120, 
    parallelUploads: 100, 
    maxFiles: 100, 
    previewTemplate: previewTemplate, 
    previewsContainer: "#dropzoner2", 

    // The setting up of the dropzone 
    init: function() { 
    this.on("addedfile", function(file) { document.getElementById("dropzoner2").style.background = "none";}); //will remove background after file added 
    var myDropzone = this; 

    // First change the button to actually tell Dropzone to process the queue. 
    this.element.querySelector("input[type=submit]").addEventListener("click", function(e) { 
     // Make sure that the form isn't actually being sent. 
     e.preventDefault(); 
     e.stopPropagation(); 
     myDropzone.processQueue(); 
    }); 

    // Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead 
    // of the sending event because uploadMultiple is set to true. 
    this.on("sendingmultiple", function() { 
     // Gets triggered when the form is actually being sent. 
     // Hide the success button or the complete form. 

    }); 
    this.on("successmultiple", function(files, response) { 
     // Gets triggered when the files have successfully been sent. 
     // Redirect user or notify of success. 
    }); 
    this.on("errormultiple", function(files, response) { 
     // Gets triggered when there was an error sending the files. 
     // Maybe show form again, and notify user of error 
    }); 
    } 

} 

我試過在維基和計算器其他一些演示,但一直未能得到這個工作。現在,當我拖放我的圖像時,我確實看到了模板中的縮略圖,但是當我單擊「提交」時,圖像不會傳遞到服務器供我處理。任何幫助,將不勝感激。

+0

你應該提供一些關於這個不起作用的更多信息。張貼網絡請求到服務器的外觀。您可以打開調試工具並轉到「網絡」選項卡並在拖放時觀看它。 – Du3 2015-01-31 23:44:09

回答