如何使用dropzone js发布其他表单字段?

时间:2015-04-25 04:14:52

标签: php forms post upload dropzone.js

我有一个HTML表单,上传dropzone js个文件。我想在文件中发布其他表单字段信息。我试过这段代码,

HTML

<script src="dropzone/dist/dropzone.js"></script>
<link rel="stylesheet" href="dropzone/dist/dropzone.css">

<form role="form" id="my-awesome-dropzone" method="post" action="photos/post"  enctype='multipart/form-data'>
     <input type="text" name="title" id="title" class="form-control input-lg" placeholder="Title" >
     <input type="text" name="location" id="location" class="form-control input-lg" placeholder="Location">
     <div class="dropzone dz-clickable" id="myDrop">
        <div class="dz-default dz-message" data-dz-message="">
            <span>Drop files here to upload</span>
        </div>
     </div>
    <input type="button" value="Post" id="post-btn">

的Javascript

<script type="text/javascript">
var myDropzone = new Dropzone("div#myDrop", {
    url: "photos/post",
    autoProcessQueue: false,
    uploadMultiple: true,
    addRemoveLinks: true,
    parallelUploads:3,
    maxFiles : 3,       
});

$('#post-btn').on('click',function(){        
     myDropzone.processQueue();
});

但是使用这段代码我只能发布图片而不是标题和位置。如何使用上传信息发布标题和位置值?

1 个答案:

答案 0 :(得分:0)

您可以查看http://www.dropzonejs.com/#tips

myDropzone.on("sending", function(file, xhr, formData) {
  // Will send the filesize along with the file as POST data.
  formData.append("filesize", file.size);
});