|
-
Feb 26th, 2001, 08:14 AM
#4
Fanatic Member
visordown
Well, this should work:
Create a HTML page named "mySubmitPage.htm" and paste in the following:
Code:
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM NAME="NewMessage" ACTION="PostData.asp?action=save" METHOD="post">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD VALIGN="top" ALIGN="right">Name: </TD>
<TD><INPUT TYPE="text" NAME="name" MAXLENGTH="50" VALUE=""></INPUT></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="right">E-mail: </TD>
<TD><INPUT TYPE="text" NAME="email" MAXLENGTH="50" VALUE=""></INPUT></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="right">Item 1: </TD>
<TD><INPUT TYPE="text" NAME="Item1" MAXLENGTH="50" VALUE=""></INPUT></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="right">Item 2: </TD>
<TD><INPUT TYPE="text" NAME="Item2" MAXLENGTH="50" VALUE=""></INPUT></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="right">Item 3: </TD>
<TD><INPUT TYPE="text" NAME="Item3" MAXLENGTH="50" VALUE=""></INPUT></TD>
</TR>
<TR>
<TD COLSPAN="2" ALIGN="right"><INPUT TYPE="reset" VALUE="Reset Form" id=reset1 name=reset1> <INPUT TYPE="submit" VALUE="Post Data" id=submit1 name=submit1></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
Then create an ASP page called "PostData.asp" and paste in the following code:
Code:
<%@ Language=VBScript %>
<%
' Default Access 2000 DB connection info
' Not using a constant, as the MapPath function is used in string
Dim DB_CONNECTIONSTRING
DB_CONNECTIONSTRING = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database/MyData.mdb") & ";"
' Sample SQL Server connection info
'Const DB_CONNECTIONSTRING = "Provider=SQLOLEDB; Data Source=myServer; Initial Catalog=myDater;"
'Const DB_USERNAME = "webuser"
'Const DB_PASSWORD = "webuser"
Const SEND_EMAIL = True
' This is the From address which will send the email
' Typicaly this is an account on your exchange.server in the same PC as IIS.
Const EMAIL_SERVER_ADDR = "Keyfax Webmaster <[email protected]>"
' You'll need to modify this function to use whatever email compnent
' you prefer if you want to use email notification.
Sub SendEmail(strTo, strSubject, strBody)
' DB and email object vars for email notification
Dim objCDOMail
' Make sure emailing is enabled
If SEND_EMAIL Then
' Create an instance of the NewMail object.
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
' Set the properties of the object
objCDOMail.From = EMAIL_SERVER_ADDR
objCDOMail.To = strTo
objCDOMail.Subject = strSubject
objCDOMail.Body = strBody
' Send the message!
objCDOMail.Send
Set objCDOMail = Nothing
End If
End Sub ' SendEmail
' Open up the database and INSERT the data
Sub InsertData(sName, sItem1, sItem2, sItem3)
Dim conn
Dim sql
Set conn = Server.createobject("ADODB.CONNECTION")
conn.open DB_CONNECTIONSTRING
sql = "INSERT INTO myTable(Name, Item1, Item2, Item3) " & _
"VALUES ('" & sName & "', '" & sItem1 & "', '" & sItem2 & "', '" & sItem3 & "')"
conn.execute(sql)
Set conn=Nothing
End Sub ' InsertData
Sub DoSubmit()
Dim sSubject, sMessage, bNotify
Dim sItem1, sItem2, sItem3
Dim sName, sEmail ' User Info from Cookies
Select Case Request.QueryString("action")
Case "save"
' Retrieve parameters
sName = oConfirmation.name.Value
sEmail = oConfirmation.email.Value
'' The name and email could be fetched from a cookie as follows
' sName = Request.Cookies("name")
' sEmail = Request.Cookies("email")
'' If the data is held in a database, then query for data based
'' on a supplied userID as follows
' Dim conn, strSQL, ORS, strUserID
' strUserID = Request.Form("UserID")
' conn.open DB_CONNECTIONSTRING
' strSQL = "SELECT name, email FROM users WHERE userID = '" & strUserID & "'"
' Set ORS = conn.execute(sql)
' If Not ORS.EOF Then
' sName = ORS.Fields("name")
' sEmail = ORS.Fields("email")
' End If
'
'' There obviously needs some validation here for a password
'' This example is for reference only.
' Add all the items on the form which are to be validated and
' in turn to be included in the Email confirmation and database INSERT.
sItem1 = oConfirmation.Item1.Value
sItem2 = oConfirmation.Item2.Value
sItem3 = oConfirmation.Item3.Value
' DO YOUR VALIDATION HERE
' To keep this simple I am only checking for values in each input field.
If Len(Trim(oConfirmation.Item1.Value)) > 0 Or Len(Trim(oConfirmation.Item2.Value)) > 0 Or Len(Trim(oConfirmation.Item3.Value)) > 0 Then
sSubject = "Submission notification"
sMessage = "Item1=[" & oConfirmation.Item1.Value & "]" & vbCrLf & _
"Item2=[" & oConfirmation.Item2.Value & "]" & vbCrLf & _
"Item3=[" & oConfirmation.Item3.Value & "]"
' Send the email confirmation to the user
SendEmail sEmail, sSubject, sMessage
InsertData sName, sItem1, sItem2, sItem3
Else
End If
Case Else
End Select
End Sub
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>Confirmation</TITLE>
</HEAD>
<BODY>
<FORM NAME="oConfirmation">
<P>You have requested to send the following data. Please confirm the following details are correct</P>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD VALIGN="top" ALIGN="right">Name: </TD>
<TD><INPUT TYPE="text" NAME="name" MAXLENGTH="50" VALUE="<%=Request.Form("name")%>"></INPUT></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="right">E-mail: </TD>
<TD><INPUT TYPE="text" NAME="email" MAXLENGTH="50" VALUE="<%=Request.Form("email")%>"></INPUT></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="right">Item 1: </TD>
<TD><INPUT TYPE="text" NAME="Item1" MAXLENGTH="50" VALUE="<%=Request.Form("Item1")%>"></INPUT></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="right">Item 2: </TD>
<TD><INPUT TYPE="text" NAME="Item2" MAXLENGTH="50" VALUE="<%=Request.Form("Item2")%>"></INPUT></TD>
</TR>
<TR>
<TD VALIGN="top" ALIGN="right">Item 3: </TD>
<TD><INPUT TYPE="text" NAME="Item3" MAXLENGTH="50" VALUE="<%=Request.Form("Item3")%>"></INPUT></TD>
</TR>
<TR>
<TD COLSPAN="2" ALIGN="right"><INPUT TYPE="button" VALUE="Send Data" id=submit1 name=submit1 onClick="DoSubmit()"></INPUT></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
You will have to check with your server administrator about the email service running on the server and change accordingly. I have used CDONTS.
When both are in IIS, in the same folder, run "mySubmitPage".
Hope this helps
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|