如何检查 VBScript 中是否存在 POST 提交的字段? [英] How to check if a POST submitted field exists in VBScript?

查看:18
本文介绍了如何检查 VBScript 中是否存在 POST 提交的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提交表单后,如何检查服务器端是否存在特定字段?例如:

After a form is submitted, how does one check server-side if a particular field exists? For example:

If [Exists] Request("FieldName") Then
    ...
End If

推荐答案

检查是否为空.有几种不同的方法,但我见过更常用的一种是:

Check if it's not empty. There are a few different ways, but the one I've seen more frequently used is along the lines of:

If Request("FieldName") <> "" Then
 'etc.
End If

如果我可能会根据上下文从一个或另一个中获取变量,我通常会明确检查 FormQueryString 集合以及以下代码之一的一些变体:

I usually explicitly check the Form and QueryString collections with some variation of one of the code below if I may be getting the variable from one or the other depending on context:

Select Case True
    Case Request.Form("FieldName") <> ""
        'Run if the Form isn't empty
    Case Request.QueryString("FieldName") <> ""
        'Run if the QueryString isn't empty
    Case Else
        'Set a predefined default if they're both empty
End Select

或者嵌套的 If ... Then:

Or a nested If ... Then:

If Request.Form("FieldName") <> "" Then
    'Run if the Form isn't empty
ElseIf Request.QueryString("FieldName") <> "" Then
    'Run if the QueryString isn't empty
Else
    'Set a predefined default if they're both empty
End If

如果我确切知道它来自哪个集合,我会专门检查那个集合.原因是我想确保它从我期望它来自的地方拉出我期望的东西.我不希望有人通过在 QueryString 中发送一些我不期望的东西来覆盖 Form 值.

If I know exactly which collection it's coming from, I'll check that collection specifically. The reason is that I want to make sure it is pulling what I expect from where I expect it to come from. I don't want someone overriding a Form value by sending something in the QueryString when I'm not expecting it.

来自 MSDN:

如果指定的变量不在前五个之一中集合,Request 对象返回 EMPTY.

If the specified variable is not in one of the preceding five collections, the Request object returns EMPTY.

所有变量都可以通过调用Request(variable)直接访问没有集合名称.在这种情况下,Web 服务器搜索按以下顺序收集:

All variables can be accessed directly by calling Request(variable) without the collection name. In this case, the Web server searches the collections in the following order:

  • 查询字符串
  • 表格
  • Cookie
  • 客户证书
  • 服务器变量

如果同名变量存在于多个集合中,Request 对象返回该对象的第一个实例相遇.

If a variable with the same name exists in more than one collection, the Request object returns the first instance that the object encounters.

强烈建议在提及成员时集合全名被使用.例如,而不是Request.("AUTH_USER") 使用 Request.ServerVariables("AUTH_USER").这允许服务器更快地定位到该项目.

It is strongly recommended that when referring to members of a collection the full name be used. For example, rather than Request.("AUTH_USER") use Request.ServerVariables("AUTH_USER"). This allows the server to locate the item more quickly.

这篇关于如何检查 VBScript 中是否存在 POST 提交的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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