gcook1
09-14-2005, 09:06 AM
I'm hoping someone can see what I'm doing wrong! I'm writing an ASP web form and I want to do a simple e-mail check. I've stripped it down to just the part that isn't working. I want a pop-up box to prompt the user if he forgets to put in an e-mail address. If he does enter an e-mail address, I just want a simple check to see if the "@" character is in the address. Here's my code...why doesn't it work? The validation isn't happening.
Thanks for your help!
<html>
<head>
<title><%= FORM_NAME %></title>
<link rel="stylesheet" type="text/css" href="forms.css">
<style type="text/css">
<!--
TD {
font-family: Arial;
font-size: 9pt;
}
-->
</style>
</head>
<body <!-- #include file="bodytag.asp" -->>
<!-- #include file="bodyheader2.asp" -->
<script language="VBScript">
dim validation
Function MyForm_OnSubmit
validation = True
If(document.MyForm.strMailTo.Value) = "" Then
MsgBox("An E-mail address is required")
validation = False
Elseif(InStr(1,document.MyForm.strMailTo.Value,"@",1)<2) Then
MsgBox("Your Email address is invalid")
validation = False
End If
If validation = True Then
MyForm_OnSubmit = True
Else
MyForm_OnSubmit = False
End if
End Function
</script>
<%
' setup variables
Dim strLoginID
strLoginID = Replace(Request.ServerVariables("LOGON_USER"), "NA\", "")
Const FORM_NAME = "Seating Incentive Form"
Dim strMailTo, strCopyTo
strMailTo = Request.Form("tbxTo")
strCopyTo = "gcook1@steelcase.com"
If strMailTo <> "" Then ' send email
' format email body
Dim strBody
strBody = "To: " & strMailTo & VbCrLf & _
"Cc: " & strCopyTo & VbCrLf & _
"From: " & strLoginID & "@steelcase.com" & VbCrLf & _
"Date: " & Date & " Time: " & Time & VbCrLf & VbCrLf
' send email
Dim objMail
Set objMail = Server.CreateObject("CDO.Message")
With objMail
.To = strMailTo
.CC = strCopyTo
.From = strLoginID & "@steelcase.com"
.Subject = FORM_NAME
.TextBody = strBody
.Send
End With
Set objMail = Nothing
Response.Redirect "thankyou.asp"
End If
%>
<br><center><h3><%= FORM_NAME %></center></h3>
<!-- this table is used to control format of the page -->
<table width="600" cellpadding="5" cellspacing="0" align="center" style="{border-width: 1px; border-color: gray; border-style: solid }"><tr><td bgcolor="#E5E5E5">
<form name="Form" action="<%= Request.ServerVariables("Script_Name") %>" method="post">
<table>
<tr><td>To:</td><td><input type="text" name="tbxTo" size="30"></td></tr>
<tr><td>Cc:</td><td>Gary Cook</td></tr>
<tr><td>From:</td><td><%= LCase(strLoginID) %>@steelcase.com</td></tr>
<tr><td>Subject:</td><td><%= FORM_NAME %></td></tr>
<tr><td>Date:</td><td><%= Date %></td></tr>
<tr><td>Time:</td><td><%= Time %></td></tr>
</table><br>
<table align="center" width="100%">
<tr>
<td align="center"><input type="reset" value="Clear Form"> <input type="submit" value="Submit Form"></td>
</tr>
</table>
</form>
<!-- this table is used to control format of the page -->
</td></tr></table><br><br>
<!-- #include file="footer.asp" -->
</body>
</html>
Thanks for your help!
<html>
<head>
<title><%= FORM_NAME %></title>
<link rel="stylesheet" type="text/css" href="forms.css">
<style type="text/css">
<!--
TD {
font-family: Arial;
font-size: 9pt;
}
-->
</style>
</head>
<body <!-- #include file="bodytag.asp" -->>
<!-- #include file="bodyheader2.asp" -->
<script language="VBScript">
dim validation
Function MyForm_OnSubmit
validation = True
If(document.MyForm.strMailTo.Value) = "" Then
MsgBox("An E-mail address is required")
validation = False
Elseif(InStr(1,document.MyForm.strMailTo.Value,"@",1)<2) Then
MsgBox("Your Email address is invalid")
validation = False
End If
If validation = True Then
MyForm_OnSubmit = True
Else
MyForm_OnSubmit = False
End if
End Function
</script>
<%
' setup variables
Dim strLoginID
strLoginID = Replace(Request.ServerVariables("LOGON_USER"), "NA\", "")
Const FORM_NAME = "Seating Incentive Form"
Dim strMailTo, strCopyTo
strMailTo = Request.Form("tbxTo")
strCopyTo = "gcook1@steelcase.com"
If strMailTo <> "" Then ' send email
' format email body
Dim strBody
strBody = "To: " & strMailTo & VbCrLf & _
"Cc: " & strCopyTo & VbCrLf & _
"From: " & strLoginID & "@steelcase.com" & VbCrLf & _
"Date: " & Date & " Time: " & Time & VbCrLf & VbCrLf
' send email
Dim objMail
Set objMail = Server.CreateObject("CDO.Message")
With objMail
.To = strMailTo
.CC = strCopyTo
.From = strLoginID & "@steelcase.com"
.Subject = FORM_NAME
.TextBody = strBody
.Send
End With
Set objMail = Nothing
Response.Redirect "thankyou.asp"
End If
%>
<br><center><h3><%= FORM_NAME %></center></h3>
<!-- this table is used to control format of the page -->
<table width="600" cellpadding="5" cellspacing="0" align="center" style="{border-width: 1px; border-color: gray; border-style: solid }"><tr><td bgcolor="#E5E5E5">
<form name="Form" action="<%= Request.ServerVariables("Script_Name") %>" method="post">
<table>
<tr><td>To:</td><td><input type="text" name="tbxTo" size="30"></td></tr>
<tr><td>Cc:</td><td>Gary Cook</td></tr>
<tr><td>From:</td><td><%= LCase(strLoginID) %>@steelcase.com</td></tr>
<tr><td>Subject:</td><td><%= FORM_NAME %></td></tr>
<tr><td>Date:</td><td><%= Date %></td></tr>
<tr><td>Time:</td><td><%= Time %></td></tr>
</table><br>
<table align="center" width="100%">
<tr>
<td align="center"><input type="reset" value="Clear Form"> <input type="submit" value="Submit Form"></td>
</tr>
</table>
</form>
<!-- this table is used to control format of the page -->
</td></tr></table><br><br>
<!-- #include file="footer.asp" -->
</body>
</html>