我有一个ASP脚本与aspcaptcha其中有评论表单字段,并发送一封电子邮件给网站管理员。然而,如果访问者没有正确输入验证码,他们将被带回表单页面,一条消息表明他们没有正确填写验证码,但表单字段为空。我希望将注释保留在表单字段中,并要求访问者重新填写验证码。
下面是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告诉表单验证码没有填写,并抛出一个错误。如何使用访问者已经输入的内容填充表单域,而不要求访问者重新输入备注?
发布于 2011-08-11 22:15:46
我不知道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"))
%>" />希望这能帮上忙。
发布于 2012-05-09 23:53:51
在以下情况下,函数通常会有所帮助:
尝试如下所示:
'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然后,您的表单可以根据需要使用该函数:
,例如
<input name="frmName" type="text" id="frmName" value="<% SelectValue(Session("frmName"), Request.Form("frmName"))%>" />https://stackoverflow.com/questions/7014590
复制相似问题