6 examples of 'javascript serialize form' in JavaScript

Every line of 'javascript serialize form' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
91function serializeForm(form) {
92 var formData = new FormData();
93 var params = form.serializeArray();
94 $.each(params, function (i, val) {
95 formData.append(val.name, val.value);
96 });
97 return formData;
98};
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

12function serializeForm(el, inputSelectors) {
13 inputSelectors = inputSelectors || defaultInputSelectors;
14 var res = {};
15 d3.select(el).selectAll(inputSelectors).each(function () {
16 var el = d3.select(this), type = el.attr("type");
17 if (type === "checkbox" || type === "radio") {
18 //only add checkboxes when they aer checked
19 if (this.checked) {
20 //store as array if it is a checkbox
21 if (!res[el.attr("name")]) { res[el.attr("name")] = []; }
22 res[el.attr("name")].push(el.property("value"));
23 }
24 } else if (el.attr("type") === "file") {
25 res[el.attr("name")] = el.property("files");
26 } else {
27 res[el.attr("name")] = el.property("value") || el.text();
28 }
29 });
30 return res;
31}
57function serializeForm (form) {
58 var q = []
59 for (var i = form.elements.length - 1; i >= 0; i = i - 1) {
60 var element = form.elements[i]
61 if (element.nodeName === 'INPUT' && ['hidden', 'url'].includes(element.type)
62 ) {
63 if (!secrets.includes(element.name)) {
64 q.unshift(`${element.name}=${encodeURIComponent(element.value)}`)
65 }
66 }
67 }
68 return q.join('&')
69}
534function getFormData(formElem) {
535 var formData = $(formElem).serializeArray(),
536 fileInputs = $(formElem).find("input[type=file]"),
537 files = [];
538
539 fileInputs.each(function () {
540 var fileSize, fileType, fieldName = this.name;
541
542 if (this.files.length > 0) {
543 fileSize = this.files[0].size;
544 fileType = this.files[0].type;
545 } else {
546 fileSize = 0;
547 fileType = '';
548 }
549 files.push({name: fieldName, value: fileSize, fileType: fileType, files: this.files});
550 });
551
552 _.each(files, function (fileObj) {
553 formData.push(fileObj);
554 });
555
556 return formData;
557}
1325function getFormData(theForm) {
1326 return $(theForm).serializeObject();
1327}
175function get_form_data(form_id, mode) {
176 // Access the form data.
177 var fields = $("form#" + form_id + " :input").serializeArray();
178 //console.log("gfd: %o", fields);
179 // 'fields' is now an array of {"name": foo, "value" : bar} items.
180 // Convert this into a simpler form, create a new dict.
181 var output = {};
182 // Set the mode, which is not provided by the form.
183 output.mode = mode;
184 // Add the rest of the form elements.
185 $.each(fields, function(i, field){
186 output[field.name] = field.value;
187 });
188 return JSON.stringify(output);
189}

Related snippets