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

前端 未结 2 400
礼貌的吻别
礼貌的吻别 2020-12-10 13:33

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 vi

相关标签:
2条回答
  • 2020-12-10 14:02

    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
    
    0 讨论(0)
  • 2020-12-10 14:21

    This is a very small snippet I use to show all form fields POSTED

    <% 
    For x = 1 to Request.Form.Count 
      Response.Write x & ": " _ 
        & Request.Form.Key(x) & "=" & Request.Form.Item(x) & "<BR>" 
    Next 
    %> 
    
    0 讨论(0)
提交回复
热议问题