I'm not sure I understand.. But i'll give it a shot.
In PHP, you can do something like this. Say you have a script that grabs the IP of the visitor and sends it via the mail() function. The function is called on by a form. But as you said, you don't want to have to submit the form for it to activate the script. Well yes you can do this. But that means the function will be called every time the page is loaded, rather than every time the form is submitted. To achieve this, all you'd have to do is throw the function in the actual page file.
For those about to hack, I salute you.