如何检查表单提交 ASP 经典 [英] How to check form submission ASP classic

查看:22
本文介绍了如何检查表单提交 ASP 经典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 ASP 经典中设置一个表单,它会在提交后重新加载(操作自我)

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 中一样:

Like in PHP:

if($_POST['submit']) {
  show results...
}

推荐答案

你有几个选择:

方法一 - 检查请求方法:

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 - 发布到查询字符串(即设置

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屋!

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