ASP 经典:将 "variable" 放入 "Request.Form()"
ASP Classic : Put a "variable" in a "Request.Form()"
我有一个表单可以将一组数据发送到 ASP 页面。
假设这个数组叫做 "matrix".
通常,在 ASP 收到表单时,我会写出这个以从数组 "matrix".
中检索表单输入
Request.Form("matrix[]")(i) where i = 1, 2, 3 which are the elements in the array.
假设我想做一个像这样的变量
a="matrix"
我想使用这个变量 a
并将其放入请求表单中,而不是写 "matrix"
,这样它看起来像这样
Request.Form(a[])(i)
怎么办?现在,我所有的尝试都显示空白。例如当我尝试让它们出现在带有 response.write 的页面上时,没有任何显示。
如果无法完成,请帮助我或告诉我,我已经为此花费了数小时。
Request.Form("matrix[]")
取字符串值 "matrix[]"
而不是名为 "matrix"
.
的字符串数组
所以你需要做任何一个
a = "matrix[]"
Request.Form(a)(i)
或
a = "matrix"
Request.Form(a & "[]")(i)
与需要添加方括号的 PHP 不同,在经典 ASP 中,您只需为要组合到数组中的元素指定相同的名称即可。
HTML应该是:
<input type="text" name="matrix" />
<input type="text" name="matrix" />
<input type="text" name="matrix" />
然后您可以像这样遍历提交的值:
For x=1 To Request.Form("matrix").Count
Response.Write("Value of matrix #" & CStr(x) & "is: " & Request.Form("matrix").Item(x))
Next
请注意,所有元素都包含在内,即使用户将它们留空也是如此。
我有一个表单可以将一组数据发送到 ASP 页面。
假设这个数组叫做 "matrix".
通常,在 ASP 收到表单时,我会写出这个以从数组 "matrix".
中检索表单输入Request.Form("matrix[]")(i) where i = 1, 2, 3 which are the elements in the array.
假设我想做一个像这样的变量
a="matrix"
我想使用这个变量 a
并将其放入请求表单中,而不是写 "matrix"
,这样它看起来像这样
Request.Form(a[])(i)
怎么办?现在,我所有的尝试都显示空白。例如当我尝试让它们出现在带有 response.write 的页面上时,没有任何显示。
如果无法完成,请帮助我或告诉我,我已经为此花费了数小时。
Request.Form("matrix[]")
取字符串值 "matrix[]"
而不是名为 "matrix"
.
所以你需要做任何一个
a = "matrix[]"
Request.Form(a)(i)
或
a = "matrix"
Request.Form(a & "[]")(i)
与需要添加方括号的 PHP 不同,在经典 ASP 中,您只需为要组合到数组中的元素指定相同的名称即可。
HTML应该是:
<input type="text" name="matrix" />
<input type="text" name="matrix" />
<input type="text" name="matrix" />
然后您可以像这样遍历提交的值:
For x=1 To Request.Form("matrix").Count
Response.Write("Value of matrix #" & CStr(x) & "is: " & Request.Form("matrix").Item(x))
Next
请注意,所有元素都包含在内,即使用户将它们留空也是如此。