Changing a form submit url with javascript
Sometimes you might need to change the address a form submits to, it’s quite easy with javascript. One example could be if you - like me - from time to time is hit hard by comment-spammers. Changing the submit URL on the form with javascript, makes it at least somewhat harder for “automated brainless robots” to kill your site in a spam attack.
The recipie below is a very simple example, but so far it seems to work quite well:
<script type="text/javascript">
function doSubmit() {
var target1 = 'hello';
var target2 = 'world';
var target3 = '.cgi';
var supertarget = target0 + target1 + target2 + target3;
var theForm=document.getElementById("theForm");
theForm.action = supertarget;
theForm.submit();
}
</script>
<form id="myForm" method="post" action="some\_fake\_address.php">
<input type="text" name="dummy field" value="">
<input type="button" onclick="javascript:doSubmit();">
</form>