% Option Explicit ' Form processer for TC 2004 proposals %>
Order Confirmation - David's Sugar-Free Sweets
<% ' Start asp section
' *************************** This means a BIG MAIN section
' Put information in database
' ***************************
Dim cnConnect
Dim rsOrder
Dim cmCon
Dim fld
Dim FieldName
Dim FieldValue
Dim adOpenKeyset
Dim adLockPessimistic
adOpenKeyset = 1
adLockPessimistic = 2
' Calculate the cost information from the form information, for example
Dim SubTotal1
Dim SubTotal2
Dim SubTotal3
Dim N1, N2, N3, C1, C2, C3
Dim TotalCost
N1 = Request("Number_1")
N2 = Request("Number_2")
N3 = Request("Number_3")
C1 = Request("Cost_1")
C2 = Request("Cost_2")
C3 = Request("Cost_3")
SubTotal1 = N1 * C1
SubTotal2 = N2 * C2
SubTotal3 = N3 * C3
TotalCost = SubTotal1 + SubTotal2 + SubTotal3
' End of calculation
' -------------------------- This means a sub-section
' MAKE CONNECTION TO DTABASE
Set cnConnect = Server.CreateObject("ADODB.Connection")
cnConnect.ConnectionString = "DSN=[Your DSN]"
cnConnect.Open
' -----------------------------
' CREATE AND OPEN THE RECORDSET
Set rsOrder = CreateObject("ADODB.RecordSet")
rsOrder.CursorLocation = 3 ' adUseClient or client-side cursor
rsOrder.Open "[Your table]", cnConnect, 2, 3
' ---------------------------
' ADD NEW RECORD TO RECORDSET
rsOrder.AddNew
' Populate the database fields by looping over them, For to Next
For each fld in rsOrder.Fields
FieldName = fld.Name
If (FieldName = "Order_Number") Then
' Do nothing - autonumber
' Date and time come from the server clock
ElseIf (FieldName = "Date") Then
rsOrder.Fields("Date") = FormatDateTime(Now, vbShortDate)
ElseIf (FieldName = "Time") Then
rsOrder.Fields("Time") = FormatDateTime(Now, vbShortTime)
' Information calculated in the script must be put in item by item
ElseIf (FieldName = "Status") Then
rsOrder.Fields(FieldName) = "Received"
ElseIf (FieldName = "SubTotal1") Then
rsOrder.Fields(FieldName) = SubTotal1
ElseIf (FieldName = "SubTotal2") Then
rsOrder.Fields(FieldName) = SubTotal2
ElseIf (FieldName = "SubTotal3") Then
rsOrder.Fields(FieldName) = SubTotal3
ElseIf (FieldName = "TotalCost"
rsOrder.Fields(FieldName) = TotalCost
' Information from the form goes in easily
Else
FieldValue = Request(FieldName)
rsOrder.Fields(FieldName) = FieldValue
End If
Next
' End of loop
' Transfer order data from recordset to database
' and transfer the order number from database to recordset
rsOrder.Update
' ********************************************************
' Prepare the response page, will be sent at end of script
' ********************************************************
%>
This is your printable confirmation:
<%
For each fld in rsOrder.Fields
FieldName = fld.Name
FieldValue = rsOrder.Fields(FieldName)
%>
| <%=FieldName%> |
<%=FieldValue%> |
<% Next
%>
We will send a confirming email shortly.
Link back to Our home page
<%
' ******************
' Now send the Email
' ******************
Dim objMail ' The email message
Dim strMessage ' The message content
Dim strName ' The sender's regular name
Dim intEmailOK ' = 1 for Sender's email OK
Dim strSubject ' The topic of the email message
Dim strReceive ' To address
Dim strSender ' The From email address
strReceive = Request("[Email]") ' Customer's email address, must match name of field in form
strSender = "[Your WSU email address]"
strSubject = "Your order from [...]"
' Construct the message
strMessage = ""
For each fld in rsProp.Fields
FieldName = fld.Name
FieldValue = rsProp.Fields(FieldName)
strMessage = strMessage & FieldName & ": " & FieldValue & vbNewLine
Next
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = strSender
objMail.To = strReceive
objMail.Subject = strSubject
objMail.Body = strMessage
objMail.Send ' This is the method, actually sends the email
' Clean up - empty and destroy all objects
Set objMail = Nothing
rsOrder.Close
Set rsOrder = Nothing
cnConnect.Close
Set cnConnect = Nothing
%>