我使用javascript的工具包dojo将这个简单的表单转换为HTML元素形式:
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"> </dt>
<dd id="submit-element">
<input type="submit" value="OK" id="submit" name="submit">
</dd>
</dl>
</form>
但是,点击提交按钮时,表单正在提交,没有任何帖子数据。
我做错了什么?
答案 0 :(得分:15)
我认为问题是你的dijit表单字段没有任何名称。我知道你已经在html代码中指定了名称,但我认为有必要将它们包含在你的dijit调用中,否则提交不知道以什么名称发送表单数据。
例如:
var title = new dijit.form.ValidationTextBox({
required: true,
trim: true,
name: "title"
}, "title");