Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to stecol
Default sending email based on form value

Hi,

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:

Code:
<%@LANGUAGE="VBSCRIPT"%>


<%
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.Open()

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.Open()

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
    key=request.form("key")
end if

'get action
a=request.form("a")

'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

        objCDO.Send

        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

        rs.AddNew

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
Else
    rs("Pending") = False
End If
tmpFld = Trim(x_Additional_comments)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("Additional comments") = tmpFld

        rs.Update
        rs.Close
        Set rs = Nothing
        conn.Close
        Set conn = Nothing
        Response.Clear
        Response.Redirect "emstablelist.asp"
End Select
%><title>EMS additions&amp;tracking - Add</title>
<body leftmargin="20">
<p><strong>Add to TABLE : emstable<br>
</strong>Please
provide your details so we can let you know once the pupil has been added to
EMS<br>
  <br>
    <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 -->
</script>
<% if ConfirmMsg <> "" then %>
<script language=javascript>
alert("<%=ConfirmMsg%>")
</script>
<% End If %>
<form onSubmit="return EW_checkMyForm(this);"  action="emstableadd.asp" method="post">
<p>
<input type="hidden" name="a" value="A">
<input type="hidden" name="key" value="<%= key %>">
<table border="0" cellspacing="1" cellpadding="2">
  <tr>
    <td colspan="2">Enter your details here</td>
    </tr>
  <tr>
    <td width="126" bgcolor="#000099">Your
          Name</td>
    <td width="298" bgcolor="#FFFFCC">
      <input name="x_yourname" type="text" id="x_yourname" value="<%= x_yourname %>" size=30 maxlength=50>
    </td>
  </tr>
  <tr>
    <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>
  </tr>
  <tr>
    <td colspan="2">Enter pupils details here</td>
    </tr>
  <tr>
<td bgcolor="#000099">Date&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="x_Date" value="<%= FormatDateTime(Now) %>" size=30 maxlength=25>
&nbsp;</td>
</tr>
<tr>
<td bgcolor="#000099">ID&nbsp;</td>
<td bgcolor="#FFFFCC"><%= x_ID %>&nbsp;</td>
</tr>
<tr>
<td bgcolor="#000099">Forename&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="x_Forename" value="<%= x_Forename %>" size=30 maxlength=50>&nbsp;</td>
</tr>
<tr>
<td bgcolor="#000099">Surname&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="x_Surname" value="<%= x_Surname %>" size=30 maxlength=50>&nbsp;</td>
</tr>
<tr>
<td bgcolor="#000099">DOB&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="x_DOB" value="<%= x_DOB %>" size=30 maxlength=25>&nbsp;</td>
</tr>
<tr>
<td valign="top" bgcolor="#000099">Address&nbsp;</td>
<td bgcolor="#FFFFCC">
<textarea name="x_Address" cols="30" rows="3"><%= x_Address %></textarea>
&nbsp;</td>
</tr>
<tr>
  <td valign="top" bgcolor="#000099"><p>Previous
      Address<br>
      (exclusions)</p></td>
  <td bgcolor="#FFFFCC">
    <textarea name="x_PreviousAddress" cols="30" rows="3"><%= x_PreviousAddress %></textarea>
  </td>
</tr>
<tr>
<td bgcolor="#000099">Postcode&nbsp;</td>
<td bgcolor="#FFFFCC"><input type="text" name="x_Postcode" value="<%= x_Postcode %>" size=30 maxlength=20>&nbsp;</td>
</tr>
<tr>
<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>
    <%
  Recordset2.MoveNext()
Wend
If (Recordset2.CursorType > 0) Then
  Recordset2.MoveFirst
Else
  Recordset2.Requery
End If
%>
  </select>
&nbsp;</td>
</tr>
<tr>
  <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>
</tr>
<tr>
<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>
</tr>
<tr>
<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>
&nbsp;</td>
</tr>
</table>
<p>
<input type="submit" name="Action" value="ADD">
</form>


<%
Recordset2.Close()
Set Recordset2 = Nothing
%>
<%
Recordset1.Close()
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.