Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CDO form new field

Status
Not open for further replies.

AKS44

Programmer
Feb 7, 2006
20
0
0
US
I am working on a workorder request form that uses cdonts (Win 2000 server) I am simply trying to add more fields to the form and have the results sent via the email. This form also allows for multiple file attachments. You will notice the field "Requestor" that is a field that i added, however it is not gathering information.

The Code:

<%
option explicit

'Get temporary folder
Dim ResultHTML

'Create upload form
Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")

'Set timeout to 30 minutes
Server.ScriptTimeout = 1800
'Set an upload limit to 1.8GB
Form.SizeLimit = 1800*&H100000

'Progress bar window will receive the same ID.
Form.UploadID = Request.QueryString("UploadID")'{/b}

Const fsCompletted = 0

If Form.State = fsCompletted Then 'Completted
ResultHTML = ProcessForm
ElseIf Form.State > 10 then
Const fsSizeLimit = &HD
Select case Form.State
case fsSizeLimit: ResultHTML = "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
case else ResultHTML = "<br><Font Color=red>Some form error.</Font><br>"
end Select
End If
if request.QueryString("Action") = "Cancel" then
ResultHTML = "<br><b>Upload was cancelled</b>"
end if

Function TempFolder()
Dim FS
Set FS = CreateObject("Scripting.FileSystemObject")
'Get temporary folder
TempFolder = FS.GetSpecialFolder(2) & "\emailtemp"
End Function

Sub DeleteFile(FileName)
Dim FS
Set FS = CreateObject("Scripting.FileSystemObject")
FS.DeleteFile FileName
End Sub

Function ProcessForm
Dim eTo, eFrom, Subject, Message

'get source form fields - From, To, Subject, Message
eFrom = Form("From")
Subject = Form("Subject")
Message = Form("Message")

Dim HTML
HTML = "<br><Font Color=red>Thank you, Your request has been processed. "
HTML = HTML & "<br>From: <b>" & eFrom & "</b>"
HTML = HTML & "<br>Subject: <b>" & Subject & "</b>"
HTML = HTML & "<br>Message: <b>" & Message & "</b>"

Dim File, FileName, FileNames

'Create a new email message
'Save source files to temporary folder
HTML = HTML & "<br>Attachments:"
For Each File In Form.Files

'If source file is specified.
If Len(File.FileName) > 0 Then
HTML = HTML & "<br>&nbsp;" & File.Name & ": <b>" & File.FileName & ", " & File.Length \ 1024 & "kB</b>"
FileName = TempFolder & "\" & File.FileName

File.SaveAs FileName

FileNames = FileNames & "," & FileName
End If
Next
FileNames = mid(FileNames,2)

SendMailCDO eTo, Subject, Message, FileNames, eFrom

'delete temporary files
For Each File In Form.Files
If Len(File.FileName) > 0 Then
FileName = TempFolder & "\" & File.FileName
on error resume next
DeleteFile FileName
End If
Next
HTML = HTML & "</Font><br>"
ProcessForm = HTML
End Function

'This function sends an email message from a local computer, using CDONTS.NewMail or CDO.Message, through IIS SMTP service

Sub SendMailCDO(aTo, Subject, TextBody, byval FileNames, aFrom)
if not isarray(FileNames) then FileNames = split(FileNames, ",")

Const cdoOutlookExvbsss = 2
Const cdoIIS = 1
Const CdoMailFormatMime = 0
Const cdoSendUsingPort = 2

Dim Message, CDONTS, varRequestor

varRequestor = Form("Requestor")

on error resume next

'Create a new email message
Set Message = Server.CreateObject("CDONTS.NewMail")

if err = 0 then 'there is CDONTS.NewMail object.
CDONTS = True

Message.MailFormat = CdoMailFormatMime

else 'use CDO.Message instead
CDONTS = False

'Create CDO message object
Set Message = Server.CreateObject("CDO.Message")


'Load IIS configuration
'Message.Configuration.Load cdoIIS
'Set configuration fields.
With Message.Configuration.Fields
'Original sender email address
.Item(" = aFrom

'SMTP settings - without authentication, using standard port 25 on host smtp
.Item(" = cdoSendUsingPort
.Item(" = 25
.Item(" = "localhost"

'SMTP Authentication
.Item(" = cdoAnonymous

.Update
End With
end if
on error goto 0

With Message
'Set from, to and subject
.From = aFrom
.To = aTo
.Subject = Subject

'Add attachments
Dim File
For Each File In FileNames
if CDONTS then
.AttachFile File
else
.AddAttachment File
end if
Next

'Set body of the message
if CDONTS then
.Body = "Message: " & TextBody & VBCrLf & "Requestor: " & varRequestor & VBCrLf
end if

.Send
End With
End Sub

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<TITLE>PCLS - Communications Request Form</TITLE>

<meta name="robots" content="noindex,nofollow">
<link href="../../css/pcls_new.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style2 {font-size: 75%}
-->
</style>
</HEAD>
<BODY>

<TABLE cellSpacing="1" cellPadding="0" width="750" align="center" background="/images/body_bg.gif">
<!--DWLayoutTable-->

<TR>
<TD width="392" height="387">&nbsp;</TD>
<TD width="349" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->

<tr>
<TD width="350" height="387" valign="top">
<p><%=ResultHTML%></p> <table width="350" border="0" cellpadding="0" cellspacing="0" bgcolor="#F0DD73">

<form name="file_upload" method="POST" ENCTYPE="multipart/form-data">

<tr>
<td width="11" height="31" valign="top" bgcolor="#FFCC00"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td colspan="4" bgcolor="#FFCC00"><span style="font-size: 14px; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold;">Web </span></td>
</tr>
<tr>
<td height="2"></td>
<td width="126"></td>
<td width="4"></td>
<td width="307"></td>
<td width="14"></td>
</tr>
<tr>
<td height="22">&nbsp;</td>
<td class="overview1"> E-Mail : </td>
<td>&nbsp;</td>
<td colspan="2" valign="top"><input Name=From Size=30 value="<%=Form("From")%>"></td>
</tr>
<tr>
<td height="2"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="22">&nbsp;</td>
<td class="overview1"> Requestor : </td>
<td>&nbsp;</td>
<td colspan="2" valign="top"><input Name=From Size=30 value="<%=Form("Requestor")%>"></td>
</tr>
<tr>
<td height="2"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="22">&nbsp;</td>
<td class="overview1"> Subject : </td>
<td></td>
<td colspan="2" valign="top"><input Name=Subject Size=30 value="<%=Form("Subject")%>"></td>
</tr>
<tr>
<td height="2"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="137"></td>
<td ColSpan=4 valign="top" class="overview1"> Message: <br>
<TEXTAREA name=Message rows=6 cols=35><%=Form("Message")%></TEXTAREA> </td>
</tr>
<tr>
<td height="2"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="67"></td>
<td ColSpan=4 valign="top"><span class="tagline style2">File attachments:
Form size limit is <%=Form.SizeLimit%>B (<%=Form.SizeLimit \ 1024 %>kB).<br>
</span>
<DIV class="overview1" ID=files>
Attachment 1 : <input type="file" name="File 1">
</DIV> <INPUT Type=button Value="Add a file" OnClick=return(Expand())
Style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: yellow; BORDER-LEFT: 0px; CURSOR: hand; BORDER-BOTTOM: 0px"> </td>
</tr>
<tr>
<td height="9"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="30">&nbsp;</td>
<td ColSpan=3 Align=right>
<div align="right">
<input Name=SubmitButton Value="Submit Request &gt;&gt;" Type=submit>
</div></td>
<td>&nbsp;</td></form>
</table></TD>
</tr>
</table></TD>
</TR>
<TR>
<TD height="8"></TD>
<TD></TD>
</TR>
</TABLE>

<SCRIPT>
//Script to add an attachment file field
var nfiles = 1;
function Expand(){
nfiles++
var adh = '<BR> Attachment '+nfiles+' : <input type="file" name="File '+nfiles+'">';
files.insertAdjacentHTML('BeforeEnd',adh);
return false;
};

</SCRIPT>
 
I spotted the following HTML error:

<input [highlight]Name=From[/highlight] Size=30 value="<%=Form("Requestor")%>">

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top