DanClark86
MIS
I have several issues going here and i can't seem to figure out why it is happending. here is the code for the first page (problem.asp)
The Second File involved is called fpdbform.inc
[code}
<%
Function FP_SaveFormFields(rs, rgFormFields, rgDBFields)
On Error Resume Next
Err.Clear
Dim i
For i = 0 To UBound(rgFormFields)
FP_SaveFormField rs, rgFormFields(i), rgDBFields(i)
Next
Err.Clear
End Function
Function FP_SaveFormField(rs, strField, strDBField)
On Error Resume Next
Err.Clear
If (Request.Form(strField)) = "" And rs(strDBField).Type <> adBoolean Then
Exit Function
End If
FP_SaveFieldToDB rs, Request.Form(strField), strDBField
Err.Clear
End Function
Function FP_SaveFieldToDB(rs, strField, strDBField)
On Error Resume Next
Err.Clear
Select Case rs(strDBField).Type
Case adInteger Or adBigInt Or adUnsignedTinyInt Or adUnsignedSmallInt Or adUnsignedInt Or adUnsignedBigInt
rs(strDBField) = CInt(strField)
Case adSingle Or adDecimal Or adNumeric
rs(strDBField) = CSng(strField)
Case adDouble
rs(strDBField) = CDbl(strField)
Case adCurrency
rs(strDBField) = CCur(strField)
Case adBoolean
rs(strDBField) = CBool(strField)
Case adDate Or adDBDate Or adDBTime or adDBTimeStamp
rs(strDBField) = CDate(strField)
Case Else
rs(strDBField) = CStr(strField)
End Select
strError = "Cannot save value """ & strField & """ to database field """ & strDBField & """"
FP_DumpError strErrorUrl, strError
Err.Clear
End Function
Function FP_FormConfirmation(szCharset, szTitle, szmsg1, szUrl, szMsg2)
Response.Write "<html>" & vbCrLf
Response.Write "<head>" & vbCrLf
Response.Write "<meta http-equiv=""Content-Type"" content=" & szCharSet & ">" & vbCrLf
Response.Write "<title> " & szTitle & "</title>" & vbCrLf
Response.Write "</head>" & vbCrLf
Response.Write "<body>" & vbCrLf
Response.Write "<h1> " & szTitle & "</h1>" & vbCrLf
Response.Write "<p> " & szMsg1 &"</p>" & vbCrLf
Response.Write "<p>" & vbCrLf
For Each item in Request.Form
If item <> "VTI-GROUP" Then
Response.Write "<b>" & item & "</b>" & ": " & Server.HTMLEncode(Request.Form(item)) & "<BR>" & vbCrLf
End If
Next
Response.Write "</p>" & vbCrLf
Response.Write "<p> <a href=""" & szUrl & """>" & szMsg2 & "</a></p>" & vbCrLf
Response.Write "</body>" & vbCrLf
Response.Write "</html>" & vbCrLf
Response.End
End Function
Function FP_DumpError(strErrorUrl, strMsg)
If Err.Number <> 0 Then
fp_conn.Close
If strErrorUrl <> "" Then
Response.Redirect strErrorUrl
Else
Response.Write "<b> " & strMsg & "</b><p>"
Response.Write "Error Description: " & Err.Description & "<p>"
Response.Write "Error Number: " & Err.Number & "<p>"
Response.Write "Error Source: " & Err.Source & "<p>"
Response.End
End If
End if
End Function
%>
[/code]
And the results look like this:
Everything works in this with the exception of the E-mail when you click submit and i want it to return the ID of the Database entry. Any help or guidence would be great
Code:
<%
' FP_ASP ASP Automatically generated by a Frontpage Component. Do not Edit.
On Error Resume Next
Dim strTo, strFrom, strSubject, strBody 'Strings for recipient, Sender, subject, boby
Dim objCDOMail 'The CDO object
strErrorUrl = ""
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
If Request.Form("VTI-GROUP") = "0" Then
Err.Clear
Set fp_conn = Server.CreateObject("ADODB.Connection")
FP_DumpError strErrorUrl, "Cannot create connection"
Set fp_rs = Server.CreateObject("ADODB.Recordset")
FP_DumpError strErrorUrl, "Cannot create record set"
fp_conn.Open Application("H1_ConnectionString")
FP_DumpError strErrorUrl, "Cannot open database"
fp_rs.Open "Tickets", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable
FP_DumpError strErrorUrl, "Cannot open record set"
fp_rs.AddNew
FP_DumpError strErrorUrl, "Cannot add new record set to the database"
Dim arFormFields0(10)
Dim arFormDBFields0(10)
Dim arFormValues0(10)
arFormFields0(0) = "Prob"
arFormDBFields0(0) = "Prob"
arFormValues0(0) = Request("Prob")
arFormFields0(1) = "Last"
arFormDBFields0(1) = "Last"
arFormValues0(1) = Request("Last")
arFormFields0(2) = "tech"
arFormDBFields0(2) = "Tech"
arFormValues0(2) = Request("tech")
arFormFields0(3) = "USER"
arFormDBFields0(3) = "USER"
arFormValues0(3) = Request("USER")
arFormFields0(4) = "First"
arFormDBFields0(4) = "First"
arFormValues0(4) = Request("First")
arFormFields0(5) = "Ext"
arFormDBFields0(5) = "Ext"
arFormValues0(5) = Request("Ext")
arFormFields0(6) = "Operator"
arFormDBFields0(6) = "Entered"
arFormValues0(6) = Request("Operator")
arFormFields0(6) = "Operator"
arFormDBFields0(6) = "Entered"
arFormValues0(6) = Request("Operator")
arFormFields0(7) = "ID"
arFormDBFields0(7) = "ID"
arFormValues0(7) = Request("ID")
FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0
FP_SaveFieldToDB fp_rs, Now, "Timestamp"
fp_rs.Update
FP_DumpError strErrorUrl, "Cannot update the database"
iRecordAdded = objRecordset.Fields("ID").Value
Response.Write "<p>Record id " & iRecordAdded & " added!</p>" & vbCrLf
fp_rs.Close
fp_conn.Close
FP_FormConfirmation "text/html; charset=windows-1252",_
"Form Confirmation",_
"Thank you for submitting the following information:",_
"Problem.asp",_
"Return to the form."
End If
End If
%>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Problem Information Form</title>
</head>
<body>
<h2 align="center">Problem Information Form</h2>
<!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script Language="JavaScript"><!--
function FrontPage_Form1_Validator(theForm)
{
if (theForm.First.value == "")
{
alert("Please enter a value for the \"First\" field.");
theForm.First.focus();
return (false);
}
if (theForm.First.value.length < 3)
{
alert("Please enter at least 3 characters in the \"First\" field.");
theForm.First.focus();
return (false);
}
if (theForm.First.value.length > 10)
{
alert("Please enter at most 10 characters in the \"First\" field.");
theForm.First.focus();
return (false);
}
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
var checkStr = theForm.First.value;
var allValid = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert("Please enter only letter characters in the \"First\" field.");
theForm.First.focus();
return (false);
}
if (theForm.Last.value == "")
{
alert("Please enter a value for the \"Last\" field.");
theForm.Last.focus();
return (false);
}
if (theForm.Last.value.length < 3)
{
alert("Please enter at least 3 characters in the \"Last\" field.");
theForm.Last.focus();
return (false);
}
if (theForm.Last.value.length > 15)
{
alert("Please enter at most 15 characters in the \"Last\" field.");
theForm.Last.focus();
return (false);
}
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
var checkStr = theForm.Last.value;
var allValid = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert("Please enter only letter characters in the \"Last\" field.");
theForm.Last.focus();
return (false);
}
if (theForm.USER.value == "")
{
alert("Please enter a value for the \"Init\" field.");
theForm.USER.focus();
return (false);
}
if (theForm.USER.value.length < 2)
{
alert("Please enter at least 2 characters in the \"Init\" field.");
theForm.USER.focus();
return (false);
}
if (theForm.USER.value.length > 8)
{
alert("Please enter at most 8 characters in the \"Init\" field.");
theForm.USER.focus();
return (false);
}
if (theForm.Ext.value == "")
{
alert("Please enter a value for the \"Ext\" field.");
theForm.Ext.focus();
return (false);
}
if (theForm.Ext.value.length < 4)
{
alert("Please enter at least 4 characters in the \"Ext\" field.");
theForm.Ext.focus();
return (false);
}
if (theForm.Ext.value.length > 4)
{
alert("Please enter at most 4 characters in the \"Ext\" field.");
theForm.Ext.focus();
return (false);
}
var checkOK = "0123456789-";
var checkStr = theForm.Ext.value;
var allValid = true;
var decPoints = 0;
var allNum = "";
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
allNum += ch;
}
if (!allValid)
{
alert("Please enter only digit characters in the \"Ext\" field.");
theForm.Ext.focus();
return (false);
}
if (theForm.Prob.value == "")
{
alert("Please enter a value for the \"Prob\" field.");
theForm.Prob.focus();
return (false);
}
if (theForm.Prob.value.length > 50)
{
alert("Please enter at most 50 characters in the \"Prob\" field.");
theForm.Prob.focus();
return (false);
}
return (true);
}
//--></script><!--webbot BOT="GeneratedScript" endspan --><form method="POST" action="./Problem.asp" onsubmit="return FrontPage_Form1_Validator(this)" name="FrontPage_Form1" webbot-action="--WEBBOT-SELF--">
<!--webbot bot="SaveDatabase" startspan SuggestedExt="asp"
U-ASP-Include-Url="../_fpclass/fpdbform.inc" S-DataConnection="H1"
S-RecordSource="Tickets" U-Database-URL="../fpdb/helpdesk.mdb"
S-Builtin-Fields="Timestamp" S-Builtin-DBFields="Timestamp"
S-Form-Fields="Prob Last tech USER First Ext Operator
S-Form-DBFields="Prob Last Tech USER First Ext Entered " --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--#include file="../_fpclass/fpdbform.inc"--><!--webbot
bot="SaveDatabase" endspan i-checksum="34604" -->
<p>First Name: <!--webbot bot="Validation"
S-Display-Name="First" S-Data-Type="String" B-Allow-Letters="TRUE"
B-Value-Required="TRUE" I-Minimum-Length="3" I-Maximum-Length="10" --><input type="text" name="First" value="Daniel"><br>
Last Name: <!--webbot bot="Validation" S-Display-Name="Last"
S-Data-Type="String" B-Allow-Letters="TRUE" B-Value-Required="TRUE"
I-Minimum-Length="3" I-Maximum-Length="15" --><input type="text" name="Last" value="Clark"><br>
User Initials: <!--webbot bot="Validation" S-Display-Name="Init"
S-Data-Type="String" B-Value-Required="TRUE" I-Minimum-Length="2"
I-Maximum-Length="8" --><input type="text" name="USER" value="DTC"><br>
Extension: <!--webbot bot="Validation"
S-Display-Name="Ext" S-Data-Type="Integer" S-Number-Separators="x"
B-Value-Required="TRUE" I-Minimum-Length="4" I-Maximum-Length="4" --><input type="text" name="Ext" value="7818"><BR>
Problem: <!--webbot
bot="Validation" S-Display-Name="Prob" S-Data-Type="String"
B-Value-Required="TRUE" I-Maximum-Length="50" -->
<input type="text" name="Prob" value="This is a test">
</p>
<p>
<input type="hidden" name="Operator" value="<%=Request.Cookies("theCookie")%>">
<input type="hidden" name="tech" value="Dispatch">
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
<%=RS("First")%>
</form>
<p> </p>
</body>
</html>
<%
strBody = "You have new tickets from "=Request.Cookies("theCookie")
If strTo = "" Or Not IsvalidEmail(strTo) Then
else
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")'
objCDOMail.From = "Junkmail@mycompan.com"
objCDOMail.to = "Junkmail@mycompan.com"
objCDOMail.Subject = "You have Helpdesk Tickets Pending"
objCDOMail.body = strBody
objCDOMail.Send
Set objCDOMail = Nothing
Set strTo = Nothing
Set strSubject = Nothing
Set strBody = Nothing
End If
%>
<%
Function IsValidEmail(strEmail)
Dim bIsValid
bIsValid = True
If Len(strEmail) < 5 Then
bIsValid = False
Else
If Instr(1, strEmail, " ") <> 0 Then
bIsValid = False
Else
If InStr(1, strEmail, "@", 1) < 2 Then
bIsValid = False
Else
If InStrRev(strEmail, ".") < InStr(1, strEmail, "@", 1) + 2 Then
bIsValid = False
End If
End If
End If
End If
IsValidEmail = bIsValid
End Function
%>
The Second File involved is called fpdbform.inc
[code}
<%
Function FP_SaveFormFields(rs, rgFormFields, rgDBFields)
On Error Resume Next
Err.Clear
Dim i
For i = 0 To UBound(rgFormFields)
FP_SaveFormField rs, rgFormFields(i), rgDBFields(i)
Next
Err.Clear
End Function
Function FP_SaveFormField(rs, strField, strDBField)
On Error Resume Next
Err.Clear
If (Request.Form(strField)) = "" And rs(strDBField).Type <> adBoolean Then
Exit Function
End If
FP_SaveFieldToDB rs, Request.Form(strField), strDBField
Err.Clear
End Function
Function FP_SaveFieldToDB(rs, strField, strDBField)
On Error Resume Next
Err.Clear
Select Case rs(strDBField).Type
Case adInteger Or adBigInt Or adUnsignedTinyInt Or adUnsignedSmallInt Or adUnsignedInt Or adUnsignedBigInt
rs(strDBField) = CInt(strField)
Case adSingle Or adDecimal Or adNumeric
rs(strDBField) = CSng(strField)
Case adDouble
rs(strDBField) = CDbl(strField)
Case adCurrency
rs(strDBField) = CCur(strField)
Case adBoolean
rs(strDBField) = CBool(strField)
Case adDate Or adDBDate Or adDBTime or adDBTimeStamp
rs(strDBField) = CDate(strField)
Case Else
rs(strDBField) = CStr(strField)
End Select
strError = "Cannot save value """ & strField & """ to database field """ & strDBField & """"
FP_DumpError strErrorUrl, strError
Err.Clear
End Function
Function FP_FormConfirmation(szCharset, szTitle, szmsg1, szUrl, szMsg2)
Response.Write "<html>" & vbCrLf
Response.Write "<head>" & vbCrLf
Response.Write "<meta http-equiv=""Content-Type"" content=" & szCharSet & ">" & vbCrLf
Response.Write "<title> " & szTitle & "</title>" & vbCrLf
Response.Write "</head>" & vbCrLf
Response.Write "<body>" & vbCrLf
Response.Write "<h1> " & szTitle & "</h1>" & vbCrLf
Response.Write "<p> " & szMsg1 &"</p>" & vbCrLf
Response.Write "<p>" & vbCrLf
For Each item in Request.Form
If item <> "VTI-GROUP" Then
Response.Write "<b>" & item & "</b>" & ": " & Server.HTMLEncode(Request.Form(item)) & "<BR>" & vbCrLf
End If
Next
Response.Write "</p>" & vbCrLf
Response.Write "<p> <a href=""" & szUrl & """>" & szMsg2 & "</a></p>" & vbCrLf
Response.Write "</body>" & vbCrLf
Response.Write "</html>" & vbCrLf
Response.End
End Function
Function FP_DumpError(strErrorUrl, strMsg)
If Err.Number <> 0 Then
fp_conn.Close
If strErrorUrl <> "" Then
Response.Redirect strErrorUrl
Else
Response.Write "<b> " & strMsg & "</b><p>"
Response.Write "Error Description: " & Err.Description & "<p>"
Response.Write "Error Number: " & Err.Number & "<p>"
Response.Write "Error Source: " & Err.Source & "<p>"
Response.End
End If
End if
End Function
%>
[/code]
And the results look like this:
Code:
Record id added!
Form Confirmation
Thank you for submitting the following information:
First: fname
Last: lname
USER: int
Prob: This is a test
Ext: 7818
Operator: User updated
tech: Dispatch
B1: Submit
Return to the form.