Last active
December 18, 2015 12:10
-
-
Save vortizhe/5781138 to your computer and use it in GitHub Desktop.
Send form with link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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