Click to See Complete Forum and Search --> : [RESOLVED] Form Validation won't work.


dtm32236
10-12-2007, 08:56 AM
I can't figure out where my error is, can anyone help?

<%
Dim strTo, strFrom, strSubject, strComments, strSendName, Validated_Form
strTo = "dmathisen@foremostgroups.com"
strFrom = trim(replace(request.form("Email_Address"),"""",""""""))
strSubject = trim(replace(request.form("Subject"),"""",""""""))
strComments = trim(replace(request.form("Comments"),"""",""""""))
strSendName = trim(replace(request.form("Sender_Name"),"""",""""""))
strSpecial = request.form("Info")

Validated_Form = true

IF len(strFrom)<6 OR InStr(Form_Email,"@")=0 THEN
Validated_Form = false
END IF

IF len(strSubject)=0 THEN
Validated_Form = false
END IF

IF len(strComments)=0 THEN
Validated_Form = false
END IF

IF len(strSendName)=0 THEN
Validated_Form = false
END IF

IF len(strSpecial) <> THEN
Validated_Form = false
END IF

IF NOT Validated_Form THEN
%>
<html>
<body>
<p>There were blank fields in the form.</p>
<p>Please <a href="javascript:history.go(-1)" class="in_text">go back</a> and fill in all fields.</p>
</body>
</html>
<%
ELSE
Dim strBodyText
Dim objMyMessage, objMyConfiguration

' create the message and connection objects
Set objMyMessage = Server.CreateObject("CDO.Message")
Set objMyConfiguration = Server.CreateObject ("CDO.Configuration")

' ***CONFIGURATION***

' the target smtp server, you can use IP or SERVERNAME.DOMAINNAME
objMyConfiguration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "207.207.213.226"
' the SMTP server port being utilised, normally 25
objMyConfiguration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' the CDO port being utlised
objMyConfiguration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
' connection timeout
objMyConfiguration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
' update the connection
objMyConfiguration.Fields.Update
' set the message configuration to the connection info defined above
Set objMyMessage.Configuration = objMyConfiguration

' ***END CONFIGURATION***

' message start

strBodyText = "Name: " & strSendName & vbCrLf & vbCrLf
strBodyText = strBodyText & "Comments: " & strComments & vbCrLf

objMyMessage.To = strTo
objMyMessage.From = strFrom
objMyMessage.Subject = strSubject

objMyMessage.TEXTBody = strBodyText
objMyMessage.Send

' message end

' do a clean-up
Set objMyMessage = Nothing
Set objMyConfiguration = Nothing
%>
<html>
<body>
<p>Email Sent!</p>
</body>
</html>
<%
END IF
%>

The strSpecial = request.form("Info"), is a hidden text field in the email form (http://www.foremostgroups.com/dev/2007corporate/contact.html). And I set it so that if there's any text in the field (from a spam bot), it will make it invalid. Just to clear that up.

Can anyone see what's wrong here? No matter what, it says that the form is invalid.

Thanks so much for any help.

dtm32236
10-12-2007, 08:59 AM
oh, another thing...

if you try to send with a field missing, it returns a "HTTP 500 Internal Server Error" page.

dtm32236
10-12-2007, 10:15 AM
I missed this:

IF len(strSpecial) <> THEN
Validated_Form = false
END IF

should be

IF len(strSpecial) <> 0 THEN
Validated_Form = false
END IF

but that doesn't fix it.

dtm32236
10-12-2007, 10:45 AM
nevermind, i got it!

there were a bunch of stupid errors in it.

it's working now.