FedEx
09-13-2005, 02:01 AM
I want to put a CDONTS script on the same page as my submission form. The problem I have is that as soon as I load the page, the script executes and sends a blank email. Here is a modified copy of my page. Can I move the CDONTS script elsewhere on the page so it executes at the right time or can I edit the script so it won' t fire until the user clicks submit?
<%
DIM strMonth, strDay
strMonth = request.form("DDATE")
strDay = request.form("DDATE1")
DIM objEMail
set objEMail = Server.CreateObject("CDONTS.NewMail")
objEMail.To = "xxxx@yahoo.com"
objEMail.Cc = ""
objEMail.From = "email@hotmail.com"
objEMail.subject = strMonth & "/" & strDay & "/" & "Form Results"
objEMail.Bcc = ""
objEMail.Importance = 1 '(0=Low, 1=Normal, 2=High)
objEMail.body = "<html><p>" & vbCrLf _
& " <table>" & vbCrLf _
& " <tr>" & vbCrLf _
& " <td>" & vbCrLf _
& " " & strMonth & strDay & vbCrLf _
& " </td>" & vbCrLf _
& " <tr>" & vbCrLf _
& "</table>" & vbCrLf _ ....(html table code)
& "</html>" & vbCrLf
On Error Resume Next
objEMail.send
set objEMail = nothing
IF Err <> 0 THEN
Response.Write "There has been an error and your message could not be sent
through email. " & Err.Description
END IF
%>
<%
Actionvar=Request.QueryString("actionvar")
Set conn = server.createobject("adodb.connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("fpdb\YVRPM.mdb")
conn.Open DSNtemp
IF Actionvar="add" THEN
IF Len(TRIM(request.form("flag"))) = 0 THEN
%>
<FORM METHOD="post" ACTION="form.asp?Actionvar=add" onsubmit="return
formvalidation(this)">
<INPUT TYPE="text" NAME="DDATE" size="3">
<INPUT TYPE="text" NAME="DDATE1" size="3">
<INPUT TYPE="submit" VALUE="ADD">
</FORM>
<%
ELSEIF Request.Form("flag")="2" THEN
SQLstmt = "INSERT INTO 0139 (DDATE,DDATE1)
SQLstmt = SQLstmt & " VALUES ('" & request.form("DDATE") & "','" & request.form("DDATE1") & "')"
%>
conn.Close
Set conn = nothing
Set SQLstmt = nothing
%>
<%
conn.execute(SQLstmt)
Response.Write "Operation Complete
conn.Close
Set conn = nothing
Set SQLstmt = nothing
%>
<%
DIM strMonth, strDay
strMonth = request.form("DDATE")
strDay = request.form("DDATE1")
DIM objEMail
set objEMail = Server.CreateObject("CDONTS.NewMail")
objEMail.To = "xxxx@yahoo.com"
objEMail.Cc = ""
objEMail.From = "email@hotmail.com"
objEMail.subject = strMonth & "/" & strDay & "/" & "Form Results"
objEMail.Bcc = ""
objEMail.Importance = 1 '(0=Low, 1=Normal, 2=High)
objEMail.body = "<html><p>" & vbCrLf _
& " <table>" & vbCrLf _
& " <tr>" & vbCrLf _
& " <td>" & vbCrLf _
& " " & strMonth & strDay & vbCrLf _
& " </td>" & vbCrLf _
& " <tr>" & vbCrLf _
& "</table>" & vbCrLf _ ....(html table code)
& "</html>" & vbCrLf
On Error Resume Next
objEMail.send
set objEMail = nothing
IF Err <> 0 THEN
Response.Write "There has been an error and your message could not be sent
through email. " & Err.Description
END IF
%>
<%
Actionvar=Request.QueryString("actionvar")
Set conn = server.createobject("adodb.connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("fpdb\YVRPM.mdb")
conn.Open DSNtemp
IF Actionvar="add" THEN
IF Len(TRIM(request.form("flag"))) = 0 THEN
%>
<FORM METHOD="post" ACTION="form.asp?Actionvar=add" onsubmit="return
formvalidation(this)">
<INPUT TYPE="text" NAME="DDATE" size="3">
<INPUT TYPE="text" NAME="DDATE1" size="3">
<INPUT TYPE="submit" VALUE="ADD">
</FORM>
<%
ELSEIF Request.Form("flag")="2" THEN
SQLstmt = "INSERT INTO 0139 (DDATE,DDATE1)
SQLstmt = SQLstmt & " VALUES ('" & request.form("DDATE") & "','" & request.form("DDATE1") & "')"
%>
conn.Close
Set conn = nothing
Set SQLstmt = nothing
%>
<%
conn.execute(SQLstmt)
Response.Write "Operation Complete
conn.Close
Set conn = nothing
Set SQLstmt = nothing
%>