无法获取所有表单数据

时间:2015-06-25 09:22:55

标签: javascript html forms java-ee dropzone.js

我在互联网上到处看。仍然卡住......这是我被困的地方: 我做了一个看起来像这样的表格: enter image description here

一个多部分表单,有两个输入:data&可选择的项目。

问题是:我迷失了dropzone,因为我知道我要以编程方式声明它(因为它只是我表单的一部分)。 但我只获取文件数据而不是选择选项。 (Java servlet很好,经过研究,问题出在我的.jsp / .js文件中)。

这是我的.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>

这是在创建表单字段后调用我的.js:

    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
        });

而且,我这样做是为了从servlet获取所有数据:https://stackoverflow.com/a/13321215/4944071

我需要一个新的POV,如果有人可以提供帮助......

0 个答案:

没有答案