aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-01-13 00:21:23 +0100
committerMatěj Cepl <mcepl@redhat.com>2010-01-13 00:21:23 +0100
commitdc94b62a881ca46f46a39d8f6af2cd4659861be6 (patch)
treeb6a6be0118f04600277f1d522c9ef7eb2dfb0a49
parent5333869aac2dbd71c91727dbca6aee1a46b3cdb1 (diff)
downloadbugzilla-triage-dc94b62a881ca46f46a39d8f6af2cd4659861be6.tar.gz
Example of the form serialization code. DON'T USE DIRECTLY, GPLv3!!!
-rw-r--r--offline-submit/form-serialization.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/offline-submit/form-serialization.js b/offline-submit/form-serialization.js
new file mode 100644
index 0000000..70c9ae0
--- /dev/null
+++ b/offline-submit/form-serialization.js
@@ -0,0 +1,37 @@
+/**
+ * (C) Thomas 'PointedEars' Lahn, 2009, released under GPLv3
+ *
+ * Retrieves the data to send in the request, and optionally the request
+ * method, from an (X)HTML form. TODO: select[multiple] elements
+ *
+ * @param f : HTMLFormElement
+ * @param bUseFormMethod: optional boolean
+ * If <code>true</code>, the form's request method becomes the
+ * <code>HTTPRequest</code> object's request method. The default
+ * is <code>false</code>.
+ * @return boolean
+ */
+getDataFromForm = function(f, bUseFormMethod) {
+ var result = false, es, len;
+
+ if (f && (es = f.elements) && (len = es.length))
+ {
+ if (bUseFormMethod) this.method = f.method;
+
+ var aData = [];
+
+ for (var i = 0; i < len; i++)
+ {
+ var o = es[i];
+ if (o.name)
+ {
+ aData.push(esc(o.name) + "=" + esc(o.value != "" ? o.value : ""));
+ }
+ }
+
+ this.data = aData.join("&");
+ result = true;
+ }
+
+ return result;
+};