最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to submit post data with dijit.form.Form with Dojo? - Stack Overflow

programmeradmin3浏览0评论

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=".9.3/dojo/resources/dojo.css" rel="stylesheet" />
<link href=".9.3/dijit/themes/claro/claro.css" rel="stylesheet" />
<script src="//ajax.googleapis/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>

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./ajax/libs/dojo/1.9.3/dojo/resources/dojo.css" rel="stylesheet" />
<link href="http://ajax.googleapis./ajax/libs/dojo/1.9.3/dijit/themes/claro/claro.css" rel="stylesheet" />
<script src="//ajax.googleapis./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?

Share Improve this question edited Apr 2, 2015 at 14:08 Ruslan López 4,4772 gold badges30 silver badges40 bronze badges asked Jan 30, 2011 at 17:07 SasaSasa 911 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 15

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");
发布评论

评论列表(0)

  1. 暂无评论