I use a jQuery script to create "shadow" forms for my POSTable links.
Instead of <a href="/some/action?foo=bar">
, I write <a data-post="/some/action" data-var-foo="bar" href="#do_action_foo_bar">
. The script makes a hidden form with hidden inputs, and submits it when the link is clicked.
$("a[data-post]")
.each(function() {
let href = $(this).data("post"); if (!href) return;
let $form = $("<form></form>").attr({ method:"POST",action:href }).css("display","none")
let data = $(this).data()
for (let dat in data) {
if (dat.startsWith("postVar")) {
let varname = dat.substring(7).toLowerCase() // postVarId -> id
let varval = data[dat]
$form.append($("<input/>").attr({ type:"hidden",name:varname,value:varval }))
}
}
$("body").append($form)
$(this).data("postform",$form)
})
.click(function(ev) {
ev.preventDefault()
if ($(this).data("postform")) $(this).data("postform").submit(); else console.error("No .postform set in <a data-post>")
})
_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a data-post="/some/action" data-var-foo="bar" href="#do_action_foo_bar">click me</a>
_x000D_