Wrox Programmer Forums
Classic ASP Professional For advanced coder questions in ASP 3. 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 Professional 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 February 1st, 2007, 10:21 AM
Registered User
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to stecol
Default sending email based on form value


I have set up a form which sends an email via CDONTS which works fine. What i need to do is set up another email address and send the form to this address only if a certain field in the form has been filled in.
Eg. The form is regarding student details. There is a field for 'previous address'. If this field has a value, it is sent to the exclusion team via email.

Any help appreciated. Thanks. My code is below:


Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_emsdb_STRING
Recordset1.Source = "SELECT School  FROM emstable"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1

Recordset1_numRows = 0
Dim Recordset2
Dim Recordset2_numRows

Set Recordset2 = Server.CreateObject("ADODB.Recordset")
Recordset2.ActiveConnection = MM_allschools_STRING
Recordset2.Source = "SELECT allschools  FROM allschools"
Recordset2.CursorType = 0
Recordset2.CursorLocation = 2
Recordset2.LockType = 1

Recordset2_numRows = 0
<% 'no security checking %>
session.lcid = 2057
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.CacheControl = "no-cache"

response.buffer = true
'get key
key = request.querystring("key")
if key="" or isnull(key) then
end if

'get action

'get fields from form

x_ID = key
x_yourname = Request.Form("x_yourname")
x_youremail = Request.Form("x_youremail")
x_Date = Request.Form("x_Date")
x_ID = Request.Form("x_ID")
x_Forename = Request.Form("x_Forename")
x_Surname = Request.Form("x_Surname")
x_DOB = Request.Form("x_DOB")
x_Address = Request.Form("x_Address")
x_PreviousAddress = Request.Form("x_PreviousAddress")
x_Postcode = Request.Form("x_Postcode")
x_School = Request.Form("x_School")
x_districts = Request.Form("x_districts")
x_Pending = Request.Form("x_Pending")
x_Additional_comments = Request.Form("x_Additional_comments")

'---Dim all values for CDONTS email here---'

if Request.Form("Action") = "ADD" then

Dim objCDO

        Set objCDO = Server.CreateObject("CDONTS.NewMail")

        objCDO.From = "DCSEMS@knowsley.gov.uk"

        objCDO.To = "DCSEMS@knowsley.gov.uk"

        objCDO.Cc = x_youremail

        objCDO.Bcc = ""

        objCDO.Subject = "EMS - new entry (ID:" & key & ")"

'---below is what sends the HTML format to email address---'

bodyHTML = "<html><head></head><body>" & "" & "A new entry has been added to the EMS database (ID:" & key & ")" & "<br>" & "" & "<br>" & "Please click the link below to view the new entry and change 'Pending' to 'No' once it has been imported to EMS" & "<br>" & "<br>" & "<a href=""http://klp.kmbc/knowsley/DataTeam/EMStracking/emstablelist.asp"">Click here to launch EMS Pending list</a>"

        objCDO.Body = bodyHTML

        objCDO.BodyFormat = 0

        objCDO.MailFormat = 0


        ConfirmMsg = "This entry has been added to the list and a notification has been sent to the Data Team.  You will receive a confirmation email once this entry has been added to EMS.  Thankyou."

        end if

' Open Connection to the database
set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str

Select Case a
    Case "A": ' Add

        ' Open record
        strsql = "SELECT * FROM [emstable] WHERE 0 = 1"

        set rs = Server.CreateObject("ADODB.Recordset")
        rs.Open strsql, conn, 1, 2


tmpFld = Trim(x_yourname)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("yourname") = tmpFld
tmpFld = Trim(x_youremail)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("youremail") = tmpFld        
tmpFld = Trim(x_Date)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("Date") = tmpFld
tmpFld = Trim(x_Forename)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("Forename") = tmpFld
tmpFld = Trim(x_Surname)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("Surname") = tmpFld
tmpFld = Trim(x_DOB)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("DOB") = tmpFld
tmpFld = Trim(x_Address)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("Address") = tmpFld
tmpFld = Trim(x_PreviousAddress)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("PreviousAddress") = tmpFld
tmpFld = Trim(x_Postcode)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("Postcode") = tmpFld
tmpFld = Trim(x_School)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("School") = tmpFld
tmpFld = Trim(x_districts)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("districts") = tmpFld
tmpFld = x_Pending
If tmpFld = "Yes" Then
    rs("Pending") = True
    rs("Pending") = False
End If
tmpFld = Trim(x_Additional_comments)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("Additional comments") = tmpFld

        Set rs = Nothing
        Set conn = Nothing
        Response.Redirect "emstablelist.asp"
End Select
%><title>EMS additions&amp;tracking - Add</title>
<body leftmargin="20">
<p><strong>Add to TABLE : emstable<br>
provide your details so we can let you know once the pupil has been added to
    <a href="emstablelist.asp">Back to List</a></p>
<script language="JavaScript" src="ew.js"></script>
<script language="JavaScript">
<!-- start Javascript
function  EW_checkMyForm(EW_this) {
return true;
// end JavaScript -->
<% if ConfirmMsg <> "" then %>
<script language=javascript>
<% End If %>
<form onSubmit="return EW_checkMyForm(this);"  action="emstableadd.asp" method="post">
<input type="hidden" name="a" value="A">
<input type="hidden" name="key" value="<%= key %>">
<table border="0" cellspacing="1" cellpadding="2">
    <td colspan="2">Enter your details here</td>
    <td width="126" bgcolor="#000099">Your
    <td width="298" bgcolor="#FFFFCC">
      <input name="x_yourname" type="text" id="x_yourname" value="<%= x_yourname %>" size=30 maxlength=50>
    <td bgcolor="#000099">Your Email</td>
    <td bgcolor="#FFFFCC">
      <input name="x_youremail" type="text" id="x_youremail" value="<%= x_youremail %>" size=30 maxlength=50>
    <td colspan="2">Enter pupils details here</td>
<td bgcolor="#000099">Date&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="x_Date" value="<%= FormatDateTime(Now) %>" size=30 maxlength=25>
<td bgcolor="#000099">ID&nbsp;</td>
<td bgcolor="#FFFFCC"><%= x_ID %>&nbsp;</td>
<td bgcolor="#000099">Forename&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="x_Forename" value="<%= x_Forename %>" size=30 maxlength=50>&nbsp;</td>
<td bgcolor="#000099">Surname&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="x_Surname" value="<%= x_Surname %>" size=30 maxlength=50>&nbsp;</td>
<td bgcolor="#000099">DOB&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="x_DOB" value="<%= x_DOB %>" size=30 maxlength=25>&nbsp;</td>
<td valign="top" bgcolor="#000099">Address&nbsp;</td>
<td bgcolor="#FFFFCC">
<textarea name="x_Address" cols="30" rows="3"><%= x_Address %></textarea>
  <td valign="top" bgcolor="#000099"><p>Previous
  <td bgcolor="#FFFFCC">
    <textarea name="x_PreviousAddress" cols="30" rows="3"><%= x_PreviousAddress %></textarea>
<td bgcolor="#000099">Postcode&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="x_Postcode" value="<%= x_Postcode %>" size=30 maxlength=20>&nbsp;</td>
<td bgcolor="#000099">School&nbsp;</td>
<td bgcolor="#FFFFCC">
  <select name="x_School" id="x_School">
    <option value="Select School">Select School...</option>
While (NOT Recordset2.EOF)
    <option value="<%=(Recordset2.Fields.Item("allschools").Value)%>"><%=(Recordset2.Fields.Item("allschools").Value)%></option>
If (Recordset2.CursorType > 0) Then
End If
  <td valign="top" bgcolor="#000099">Extra districts?<br>
      If not a KMBC school,<br> 
      enter here</td>
  <td bgcolor="#FFFFCC">
    <textarea name="x_districts" cols="30" rows="2" id="x_districts"><%= x_districts %></textarea>
<td bgcolor="#000099">Pending&nbsp;</td>
<td bgcolor="#FFFFCC">

<INPUT NAME="x_Pending" TYPE="Radio" VALUE="Yes" CHECKED<% If x_Pending = False Then %>CHECKED<% End If %>>
<%= "Yes" %>

<INPUT NAME="x_Pending" TYPE="Radio"  VALUE="No"<% If x_Pending = False Then %>CHECKED<% End If %>>
<%= "No" %>

&nbsp;(please change to Yes if not added to EMS yet)</td>
<td valign="top" bgcolor="#000099">Additional comments&nbsp;</td>
<td bgcolor="#FFFFCC">
<textarea name="x_Additional_comments" cols="30" rows="3"><%= x_Additional_comments %></textarea>
<input type="submit" name="Action" value="ADD">

Set Recordset2 = Nothing
Set Recordset1 = Nothing

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP: Sending a HTML form to an email address cancer10 Classic ASP Databases 4 February 19th, 2007 05:25 PM
sending email from a form x_ray ASP.NET 1.0 and 1.1 Basics 5 February 22nd, 2006 02:58 PM
Retrievin form details and sending email yus_nash Beginning PHP 3 September 16th, 2004 04:48 AM

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