Forum Moderators: open
Is there any easy way of adding something to stop these people sending bots to fill out my forms with nonsense? Its driving me up the wall.
If you are submitting a form straight to your email via a POST, then I'm sorry, but there are a lot of programmers snickering at your expense right now because they don't remember that they did the same thing when they started out, and a lot of spammers are drooling over such an easy target.
Either way it's best to submit a form to another page that will perform an additional validation before sending it off to where it is needed. javascript validation is only to aid you user by preventing them from making an honest mistake. You need something a little better like Perl, PHP, ASP, Coldfusion, or some other server side language to enforce your rules.
If you are doing this already, post your validation code, and I could probably help you a little further.
-Greg
<%@ LANGUAGE="VBSCRIPT" %>
<%
Dim strTo, strFromName, strFromAddress, strSubject, strRedirect, strFormResults
Dim key, strname, strvalue
Dim bEmail
strTo = Request.Form("recipientemail")
strSubject = Request.Form("subject")
strRedirect = Request.Form("Redirect")
strFromName = Request.Form("yourname")
strFromAddress = Request.Form("youremail")
For Each key in Request.Form
If Not (Lcase(key) = "submit") Then
strname = key
strvalue = Request.Form(key)
strFormResults = strFormResults & strname & addspaces(Len(strname),15) & " : " & strvalue & vbCRLF & vbCRLF
End If
Next
strFormResults = "Date Submitted : " & Now() & vBCRLF & _
"-------------------------------------------------" & vBCRLF & _
strFormResults
' send email
sendmail strTo, strFromAddress, strSubject, strFormResults
' Redirect to thankyou page
Response.Redirect (strRedirect)
Response.End
Function addSpaces(intLen, intTabStop)
Dim i
For i=1 to (intTabStop - intLen)
addSpaces = addSpaces & " "
Next
End Function
Sub sendmail (strToAddress, strFromAddress, strSubject, strBody)
'Response.Write "<BR>" & strToAddress
'Response.Write "<BR>" & strFromAddress
'Response.Write "<BR>" & strSubject
'Response.Write "<BR>" & strBody
Dim objCDO
Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.To = strToAddress
objCDO.Cc = strCC
objCDO.From = strFromAddress
objCDO.Subject = strSubject
objCDO.Body = strBody
objCDO.Send
'Cleanup
Set objCDO = Nothing
End Sub
%>
FIRST GOLDEN RULE OF PROGRAMMING: Assume all input is tainted as badly as it could be.
test each input variable for :
1. data type
2. length or range
3. illegal characters
I usually test in that order as it moves quickest to slowest.
Looking over your code I can see that you forgot this step. Ask yourself:
1. How can I be sure that the data in the Request.From collection is in the right format.
2. What would happen if I entered the wrong kind of data.
Unfortunately, I know only a little vbscript, but not enough to give you a good validation routine. If no one helps you here, maybe try the Microsoft oriented forum here [webmasterworld.com ]
( Just a heads up, if you know JavaScript already, why not write the asp side in JScript? From what I know, its essentially the same as JavaScript )