Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

vbscript - Looping through a form to get field names and filed values issue (classic ASP)

on submit of a form, I would like to capture the field names and values of the forms and I want them passed without even showing in the browser (Response.Write makes them visible in the browser). How I can do this please? I am using this code:

    For Each Item In Request.Form
    fieldName = Item
    fieldValue = Request.Form(Item)

    Response.Write(""& fieldName &" = Request.Form("""& fieldName &""")")       
    Next 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your code is essentially correct, so just remove the Response.Write and do something else with the fieldName and fieldValue variables you're populating. After you're done with manipulating the data (either inserting it into a database or sending an e-mail), you can redirect the user to a success / thank you page.

To test that you're receiving the correct input, you can change your Response.Write to

Response.Write fieldName & " = " & fieldValue & "<br>"


Update

Here's how you could use a Dictionary Object to put your field names and field values together:

Dim Item, fieldName, fieldValue
Dim a, b, c, d

Set d = Server.CreateObject("Scripting.Dictionary")

For Each Item In Request.Form
    fieldName = Item
    fieldValue = Request.Form(Item)

    d.Add fieldName, fieldValue
Next

' Rest of the code is for going through the Dictionary
a = d.Keys  ' Field names  '
b = d.Items ' Field values '

For c = 0 To d.Count - 1
    Response.Write a(c) & " = " & b(c)
    Response.Write "<br>"
Next

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...