Recorrer un formulario para obtener nombres de campo y problemas de valores archivados (ASP clásico)

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 &""")")       

preguntado el 31 de enero de 12 a las 08:01

2 Respuestas

Your code is essentially correct, so just remove the Response.Write and do something else with the fieldName y la 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 a

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


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

' 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>"

Respondido el 31 de enero de 12 a las 16:01

Hi thanks for your help. basically I have a form and it submits to a script. This script had the form FieldNames requests hard coded in the script example: PID = (Request.Form("PID") . Now I created the loop in this script to work dynamically and get the fieldNames from the form, and I want them to be written as [fieldName] = Request.Form("[fieldName]") IN THE SCRIPT. How I can do it please? - René Zammit

I see; if I understand correctly, you want to Para crear variables based on the field names with the values that were submitted for them. This isn't possible and the best you can do is either creating an array or Dictionary Object with those name/value pairs. - sigilo

Which is the easiet please and How I can apply this to the array? Thanks again - René Zammit

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>" 

respondido 21 nov., 16:02

This one is a good and a very simple solution also for the issue of 'For Each Loop' - if you need to preservar el orden de los submitted Name/Value of the request. Thank you I had this issue once and had to work around with a longer and more complicated solution! - Code Reaper

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.