Asp-Classic

循環表單以獲取欄位名稱和欄位值問題(經典 ASP)

  • May 10, 2019

在送出表單時,我想擷取表單的欄位名稱和值,並且我希望它們通過甚至不顯示在瀏覽器中(Response.Write 使它們在瀏覽器中可見)。請問我該怎麼做?我正在使用這段程式碼:

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

   Response.Write(""& fieldName &" = Request.Form("""& fieldName &""")")       
   Next 

您的程式碼基本上是正確的,因此只需刪除並使用您正在填充的和變數Response.Write執行其他操作。處理完數據(將其插入數據庫或發送電子郵件)後,您可以將使用者重定向到成功/感謝頁面。fieldName``fieldValue

要測試您是否收到正確的輸入,您可以將您的更改Response.Write

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

更新

以下是使用 Dictionary 對象將欄位名稱和欄位值放在一起的方法:

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

引用自:https://stackoverflow.com/questions/9076577