Fog Creek Software
Discussion Board




How would you silently submit a form?

I'm working in ASP, but I don't think the platform matters...

I want to pre-fill some form fields and submit them to another page (that will recognize them) without using an actual form--just server-side script without the client knowing. How would you create a request that was more than just the URL but also contained the values? I could swear I've seen it done before, but Google isn't telling me.

This is possible, isn't it?

Teller
Thursday, July 29, 2004

http://www.takempis.com/takidc/Submitcode.asp

Code Monkey
Thursday, July 29, 2004

<script>
function body_onload()
{
  document.forms["theForm"].submit();
}
</script>
...
<body onload="body_onload()">
...
<form action="SomePage.asp" name="theForm">
  <input type="hidden" name="val1" value="something">
  <input type="hidden" name="val2" value="something">
  <input type="hidden" name="val3" value="something">
</form>
...

Duncan Smart
Thursday, July 29, 2004



One nifty little trick I use is having a 0 sized iframe which actually holds a copy of my form.  Then, whenever someone edits a text box in the main form, a value is updated in the iframe form.

Then, when the last box is populated or a mouseover happens, I submit the iframe form.  It is totally invisible and this is how I do all my searching in our apps.

It's a hack that gives you a multi-threaded web app.

KC
Friday, July 30, 2004

Thanks for the replies, but they're all client side solutions. I was talking about preparing a request server-side, and submitting it to another page (the other page is on another site, actually!).

But perhaps the on_load method is the only way.

Teller
Friday, July 30, 2004

Teller,

As this tutorial demonstrates, you can access another URL in your ASP code using InetCtrls.Inet:

http://www.4guysfromrolla.com/webtech/040600-1.shtml

While this is mainly used to fetch stuff from other servers, you can also include a querystring in your request to pass information.

Ged Byrne
Friday, July 30, 2004

Still not useful to fake a form submit.

But I did find this, which I think will do the job:

How To Submit Form Data by Using XMLHTTP or ServerXMLHTTP Object:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q290591&ID=KB;EN-US;Q290591

Teller
Friday, July 30, 2004

Teller, there's no reason to get the client to do that post for you if you'd rather not.

It sounds like you want something like this:

Client <--> Server A <--> Server B

But other people are describing this:

Server A <--> Client <--> Server B

Depending on the languages and libraries you have access to, you ought to be able to submit the POST request to Server B from Server A directly.  It's easy enough that you can do it if you just have access to a socket library.

Kalani
Friday, July 30, 2004

Kalani,

Exactly. I guess I was hoping I wouldn't have to hack the http protocol to get it done. On the bright side, it is my understanding that form element and values are just more text, name/value pairs...so it shouldn't be to horribly hard to figure out.

Thanks everyone...

Teller
Friday, July 30, 2004

Wow Teller, you're a moron.

muppet
Tuesday, August 03, 2004

*  Recent Topics

*  Fog Creek Home