循环表单以获取字段名称和字段值问题(经典 ASP) [英] Looping through a form to get field names and filed values issue (classic ASP)

查看:18
本文介绍了循环表单以获取字段名称和字段值问题(经典 ASP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在提交表单时,我想捕获表单的字段名称和值,并且我希望它们在不显示在浏览器中的情况下通过(Response.Write 使它们在浏览器中可见).请问我该怎么做?我正在使用此代码:

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 

推荐答案

您的代码基本上是正确的,所以只需删除 Response.Write 并使用 fieldName 和您正在填充的 fieldValue 变量.处理完数据(将其插入数据库或发送电子邮件)后,您可以将用户重定向到成功/感谢页面.

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.

要测试您是否收到正确的输入,您可以将 Response.Write 更改为

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

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


更新

以下是使用 Dictionary 对象将字段名称和字段值放在一起的方法:

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

这篇关于循环表单以获取字段名称和字段值问题(经典 ASP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆