01 Feb 2007

Dynamic Form Submit

1 Comment Programming and Technology

I've just released iZeit v1.7, a calendar written in PHP. One of the things I added to this version was JavaScript forms created on the fly to replace image links. There was a problem recently with Google Web Accelerator, which preloaded all links on the current page so they'd load faster when they were needed. That might sound like a good idea, until you get a page full of delete links that use variables passed via the GET method. Creating a form on the fly and submitting it using POST looks nicer, is alot more secure and isn' subject to Google's interfering web accelerator. Instead of using the href of an anchor, you use an onclick event in the anchor instead.

‹a title="Delete Category" onclick="var f = document.createElement('form');
f.style.display = 'none'; this.parentNode.appendChild(f);
var h = document.createElement('input'); h.type = 'hidden'; h.name = 'act'; h.value = 'admin'; f.appendChild(h);
var h2 = document.createElement('input'); h2.type = 'hidden'; h2.name = 'setadmin'; h2.value = 'delcat'; f.appendChild(h2);
f.method = 'POST';
f.action = 'index.php';
f.submit();
return false;"›
‹img border="0" src="delete.gif" alt="Delete category" /›‹/a›
Tags: , , ,
written by
The author didn‘t add any Information to his profile yet.

One Response to “Dynamic Form Submit”

  1. Reply Melina says:

    very interesting. i'm adding in RSS Reader

Leave a Reply