Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2003, 08:08 PM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP form to email & update Access db

I've created an asp page that contains a form (Supplier_Reg.asp). Once the user clicks submit, the form is validated (using an external script for validating only - validateform.js); an access database is updated and a Thank you page opens (addsupplier.asp). These pages work with the db being updated and the thank you page appearing.

I also created two other pages (for testing purposes because I'd never worked with CDONTS) where I created a form (input.asp) that when the user clicks submit, an email using CDONTS that contains the contents from the form is sent to a hidden address and a thank you page appears (output.asp).

My question is: How would I combine the two pieces? My end result should be the user fills out the form from Supplier_Reg.asp; when they click Submit it posts to addsupplier.asp; the form is validated and an email is sent which contains the contents of the form AND a small text message).

Code for Supplier_Reg.asp is as follows:
<html>
<head>
<title>Registration Form Page</title>

<script language="JavaScript" src="validateform.js" type="text/javascript"></script>
</head>
<body>

<br><b>- Registration Form -</b>

<table BORDER=1 CELLSPACING=0 CELLPADDING=2 WIDTH="100%" BGCOLOR="#C7C8C9" >
<tr>
<td><form name="supplyreg" method="post" action="addsupplier.asp">
<table BORDER=0 CELLSPACING=0 CELLPADDING=3 WIDTH="100%" >
<tr ALIGN=LEFT VALIGN=TOP>
<td>Company Name</td>
<td><input type="text" name="D_Company" size="35" maxlength="35"></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="D_Address" size="45" maxlength="45"></td>
</tr>
<tr>
<td>City, State, Zip</td>
<td><input type="text" name="D_City" size="35" maxlength="35"><input type="text" name="D_State" size="2" maxlength="2"><input type="text" name="D_Zip" size="5" maxlength="5"></td>
</tr>
<tr ALIGN=LEFT VALIGN=TOP>
<td>Phone</td>
<td><input type="text" name="D_Phone" size="14" maxlength="14"></td>
</tr>
<tr>
<td>Fax</td>
<td><input type="text" name="D_Fax" size="14" maxlength="14"></td>
</tr>
<tr>
<td>Website Address</td>
<td><input type="text" name="D_Website" size="50" maxlength="50"></td>
</tr>
<tr>
<td>Contact Person</td>
<td><input type="text" name="D_Contact" size=35 maxlength=35></td>
</tr>
<tr>
<td>Contact Phone</td>
<td><input type="text" name="D_CPhone" size=14 maxlength=14></td>
</tr>
<tr>
<td>Contact Email (Please check for accuracy prior to submission)</td>
<td><input type="text" name="D_Email" size=40 maxlength=40></td>
</tr>
<tr>
<td>Products and/or Services: (Please be general)</td>
<td><textarea name="D_Commodities" cols="37" rows="7"></textarea></td>
</tr>
<tr>
<td><input type="hidden" name="hidDate"></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=5 CELLPADDING=5 WIDTH="60%" >
<tr>
<td><center><input type="submit" name="Submit" value="Register"></center></td>
<td><input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form>
</table
</body>
</html>

Code for addsupplier.asp is as follows:
<%
Option Explicit

'Declare variables
Dim strCompany
Dim strAddress
Dim strCity
Dim strState
Dim strZip
Dim strPhone
Dim strFax
Dim strWebsite
Dim strContact
Dim strCPhone
Dim strEmail
Dim strCommodities
Dim strhidDate
Dim SQLINSERT
Dim connupdate

'Grab variables from the querystring.
strCompany=Request.Form("D_Company")
strAddress=Request.Form("D_Address")
strCity=Request.Form("D_City")
strState=Request.Form("D_State")
strZip=Request.Form("D_Zip")
strPhone=Request.Form("D_Phone")
strFax=Request.Form("D_Fax")
strWebsite=Request.Form("D_Website")
strContact=Request.Form("D_Contact")
strCPhone=Request.Form("D_CPhone")
strEmail=Request.Form("D_Email")
strCommodities=Request.Form("D_Commodities")
strhidDate=Request.Form("hidDate")

SQLINSERT = "INSERT INTO WebSupplier(Company_Name, St_Address, City, State, Zip, Phone_Num, Fax_Num, Web_Site, Contact_Person, Contact_Phone, Contact_Email, Commodities, Respond_Da) Values('" & replace(strCompany, "'", "") & "', '" & replace(strAddress, "'", "") & "', '" & replace(strCity, "'", "") & "', '" & strState & "', '" & strZip & "', '" & strPhone & "', '" & strFax & "', '" & replace(strWebsite, "'", "") & "', '" & replace(strContact, "'", "") & "', '" & strCPhone & "', '" & replace(strEmail, "'", "") & "', '" & replace(strCommodities, "'", "") & "', '" & strhidDate & "')"

set connupdate = server.createobject("ADODB.Connection")
connupdate.open "Register"
connupdate.execute(SQLINSERT)

connupdate.close
set connupdate = nothing
%>
<html>
<head>
<title>Registration Thank You Page</title>
</head>
<body>
<center><table BORDER=0 CELLSPACING=2 CELLPADDING=2 COLS=1 WIDTH="97%" >
<tr>
<td><center>REGISTRATION COMPLETED</center>
<center><b>
<% Response.Write(strCompany) %>
<% Response.Write "<br>" %>
<% Response.Write "Thank you for registering!" %> </b></center>
<br><center>
<% Response.Write "You have now been added to the Registration Database. If a product or service is needed you will be contacted. We appreciate your time and effort in completing the Registration Form." %>
<p>
<% Response.Write "Thank you!" %> </center>
</td>
</tr>
</table></center>
</body>
</html>

I didn't add the email code to keep it short. Any help would be appreciated. Thanks a million!!
 
Old June 12th, 2003, 10:26 PM
Authorized User
 
Join Date: Jun 2003
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default

All you need to do is straigh after adding data to db is create a new mail instance and send the email off. You have already done all the work by declared and assigned the variables so setup your cdonts component.

eg
<%
Option Explicit

'Declare variables
Dim strCompany
Dim strAddress
Dim strCity
Dim strState
Dim strZip
Dim strPhone
Dim strFax
Dim strWebsite
Dim strContact
Dim strCPhone
Dim strEmail
Dim strCommodities
Dim strhidDate
Dim SQLINSERT
Dim connupdate

'Grab variables from the querystring.
strCompany=Request.Form("D_Company")
strAddress=Request.Form("D_Address")
strCity=Request.Form("D_City")
strState=Request.Form("D_State")
strZip=Request.Form("D_Zip")
strPhone=Request.Form("D_Phone")
strFax=Request.Form("D_Fax")
strWebsite=Request.Form("D_Website")
strContact=Request.Form("D_Contact")
strCPhone=Request.Form("D_CPhone")
strEmail=Request.Form("D_Email")
strCommodities=Request.Form("D_Commodities")
strhidDate=Request.Form("hidDate")

SQLINSERT = "INSERT INTO WebSupplier(Company_Name, St_Address, City, State, Zip, Phone_Num, Fax_Num, Web_Site, Contact_Person, Contact_Phone, Contact_Email, Commodities, Respond_Da) Values('" & replace(strCompany, "'", "") & "', '" & replace(strAddress, "'", "") & "', '" & replace(strCity, "'", "") & "', '" & strState & "', '" & strZip & "', '" & strPhone & "', '" & strFax & "', '" & replace(strWebsite, "'", "") & "', '" & replace(strContact, "'", "") & "', '" & strCPhone & "', '" & replace(strEmail, "'", "") & "', '" & replace(strCommodities, "'", "") & "', '" & strhidDate & "')"

set connupdate = server.createobject("ADODB.Connection")
connupdate.open "Register"
connupdate.execute(SQLINSERT)

connupdate.close
set connupdate = nothing

' Create an instance of the NewMail object.
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")

' Format Email Body
Dim BodyText

BodyText = "Supplier Registration from " & strCompany & VbCrLf
BodyText = BodyText & "Company Name: " & strCompany & VbCrLf
BodyText = BodyText & "Address: " & strAddress & VbCrLf
ect. ect.

' Set the properties of the object
objCDOMail.From = anyvariable
objCDOMail.To = anyvariable
objCDOMail.Subject = anyvariable
objCDOMail.Body = BodyText
' Send the message!
objCDOMail.Send
Set objCDOMail = Nothing
%>

Hope it helps

TDA
 
Old July 19th, 2003, 03:32 PM
Registered User
 
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to tyson Send a message via MSN to tyson
Default

i know you keep the email part of the code out Because you wanted to save space do you think maybe i can get that code and the please let me know were i put my email address in this code that is the part i am so lost with thank you so much

 
Old July 22nd, 2003, 01:39 AM
Authorized User
 
Join Date: Jul 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sankar
Default

Quote:
quote:Originally posted by seala
 I've created an asp page that contains a form (Supplier_Reg.asp). Once the user clicks submit, the form is validated (using an external script for validating only - validateform.js); an access database is updated and a Thank you page opens (addsupplier.asp). These pages work with the db being updated and the thank you page appearing.

I also created two other pages (for testing purposes because I'd never worked with CDONTS) where I created a form (input.asp) that when the user clicks submit, an email using CDONTS that contains the contents from the form is sent to a hidden address and a thank you page appears (output.asp).

My question is: How would I combine the two pieces? My end result should be the user fills out the form from Supplier_Reg.asp; when they click Submit it posts to addsupplier.asp; the form is validated and an email is sent which contains the contents of the form AND a small text message).

Code for Supplier_Reg.asp is as follows:
<html>
<head>
<title>Registration Form Page</title>

<script language="JavaScript" src="validateform.js" type="text/javascript"></script>
</head>
<body>

<br><b>- Registration Form -</b>

<table BORDER=1 CELLSPACING=0 CELLPADDING=2 WIDTH="100%" BGCOLOR="#C7C8C9" >
<tr>
<td><form name="supplyreg" method="post" action="addsupplier.asp">
<table BORDER=0 CELLSPACING=0 CELLPADDING=3 WIDTH="100%" >
<tr ALIGN=LEFT VALIGN=TOP>
<td>Company Name</td>
<td><input type="text" name="D_Company" size="35" maxlength="35"></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="D_Address" size="45" maxlength="45"></td>
</tr>
<tr>
<td>City, State, Zip</td>
<td><input type="text" name="D_City" size="35" maxlength="35"><input type="text" name="D_State" size="2" maxlength="2"><input type="text" name="D_Zip" size="5" maxlength="5"></td>
</tr>
<tr ALIGN=LEFT VALIGN=TOP>
<td>Phone</td>
<td><input type="text" name="D_Phone" size="14" maxlength="14"></td>
</tr>
<tr>
<td>Fax</td>
<td><input type="text" name="D_Fax" size="14" maxlength="14"></td>
</tr>
<tr>
<td>Website Address</td>
<td><input type="text" name="D_Website" size="50" maxlength="50"></td>
</tr>
<tr>
<td>Contact Person</td>
<td><input type="text" name="D_Contact" size=35 maxlength=35></td>
</tr>
<tr>
<td>Contact Phone</td>
<td><input type="text" name="D_CPhone" size=14 maxlength=14></td>
</tr>
<tr>
<td>Contact Email (Please check for accuracy prior to submission)</td>
<td><input type="text" name="D_Email" size=40 maxlength=40></td>
</tr>
<tr>
<td>Products and/or Services: (Please be general)</td>
<td><textarea name="D_Commodities" cols="37" rows="7"></textarea></td>
</tr>
<tr>
<td><input type="hidden" name="hidDate"></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=5 CELLPADDING=5 WIDTH="60%" >
<tr>
<td><center><input type="submit" name="Submit" value="Register"></center></td>
<td><input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form>
</table
</body>
</html>

Code for addsupplier.asp is as follows:
<%
Option Explicit

'Declare variables
Dim strCompany
Dim strAddress
Dim strCity
Dim strState
Dim strZip
Dim strPhone
Dim strFax
Dim strWebsite
Dim strContact
Dim strCPhone
Dim strEmail
Dim strCommodities
Dim strhidDate
Dim SQLINSERT
Dim connupdate

'Grab variables from the querystring.
strCompany=Request.Form("D_Company")
strAddress=Request.Form("D_Address")
strCity=Request.Form("D_City")
strState=Request.Form("D_State")
strZip=Request.Form("D_Zip")
strPhone=Request.Form("D_Phone")
strFax=Request.Form("D_Fax")
strWebsite=Request.Form("D_Website")
strContact=Request.Form("D_Contact")
strCPhone=Request.Form("D_CPhone")
strEmail=Request.Form("D_Email")
strCommodities=Request.Form("D_Commodities")
strhidDate=Request.Form("hidDate")

SQLINSERT = "INSERT INTO WebSupplier(Company_Name, St_Address, City, State, Zip, Phone_Num, Fax_Num, Web_Site, Contact_Person, Contact_Phone, Contact_Email, Commodities, Respond_Da) Values('" & replace(strCompany, "'", "") & "', '" & replace(strAddress, "'", "") & "', '" & replace(strCity, "'", "") & "', '" & strState & "', '" & strZip & "', '" & strPhone & "', '" & strFax & "', '" & replace(strWebsite, "'", "") & "', '" & replace(strContact, "'", "") & "', '" & strCPhone & "', '" & replace(strEmail, "'", "") & "', '" & replace(strCommodities, "'", "") & "', '" & strhidDate & "')"

set connupdate = server.createobject("ADODB.Connection")
connupdate.open "Register"
connupdate.execute(SQLINSERT)

connupdate.close
set connupdate = nothing
%>
<html>
<head>
<title>Registration Thank You Page</title>
</head>
<body>
<center><table BORDER=0 CELLSPACING=2 CELLPADDING=2 COLS=1 WIDTH="97%" >
<tr>
<td><center>REGISTRATION COMPLETED</center>
<center><b>
<% Response.Write(strCompany) %>
<% Response.Write "<br>" %>
<% Response.Write "Thank you for registering!" %> </b></center>
<br><center>
<% Response.Write "You have now been added to the Registration Database. If a product or service is needed you will be contacted. We appreciate your time and effort in completing the Registration Form." %>
<p>
<% Response.Write "Thank you!" %> </center>
</td>
</tr>
</table></center>
</body>
</html>

I didn't add the email code to keep it short. Any help would be appreciated. Thanks a million!!

Hi seala,
First of all in the Supplier_Reg.asp page you should add the following line inside your FORM tag
onSubmit="return yourfunctionname();"
Otherwise your form will not be validated at client-side. This code ensures unless your required fields are entered the form will not be posted.
Then lets go to the addsupplier.asp page. Here you can write the code for adding new record to access database. The trick is here you can write a Sub to send email using CDO NTS.You should have some kind of error traping mech like using On Error Resume Next statement at the begining of the page. And after addition check if Err.Number >0, if it is, then there is error so redirect to an error page. If not, call this Sub, say sendmail [Call sendmail(toAddress,fromAddress)] In this sub you write the email sending code. Just next line of call the sub, you redirect user to a thank you page, instead of writing this in the same page. So, total you need four pages. Hope this will solve your problem
Chao






Similar Threads
Thread Thread Starter Forum Replies Last Post
New to Access & DB gbowne1 Access 16 December 13th, 2008 02:36 AM
Update db showing data in form Chamaeleon PHP How-To 2 January 26th, 2006 05:55 PM
Send email & submit to DB at same time brettdalldorf ASP.NET 1.0 and 1.1 Basics 2 July 2nd, 2005 08:49 AM
how to edit and update my access db using asp.net method ASP.NET 1.0 and 1.1 Basics 4 April 25th, 2005 03:03 PM
update access db with dataset DennisGi ASP.NET 1.0 and 1.1 Basics 0 November 8th, 2004 04:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.