Skip to content

Instantly share code, notes, and snippets.

@carloscabo
Forked from vortizhe/formify.js
Created June 14, 2013 11:35
Show Gist options
  • Save carloscabo/5781183 to your computer and use it in GitHub Desktop.
Save carloscabo/5781183 to your computer and use it in GitHub Desktop.
/* Send a form with a link with data-form="#form_id"
/ You can define params="name,value name,value"
/ All params will be append to the form as hidden inputs before send it
*/
$('body').on('click', '[data-form]', function(e) {
e.preventDefault();
var el = $(this),
form = $(el.data('form')),
params;
if (el.data('params')) {
params = el.data('params').split(' ');
params.forEach(function(param) {
param = param.split(',');
form.append('<input type="hidden" name="' + param[0] + '" value="' + param[1] + '">');
});
}
form.submit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment