经典ASP表单字段

时间:2011-08-10 16:46:15

标签: asp-classic

我有一个aspcaptcha的ASP脚本,它有注释表单字段,并向网站管理员发送一封电子邮件。但是,如果访问者没有正确输入验证码,它们将被带回到表单页面,一条消息表明它们没有正确填写验证码但是表单字段是空白的.... 我想在表单字段中保留注释,并要求访问者重新填写验证码。

以下是ASP脚本:

if Request.ServerVariables("REQUEST_METHOD") = "POST" then
captha = Trim(Request.Form("captha"))
if CheckCAPTCHA(captha) = true then
    ' Process form...CAPTCHA IS VALID!
else
    response.redirect "myform.asp?c=f"
end if
else
response.redirect "myform.asp?v=f"
end if

变量v = f告诉表单没有填写验证码,并抛出错误。如何使用访问者已输入的内容填充表单字段,而不要求他们再次输入他们的评论?

2 个答案:

答案 0 :(得分:1)

我不知道aspcaptcha但有两种可能性:

首先,表单是否自行发布?也就是说,处理脚本与表单在同一页面上?如果是,那么只需使用Request.Form("name")

<input name="frmName" type="text" id="frmName" value="<%
    If Request.Form("frmName") <> "" Then Response.Write(Request.Form("frmName"))
%>" />

其次,如果表单提交到第二页进行处理,然后将用户返回到原始页面,请使用会话变量:

if CheckCAPTCHA(captha) = true then
    ' Process form...CAPTCHA IS VALID!
else
    Session("frmName") = Request.Form("frmName")
    response.redirect "myform.asp?c=f"
end if

然后

<input name="frmName" type="text" id="frmName" value="<%
    If Session("frmName") <> "" Then Response.Write(Session("frmName"))
%>" />

希望有帮助...

答案 1 :(得分:0)

在这些情况下,函数通常会有所帮助:

尝试类似的事情:

'Select between Session Value / Form Value
function SelectValue(sessionValue, frmValue)
    result = ""
    if isnull(frmValue) or frmValue = "" then
        result = sessionValue
    else
        result = frmValue
    end if
    SelectValue = result
end function

然后您的表单可以根据需要使用该功能:

<强> e.g。

<input name="frmName" type="text" id="frmName" value="<% SelectValue(Session("frmName"), Request.Form("frmName"))%>" />
相关问题