简体   繁体   中英

How to submit post data with dijit.form.Form with Dojo?

I got this simple form with javascript's toolkit dojo into an HTML element form:

 dojo.require("dijit.form.Form"); dojo.require("dijit.form.ValidationTextBox"); dojo.require("dijit.form.Textarea"); dojo.require("dijit.form.Button"); dojo.addOnLoad(function() { var form = new dijit.form.Form({ method: "POST", action: "" }, "createCollectionForm"); var title = new dijit.form.ValidationTextBox({ required: true, trim: true }, "title"); var description = new dijit.form.Textarea({ trim: true }, "description"); var submit = new dijit.form.Button({ label: "OK", onClick: function(event) { dijit.byId("createCollectionForm").submit(); } }, "submit"); }); 
 <link href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/resources/dojo.css" rel="stylesheet" /> <link href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dijit/themes/claro/claro.css" rel="stylesheet" /> <script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js" djConfig="parseOnLoad:true"></script> <body class="claro"> <form method="post" action="" enctype="application/x-www-form-urlencoded" id="createCollectionForm"> <dl class="zend_form"> <dt id="title-label"><label class="required" for="title">Title:</label></dt> <dd id="title-element"> <input type="text" value="" id="title" name="title" gtbfieldid="1"> </dd> <dt id="description-label"><label class="optional" for="description">Description:</label></dt> <dd id="description-element"> <textarea cols="80" rows="24" id="description" name="description"></textarea> </dd> <dt id="submit-label">&nbsp;</dt> <dd id="submit-element"> <input type="submit" value="OK" id="submit" name="submit"> </dd> </dl> </form> 

But when clicking the submit button, the form is submitting without any post data .

What am I doing wrong?

I think the problem is that your dijit form fields don't have any names. I know you have specified the names in the html code but I think it is necessary to include them in you dijit calls as well, otherwise the submit doesn't know under what names to send the form data.

For Example:

var title = new dijit.form.ValidationTextBox({
    required: true,
    trim: true,
    name: "title"
}, "title");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM