Hey all,
I'm having some problems with some form validation. What I'm trying to do is see if a couple of fields are in the form when the user clicks the submit button. but what's happening is, if there's some errors in the code it's not working as intended. What I'd like to have is it go back to the previous page and just mention that there were a couple errors on the page and for them to go back and change them. Here's the code I'm using for after the user clicks the submit button.
Code:
<%@ Language=VBScript %>
<% 'Written By - JR %>
<%
Dim Mailer
Dim iConf
Dim Flds
Dim strUserComments
webaddr=Request.QueryString("pageref")
'Check for missing fields
Dim sCheckFailed
If Request.Form("emto") = "" then sCheckFailed = sCheckFailed & "0FN"
If Request.Form("emfrom") = "" then sCheckFailed = sCheckFailed & "0LN"
If Request.Form("emailComments") = "" then sCheckFailed = sCheckFailed & "OLN"
If sCheckFailed <> "" then
Response.Redirect(Request.Form("Page") & "?rem=" & sCheckFailed & "&" & Request.Form)
'Check for valid email address
'-- contains a @
EmailValid3 = false
For x = 1 to Len(Request.Form("emfrom"))
If mid(Request.Form("emfrom"),x,1) = "@" Then
EmailValid3 = true
End If
Next
'-- contains a .
EmailValid4 = false
For x = 1 to Len(Request.Form("emfrom"))
If mid(Request.Form("emfrom"),x,1) = "." Then
EmailValid4 = true
End If
Next
strUserComments = Request.Form("emailComments")
If Len(strUserComments) > 1 Then
strUserComments = Replace(strUserComments,Chr(13),"<br>")
End If
If EmailValid3 = False OR EmailValid4 = False Then
'Response.Redirect(Request.Form("Page") & "?rem=0EM&" & Request.Form)
Response.Redirect(webaddr)
SubmitEmail="[email protected]"
else
'All is good send the email
Set Mailer = Server.CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
'**** Path below may need to be changed if it is not correct
'Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
'Flds.Update
Set Mailer.Configuration = iConf
Mailer.From = Request.Form("emfrom")
Mailer.to = Request.Form("emto")
Mailer.Subject = "Website Email"
Mailer.HTMLBody = strUserComments & "<br>" & Request.Form("emname") & "<br><br>" & Request.Form("emphone")
Mailer.Send
Set mailer = Nothing
Response.Redirect("thank_you.htm")
end if
%>
So if ya all could help with this that'd be great!!!
Thanks in Advance!