如何检查表单提交的ASP经典 [英] How to check form submission ASP classic
问题描述
我正在用ASP Classic建立一个表单,提交后会重新加载(动作自我)
I'm setting up a form in ASP classic and it will reload after submission (action self)
但是这次显示的是以前提交的结果,那么如何检查已提交的POST?
But this time it shows results of previous submissions, so how can I check that a POST submission has been made?
类似于PHP:
if($_POST['submit']) {
show results...
}
推荐答案
您有几种选择:
方法1 -检查请求方法:
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
'Show Results...
End If
方法2 -向表单中添加一个带有值的隐藏字段,然后检查该值是否已发布:
Method 2 - add a hidden field to your form with a value then check if that value has been posted:
If Request.form("HiddenValue") = "1" Then
'Show Results...
End If
方法3 -检查request.form集合中是否包含项目:
Method 3 - Check if the request.form collection contains items:
If Request.Form.Count > 0 Then
'Show Results...
End If
方法4 -发布到查询字符串(即,将<form>
的action
设置为?post=yes
)
Method 4 - Post to a querystring (i.e. set action
of <form>
to ?post=yes
)
If Request.QueryString("post") = "yes" Then
'Show Results...
End If
选择哪个?
我的首选选项是方法4 –因为它很容易在地址栏中显示发生的情况–如果出于某种原因我想避免在url中显示此详细级别,我倾向于使用选项3,因为它很容易实施,无需更改源表单&是可靠的. 至于其他两种方法:
My preferred option is method 4 – as it’s easily visible in the address bar as to what’s going on – if for some reason I want to avoid presenting this level of detail in the url, I tend to use option 3 as it’s easy to implement, requires no changes on the source forms & is reliable. As for the other two methods:
- 方法1 –如果不这样做,我倾向于避免依赖服务器变量 对服务器有100%的控制权–没有任何正当理由, 只是我倾向于与之共处的一个习惯.
- 方法2 –您可以将隐藏字段替换为始终包含以下内容的其他字段 一个值.
- Method 1 – I tend to avoid relying on server variables if I don’t have 100% control over the server – no real justification for that, just a general habit I tend to work with.
- Method 2 – You could substitute a hidden field for another field that will always contain a value.
这篇关于如何检查表单提交的ASP经典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!