I looked everywhere on the internet. Still stuck ... Here's where i'm stuck : I did a form which looks like this :
A multipart form, with two inputs : data & selectable item.
The problem is : I'm lost with dropzone, because I know that i've to declare it programmatically (because it's just a part of my form). But I only get the file data and not the select option. (Java servlet is good, after researchs, the problem is in my .jsp / .js files).
Here's my .jsp :
<form action="upload" id="myform" method="post"
enctype="multipart/form-data">
<div id="mydz" class="dropzone dz-clickable hvr-outline-out" style="margin-bottom: 5px;">
<div class="fallback">
<input name="datafile" type="file" />
</div>
</div>
<div id="procedure">
Procédure : <select name="procedure">
<option value="1">Toulouse</option>
<option value="2">Tournefeuille</option>
<option value="3">Cine 6</option>
<option value="4">Cinéland</option>
</select>
<input type="submit" id="sbmtbtn" value="Envoyer" />
</div>
<script type="text/javascript" src="views/js/createDropzone.js"></script>
</form>
And here's my .js called after creating the form fields :
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("#mydz",
{
url : 'upload',// Action à appeler
/* Options */
acceptedFiles: ".pdf", // Seulement les PDFs.
addRemoveLinks : true,
autoProcessQueue : false, // this is important as you dont want form to be submitted unless you have clicked the submit button
uploadMultiple: false,
parallelUploads: 1,
maxFiles: 1,
autoDiscover : false,
paramName : 'datafile', // this is similar to giving name to the input type file like <input type="file" name="pic" />
clickable : true, // this tells that the dropzone will not be clickable . we have to do it because v dont want the whole form to be clickable
accept : function(file, done) {
console.log("Ajouté");
done();
},
error : function(file, msg) {
alert(msg);
},
init : function() {
//Ajout possible de seulement 1 fichier
this.on("addedfile", function() {
if (this.files[1]!=null){
this.removeFile(this.files[0]);
}
});
//Envoi du fichier
document.getElementById("sbmtbtn").onclick = function(e) {
e.preventDefault(); //this will prevent the default behaviour of submit button because we want dropzone to submit the form
myDropzone.processQueue(); // this will submit your form to the specified action which directs to your jsp upload code
// after this, your whole form will get submitted with all the inputs + your files and the jsp code will remain as usual
//REMEMBER you DON'T have to call ajax or anything by yourself to submit the inputs, dropzone will take care of that
};
} // init end
});
And, I did this to get all the datas from the servlet : http://ift.tt/1J7gV9P
I need a new POV, if anyone can help ...
Aucun commentaire:
Enregistrer un commentaire