Skip Navigation | Groups

This site uses cookies- for more information see the Cookie Policy | Continue

Tags

Forms

2009012302 Email to Ronx
 

Code to Reduce Spam using Hidden Fields

Classic ASP code for Hidden Fields


The code for the Hidden Fields page - this is written in VB Script for "classic" ASP.

<%
eTo = "user@example.com"
eBody = ""
'Did the user click the "Send" button?
if Request.Form("formID") = "00" then
'Get Form or QueryString parms
rfcheck = validHTML(Request.Form("city"))
rfcheck2 = validHTML(Request.Form("country"))
'form fields city and country are the hidden fields in the form, 
 'which should not be changed by a genuine user.
rfComments = validHTML(Request.Form("Comments"))
eName = validHTML(Request.Form("Name"))
eFrom = validHTML(Request.Form("Replyto"))
eSubject = validHTML(Request.Form("Subject"))
'Do some checks
if rfcheck<>"" then 
arrayErrors = arrayErrors & "|checks"
end if
if lcase(rfcheck2)<>"enter your country" then 
arrayErrors = arrayErrors & "|checks"
end if
if len(eName) = 0 then
arrayErrors = arrayErrors & "|eName"
end if
if len(eFrom) = 0 then
arrayErrors = arrayErrors & "|eFrom"
else
jj = inStr(eFrom,"@")
if jj = 0 or inStr(mid(eFrom,jj),".") = 0 then
arrayErrors = arrayErrors & "|eFrom"
end if
if invalidChar(eFrom,1,"@.-_") then
arrayErrors = arrayErrors & "|eFrom"
end if
end if
if len(eSubject) = 0 then
arrayErrors = arrayErrors & "|eSubject"
end if
if len(rfComments) = 0 then
arrayErrors = arrayErrors & "|Comments"
end if
'If there are no errors, send the email.
if len(trim(arrayErrors)) = 0 then
'build eBody
eBody = eBody & rfComments & vbCRLF & vbCRLF
eBody = eBody & "Name: " & validHTML(Request.Form("Name")) & vbCRLF
eBody = eBody & "email: " & eFrom & vbCRLF & vbCRLF
eBody = eBody & "IP Address: " & svrh & vbCRLF
eBody = eBody & "Time Posted: " & svts & vbCRLF
end if
else arrayErrors = "|nofields"
end if

Back to Hidden Fields page