Skip to content

Instantly share code, notes, and snippets.

@rdev5
Created August 12, 2016 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdev5/f3111f88ea5e6443ddaad2a820ac2b05 to your computer and use it in GitHub Desktop.
Save rdev5/f3111f88ea5e6443ddaad2a820ac2b05 to your computer and use it in GitHub Desktop.
var createForm = function(action, fields) {
function isObject(val) {
if (val === null) { return false;}
return ( (typeof val === 'function') || (typeof val === 'object') );
}
if (!isObject(fields))
return;
// Create form
var f = document.createElement('form');
f.setAttribute('action', action);
f.setAttribute('method', 'post');
f.setAttribute('hidden', 'true');
// Append form fields
for (var k in fields)
{
var field = document.createElement('input');
field.setAttribute('type', 'hidden');
field.setAttribute('name', k);
field.setAttribute('value', fields[k]);
f.appendChild(field);
}
// Add form fields
return f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment