Skip to content

Instantly share code, notes, and snippets.

@vortizhe
Last active December 18, 2015 12:10
Show Gist options
  • Save vortizhe/5781138 to your computer and use it in GitHub Desktop.
Save vortizhe/5781138 to your computer and use it in GitHub Desktop.
Send form with link
/* 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