开发者

Redirect to page, pre-filling form fields

开发者 https://www.devze.com 2023-03-23 21:57 出处:网络
I\'m trying to open a web page (not under my control), and pre-populate some of the fields.I have two challenges that I\'m having some trouble with.

I'm trying to open a web page (not under my control), and pre-populate some of the fields. I have two challenges that I'm having some trouble with.

  1. I (think I) need to redirect to the page itself, not simply "scrape" it.
  2. I don't want to submit the form -- just open it with some fields pre-filled. My user will need to review the input, and fill-in a few more things (potentially) before submitt开发者_开发知识库ing.

Here is what I've tried so far (thanks to a BLOG post from Peter Bromberg here.)

Protected Sub btn_Submit_amazon_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Submit_amazon.Click
    Dim myURL As String = "http://www.amazon.co.uk/exec/obidos/search-handle-form"
    Dim myFormData As New NameValueCollection()
    myFormData("field-keywords") = "Harry Potter"

    Dim myWebClient As New WebClient()

    Dim myResponseBytes As Byte() = myWebClient.UploadValues(myURL, "POST", myFormData)
    Dim myResponse As String = Encoding.UTF8.GetString(myResponseBytes)

    Response.Write(myResponse)
End Sub

The downside to this approach is 1) it submits the form, and 2) This works fine for the amazon url he uses, but when I try to do this to an .aspx page, it doesn't work at all (the form field has nothing in it).

The scenario is that my company has put a lot of their traditionally paper-forms online. Leave requests, contracts, or you name it. This has been a big improvement in terms of routing for approval. However, we are in a situation now where we enter all of this data twice -- once into a database for administrative use, and then a second time into the form for approval. What I'd like to do, is have someone enter the data into our database as they already do (via asp.net applications I've built), and then when they're ready, click a button that ports that data over to the online approval form.

BTW -- the online approval form process is managed by a different department, and they are not willing to modify their process in any way. So any solution to this has to start from my side of the house. I know it would make more sense to just have their form lookup data from my database, but unfortunately that isn't (politically) possible.

Any experience with this?

EDIT ----------

I tried to compromise and allow the form to be submitted -- so far no joy. Found an article suggesting that viewstate can be an issue for doing this with asp.net forms, so I tried to post the viewstate, but it didn't work (500 server error). Here's the article: http://www.canaware.com/default.aspx?g=posts&t=569

So now I'm trying to do this via iframe, per one of the answers I got from @Guffa.


If the form page is on the same domain, you could open the form page in an iframe, and pre-fill the form by accessing the form fields using Javascript.

If the form page is not on the same domain, it gets a lot more complicated. You can't pre-fill the form, but you could scrape the form page (instead of scraping the result page as in your example), alter the HTML code to pre-fill the fields, and then display the form to the user. You might also have to alter the action of the form if it's a relative URL, so that it points to the actual result page.


Are you just testing with an aspx page, or is the online approval form an aspx page?

You can try adding URL parameters to a GET request instead of POST.

http://www.amazon.co.uk/exec/obidos/search-handle-form?field-keywords=Harry+Potter

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号