Forums
This topic is locked
MX insert form data in DB and email?
Posted 20 Mar 2009 19:33:33
1
has voted
20 Mar 2009 19:33:33 GARY BRETT posted:
Hi, hope somebody may be able to assist Ive been trying for 2 days now!!I have created a user registration form using the "record insertion form wizard" in Dreamweaver MX. This posts the form data to an SQL2005 database table which is great but I also would like it to fire an email with the data inside, is it possible to have 2 actions on submit or is there an extension I am missing to achieve this?
If not has anyone any other methods of perhaps acheiving this as I need our users to be alerted if someone has registered via this form?
Many thanx
PS - I have tried this code below after a tutorial on here but it falls over for me, my additions are in bold?
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/SERVER.asp" -->
<%
// *** Edit Operations: declare variables
// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME"
if (Request.QueryString) {
MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}
// boolean to abort record edit
var MM_abortEdit = false;
// query string to execute
var MM_editQuery = "";
%>
<%
// *** Insert Record: set variables
if (String(Request("MM_insert") == "form1" {
var MM_editConnection = MM_GHLDNS_STRING;
var MM_editTable = "dbo.tblRegistration";
var MM_editRedirectUrl = "thankyou.htm";
var MM_fieldsStr = "CR_Status|value|FirstName|value|Surname|value|CompanyName|value|Address1|value|Address2|value|Town|value|PostCode|value|JobPosition|value|FSANo|value|CCL|value|Tel|value|Fax|value|Mobile|value|Email|value|DOB|value";
var MM_columnsStr = "CR_Status|',none,''|FirstName|',none,''|Surname|',none,''|CompanyName|',none,''|Address1|',none,''|Address2|',none,''|Town|',none,''|PostCode|',none,''|JobPosition|',none,''|FSANo|',none,''|CCL|',none,''|Tel|',none,''|Fax|',none,''|Mobile|',none,''|Email|',none,''|DOB|',none,''";
// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|"
var MM_columns = MM_columnsStr.split("|"
// set the form values
for (var i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields[i]));
}
// append the query string to the redirect URL
if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&" + Request.QueryString;
}
}
%>
<%
// *** Insert Record: construct a sql insert statement and execute it
if (String(Request("MM_insert") != "undefined" {
// create the sql insert statement
var MM_tableValues = "", MM_dbValues = "";
for (var i=0; i+1 < MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(","
var delim = (MM_typesArray[0] != "none" ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none" ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none" ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined" {
formVal = emptyVal;
} else {
if (altVal != "" {
formVal = altVal;
} else if (delim == "'" { // escape quotes
formVal = "'" + formVal.replace(/'/g,"''" + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_tableValues += ((i != 0) ? "," : "" + MM_columns[i];
MM_dbValues += ((i != 0) ? "," : "" + formVal;
}
MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + " values (" + MM_dbValues + "";
if (!MM_abortEdit) {
// execute the insert
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();
mailbody = "<font size =3 face = Verdana>" & "<strong>" & Request.Form("Namefield" & " has just entered their details" & "</strong>" & "</font>" & "<br>" & "<br>"
mailbody = mailbody & "<font size =2 face = Verdana>" & "Address: " & Request.Form("Addressfield" & "<br>" & "<br>" & "Age: " & Request.Form("PersonsAge" & "</font>"
Set objCDO = Server.CreateObject("Cdonts.NewMail"
objCDO.BodyFormat =0 ' 0 is a plain text, 0 "zero" is a HTML
objCDO.MailFormat = 0 ' 1 is a plain text, 0 "zero" is mime format
objCDO.To = " " ß put your email address here
objCDO.From = " " ß- put an email address here, can be a dummy one
objCDO.Subject ="Registration on website"
objCDO.Body =mailbody
objCDO.Send
Set objCDO = Nothing
if (MM_editRedirectUrl) {
Response.Redirect(MM_editRedirectUrl);
}
}
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>GHL NETWORK SERVICES</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<!--
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 24px;
color: #333366;
font-weight: bold;
}
-->
</style>
<style type="text/css">
<!--
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 18px;
font-weight: bold;
color: #333366;
}
.style5 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
.style7 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10; }
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?")>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="" {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF">
<span class="style2">Recruitment Registration
</span>
<form action="<%=MM_editAction%>" method="post" name="form1" onSubmit="MM_validateForm('Email','','RisEmail');MM_validateForm('FirstName','','R');MM_validateForm('Surname','','R');MM_validateForm('FSANo','','R');return document.MM_returnValue">
<table align="LEFT">
<tr valign="baseline">
<td nowrap align="right"><span class="style5">CR_Status:</span></td>
<td> <span class="style7">
<select name="CR_Status">
<option value="" selected>DA</option>
<option value="" >AR of other Network</option>
</select>
</span> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">First Name:</span></td>
<td>
<input name="FirstName" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">Surname:</span></td>
<td>
<input name="Surname" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">Company :</span></td>
<td>
<input name="CompanyName" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">Address1:</span></td>
<td>
<input name="Address1" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">Address2:</span></td>
<td>
<input name="Address2" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">Town:</span></td>
<td>
<input name="Town" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">PostCode:</span></td>
<td>
<input name="PostCode" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">Job Position:</span></td>
<td>
<input name="JobPosition" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">FSA No:</span></td>
<td>
<input name="FSANo" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">CCL:</span></td>
<td>
<input name="CCL" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">Tel:</span></td>
<td>
<input name="Tel" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">Fax:</span></td>
<td>
<input name="Fax" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">Mobile:</span></td>
<td>
<input name="Mobile" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">Email:</span></td>
<td>
<input name="Email" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><span class="style5">DOB:</span></td>
<td>
<input name="DOB" type="text" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td>
<input type="submit" value="Insert record">
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>