deadfishtower
04-15-2007, 10:59 PM
Hi there,
I have two forms im my script, one that submits the form elements into an email and one that uploads a document and sends it as an attachment.
My problem occurs when i enter details then try to upload a document, after i hit "Upload" all the details i entered into the form disappear. Basically, i want to know how to retain the form values after i have uploaded a document?
Here is my script:-
<%
dim arrErrors, a, c
redim arrErrors(0)
dim strErrorTableHTML
c = Request.QueryString("c")
'Create our own emForm dictionary
dim emForm
set emForm = emHTMLFormInitialise()
dim strCVGUID,strFileExt,strFileName,strPath,strUnique, strCVuploaded
'process attachement form if c = a
dim strField, strName, strEmail, strAddress, strPhone, strCover, strBrochure
if c = "a" then
'munge date and time to give a unique name for uploaded file
strUnique = replace(replace(replace(now()," ",""),"/",""),":","")
if emForm("dwCV").isEmpty then emValidateAddError "", "", "Please select a CV to upload", arrErrors
if UBound(arrErrors) = 0 then
' save file
strCVGUID = strUnique
strFileExt = Mid(emForm("dwCV").UserFilename, InstrRev(emForm("dwCV").UserFilename, ".")+1)
strFileName= "CV-" & strCVGUID & "." & strFileExt
strPath = Server.MapPath("../CVs/" & strFileName)
emForm("dwCV").SaveAs strPath
'useing sessions if client refreshes page still knows that they have uploaded a CV etc.
Session("strCVuploaded") = strPath
Session("strCVName") = strFileName
else
' draw error string
strErrorTableHTML = "<u>An Error Occured:</u><br/>"
for x = 1 to ubound(arrErrors)
strErrorTableHTML = strErrorTableHTML & " - " & arrErrors(x) & "<br/>"
next
strErrorTableHTML = strErrorTableHTML & "<br />"
'if error then clear all sessions to do with attachements
Session("strCVuploaded") = ""
Session("strCVName") = ""
end if
end if
a = Request.QueryString("a")
'dim strField, strName, strEmail, strAddress, strPhone, strCover, strBrochure
if a = "y" then
strField=Request.Form("strField")
strName=Request.Form("strName")
strEmail=Request.Form("strEmail")
strAddress=Request.Form("strAddress")
strPhone=Request.Form("strPhone")
strCover=Request.Form("strCover")
strBrochure=Request.Form("strBrochure")
' validation in here
if strName = "" then emValidateAddError "", "", "Please enter your name", arrErrors
if Len(strEmail) then
call emValidateEmail(strEmail, "Your email address is not valid", arrErrors)
end if
if strField = "-- Please Select --" then
emValidateAddError "", "", "Please select a field of interest", arrErrors
end if
if ubound(arrErrors) then
strErrorTableHTML = "<u>Please complete these fields:</u><br/>"
dim x
for x = 1 to ubound(arrErrors)
strErrorTableHTML = strErrorTableHTML & " - " & arrErrors(x) & "<br/>"
next
strErrorTableHTML = strErrorTableHTML
else
Dim strTo
Dim strToCC
Dim strFrom
Dim strSubject
Dim strBody
Dim strAdminEmail
'strAdminEmail = ""
strAdminEmail = "ben@emedia.co.nz"
' send email to admin *******
strTo = strAdminEmail
strToCC = ""
if len(strEmail) then
strFrom = strEmail
else
strFrom = strAdminEmail
end if
'email to admin
'REMOVED CODE
'split attachment path and name into arrays as send mail function expects arrays
dim arrAttPath, arrAttName
arrAttPath = split(Session("strCVuploaded"),",")
arrAttName = split(Session("strCVName"),",")
emMailSendMultipartWithOptions strFrom, strTo, strToCC, strSubject, strBody, "", "", arrAttPath, arrAttName, emMailOptionContentHTML
'delete uploaded file
dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(Session("strCVuploaded")) Then
filesys.DeleteFile Session("strCVuploaded")
End If
' email to submitter
'REMOVED CODE
' send email to sender
'REMOVED CODE
end if
' set all cv stuff to nothing
Session("strCVuploaded") = ""
Session("strCVName") = ""
' redirect to thankyou page
Response.Redirect "casualform1.asp?a=t"
end if
end if
%>
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="../css/odhb.css">
<script>
function testcv(){
if(document.getElementById('File1') != null){
if(document.getElementById('File1').value == ""){
return true;
}else {
alert("Please upload your CV by clicking the 'RED' Upload CV button!");
return false;
}
}
}
</script>
</HEAD>
<body style="background-color:#ffffff; margin:0px; padding:0px;">
<table border="0" cellpadding="0" cellspacing="0" align="left" ID="Table1">
<tr>
<td>
<%if not a = "t" then%>
<!--form structure here ****************************-->
<!--************************************************-->
<table border="0" cellpadding="0" cellspacing="0" align="center" width="500" ID="Table2">
<!-- errors -->
<%
if len(strErrorTableHTML) > 0 then
response.Write "<tr><td colspan=""2"" class=""errors"">" & strErrorTableHTML & "</td></tr>"
end if
%>
<!-- form starts -->
<form action="casualform1.asp?a=y" method="post" ID="Form1" name="Form1" onSubmit="return testcv()">
<tr>
<td colspan="2"><hr class="dashed"></td>
</tr>
<tr>
<td>
<font class="titles">Field of Interest:</font><br/>
<select name="strField" class="field">
<option>-- Please Select --</option>
<%'while NOT contentRS.EOF
'response.write "<option value=""" & contentRS("varcharvalue") & """"
'if contentRS("varcharvalue") = strField then
'response.write " selected"
'end if
'response.write ">" & contentRS("varcharvalue") & "</option>"
'contentRS.MoveNext
'wend%>
</select>
</td>
</tr>
<tr>
<td>
<font class="titles">Name:</font><br/>
<input type="text" name="strName" value="<%= strName%>" class="txtField" ID="Text1" onFocus="testcv()" />
</td>
</tr>
<tr>
<td>
<font class="titles">Email:</font><br/>
<input type="text" name="strEmail" value="<%= strEmail%>" class="txtField" ID="Text3" onFocus="testcv()"/>
</td>
</tr>
<tr>
<td>
<font class="titles">Contact Phone:</font><br/>
<input type="text" name="strPhone" value="<%= strPhone%>" class="txtField" ID="Text2" onFocus="testcv()" />
</td>
</tr>
<tr>
<td>
<font class="titles">Address:</font><br/>
<textarea rows="5" cols="50" class="txtField" name="strAddress" ID="Textarea1" onFocus="testcv()"><%=strAddress%></textarea>
</td>
</tr>
<tr>
<td>
<font class="titles">Comments:</font><br/>
<textarea rows="5" cols="50" class="txtField" name="strCover" ID="Textarea2" onFocus="testcv()"><%=strCover%></textarea>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="strBrochure" value="yes" <%if len(strBrochure) then response.write " checked"%> />
<font class="titles">Please send me a "Living in Dunedin" brochure</font>
</td>
</tr>
</form>
<!-- 12-04-07, BMA, moved CV code down to here. Closed the first form off (Form2) and added an onClick javascript function to Submit button. -->
<tr>
<td colspan="2"><hr class="dashed"></td>
</tr>
<tr class="header">
<td colspan="2" align="center"><b>Upload Your CV</b></td>
</tr>
<tr>
<td colspan="2"><hr class="dashed"></td>
</tr>
<% if Session("strCVuploaded") = "" Then %>
<tr class="cellbg">
<td colspan="2">
<form enctype="multipart/form-data" action="casualform1.asp?c=a" method="post" id="Form2" name="Form2">
<table border="0" cellpadding="0" cellspacing="0" width="100%" ID="Table3">
<tr>
<td colspan="2"><div style="color:red; padding:5px;">
If you would like to send us a copy of your CV please upload it now it will be attached with the email sent.</div>
</td>
</tr>
<tr>
<td style="padding:5px;"><b>CV</b></td>
<td style="padding:5px;">
<input type="file" name="dwCV" ID="File1" size="40" class="txtField">
<input class="CVbutton" type="submit" name="Submit1" value="Upload CV" ID="Submit1">
</td>
</tr>
</table>
</form>
</td>
</tr>
<% else %>
<tr class="cellbg">
<td colspan="2"><span style="color:red;">CV Uploaded - it will be forwarded with your application when you submit the Application.</span></td>
</tr>
<% end if %>
<!-- End of CV code -->
<!-- Submit -->
<tr>
<td colspan="2"><hr class="dashed"></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Submit >>" name="submit2" class="bttn" ID="Submit2" onclick="document.Form1.submit();"></td>
</tr>
</table>
<!--************************************************-->
<!-- end of form structure *************************-->
<%else%>
<h2>Thank you for submitting your CV</h2>
<%end if%>
</td>
</tr>
</table>
</body>
</HTML>
Help would be great.
Ben
I have two forms im my script, one that submits the form elements into an email and one that uploads a document and sends it as an attachment.
My problem occurs when i enter details then try to upload a document, after i hit "Upload" all the details i entered into the form disappear. Basically, i want to know how to retain the form values after i have uploaded a document?
Here is my script:-
<%
dim arrErrors, a, c
redim arrErrors(0)
dim strErrorTableHTML
c = Request.QueryString("c")
'Create our own emForm dictionary
dim emForm
set emForm = emHTMLFormInitialise()
dim strCVGUID,strFileExt,strFileName,strPath,strUnique, strCVuploaded
'process attachement form if c = a
dim strField, strName, strEmail, strAddress, strPhone, strCover, strBrochure
if c = "a" then
'munge date and time to give a unique name for uploaded file
strUnique = replace(replace(replace(now()," ",""),"/",""),":","")
if emForm("dwCV").isEmpty then emValidateAddError "", "", "Please select a CV to upload", arrErrors
if UBound(arrErrors) = 0 then
' save file
strCVGUID = strUnique
strFileExt = Mid(emForm("dwCV").UserFilename, InstrRev(emForm("dwCV").UserFilename, ".")+1)
strFileName= "CV-" & strCVGUID & "." & strFileExt
strPath = Server.MapPath("../CVs/" & strFileName)
emForm("dwCV").SaveAs strPath
'useing sessions if client refreshes page still knows that they have uploaded a CV etc.
Session("strCVuploaded") = strPath
Session("strCVName") = strFileName
else
' draw error string
strErrorTableHTML = "<u>An Error Occured:</u><br/>"
for x = 1 to ubound(arrErrors)
strErrorTableHTML = strErrorTableHTML & " - " & arrErrors(x) & "<br/>"
next
strErrorTableHTML = strErrorTableHTML & "<br />"
'if error then clear all sessions to do with attachements
Session("strCVuploaded") = ""
Session("strCVName") = ""
end if
end if
a = Request.QueryString("a")
'dim strField, strName, strEmail, strAddress, strPhone, strCover, strBrochure
if a = "y" then
strField=Request.Form("strField")
strName=Request.Form("strName")
strEmail=Request.Form("strEmail")
strAddress=Request.Form("strAddress")
strPhone=Request.Form("strPhone")
strCover=Request.Form("strCover")
strBrochure=Request.Form("strBrochure")
' validation in here
if strName = "" then emValidateAddError "", "", "Please enter your name", arrErrors
if Len(strEmail) then
call emValidateEmail(strEmail, "Your email address is not valid", arrErrors)
end if
if strField = "-- Please Select --" then
emValidateAddError "", "", "Please select a field of interest", arrErrors
end if
if ubound(arrErrors) then
strErrorTableHTML = "<u>Please complete these fields:</u><br/>"
dim x
for x = 1 to ubound(arrErrors)
strErrorTableHTML = strErrorTableHTML & " - " & arrErrors(x) & "<br/>"
next
strErrorTableHTML = strErrorTableHTML
else
Dim strTo
Dim strToCC
Dim strFrom
Dim strSubject
Dim strBody
Dim strAdminEmail
'strAdminEmail = ""
strAdminEmail = "ben@emedia.co.nz"
' send email to admin *******
strTo = strAdminEmail
strToCC = ""
if len(strEmail) then
strFrom = strEmail
else
strFrom = strAdminEmail
end if
'email to admin
'REMOVED CODE
'split attachment path and name into arrays as send mail function expects arrays
dim arrAttPath, arrAttName
arrAttPath = split(Session("strCVuploaded"),",")
arrAttName = split(Session("strCVName"),",")
emMailSendMultipartWithOptions strFrom, strTo, strToCC, strSubject, strBody, "", "", arrAttPath, arrAttName, emMailOptionContentHTML
'delete uploaded file
dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(Session("strCVuploaded")) Then
filesys.DeleteFile Session("strCVuploaded")
End If
' email to submitter
'REMOVED CODE
' send email to sender
'REMOVED CODE
end if
' set all cv stuff to nothing
Session("strCVuploaded") = ""
Session("strCVName") = ""
' redirect to thankyou page
Response.Redirect "casualform1.asp?a=t"
end if
end if
%>
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="../css/odhb.css">
<script>
function testcv(){
if(document.getElementById('File1') != null){
if(document.getElementById('File1').value == ""){
return true;
}else {
alert("Please upload your CV by clicking the 'RED' Upload CV button!");
return false;
}
}
}
</script>
</HEAD>
<body style="background-color:#ffffff; margin:0px; padding:0px;">
<table border="0" cellpadding="0" cellspacing="0" align="left" ID="Table1">
<tr>
<td>
<%if not a = "t" then%>
<!--form structure here ****************************-->
<!--************************************************-->
<table border="0" cellpadding="0" cellspacing="0" align="center" width="500" ID="Table2">
<!-- errors -->
<%
if len(strErrorTableHTML) > 0 then
response.Write "<tr><td colspan=""2"" class=""errors"">" & strErrorTableHTML & "</td></tr>"
end if
%>
<!-- form starts -->
<form action="casualform1.asp?a=y" method="post" ID="Form1" name="Form1" onSubmit="return testcv()">
<tr>
<td colspan="2"><hr class="dashed"></td>
</tr>
<tr>
<td>
<font class="titles">Field of Interest:</font><br/>
<select name="strField" class="field">
<option>-- Please Select --</option>
<%'while NOT contentRS.EOF
'response.write "<option value=""" & contentRS("varcharvalue") & """"
'if contentRS("varcharvalue") = strField then
'response.write " selected"
'end if
'response.write ">" & contentRS("varcharvalue") & "</option>"
'contentRS.MoveNext
'wend%>
</select>
</td>
</tr>
<tr>
<td>
<font class="titles">Name:</font><br/>
<input type="text" name="strName" value="<%= strName%>" class="txtField" ID="Text1" onFocus="testcv()" />
</td>
</tr>
<tr>
<td>
<font class="titles">Email:</font><br/>
<input type="text" name="strEmail" value="<%= strEmail%>" class="txtField" ID="Text3" onFocus="testcv()"/>
</td>
</tr>
<tr>
<td>
<font class="titles">Contact Phone:</font><br/>
<input type="text" name="strPhone" value="<%= strPhone%>" class="txtField" ID="Text2" onFocus="testcv()" />
</td>
</tr>
<tr>
<td>
<font class="titles">Address:</font><br/>
<textarea rows="5" cols="50" class="txtField" name="strAddress" ID="Textarea1" onFocus="testcv()"><%=strAddress%></textarea>
</td>
</tr>
<tr>
<td>
<font class="titles">Comments:</font><br/>
<textarea rows="5" cols="50" class="txtField" name="strCover" ID="Textarea2" onFocus="testcv()"><%=strCover%></textarea>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="strBrochure" value="yes" <%if len(strBrochure) then response.write " checked"%> />
<font class="titles">Please send me a "Living in Dunedin" brochure</font>
</td>
</tr>
</form>
<!-- 12-04-07, BMA, moved CV code down to here. Closed the first form off (Form2) and added an onClick javascript function to Submit button. -->
<tr>
<td colspan="2"><hr class="dashed"></td>
</tr>
<tr class="header">
<td colspan="2" align="center"><b>Upload Your CV</b></td>
</tr>
<tr>
<td colspan="2"><hr class="dashed"></td>
</tr>
<% if Session("strCVuploaded") = "" Then %>
<tr class="cellbg">
<td colspan="2">
<form enctype="multipart/form-data" action="casualform1.asp?c=a" method="post" id="Form2" name="Form2">
<table border="0" cellpadding="0" cellspacing="0" width="100%" ID="Table3">
<tr>
<td colspan="2"><div style="color:red; padding:5px;">
If you would like to send us a copy of your CV please upload it now it will be attached with the email sent.</div>
</td>
</tr>
<tr>
<td style="padding:5px;"><b>CV</b></td>
<td style="padding:5px;">
<input type="file" name="dwCV" ID="File1" size="40" class="txtField">
<input class="CVbutton" type="submit" name="Submit1" value="Upload CV" ID="Submit1">
</td>
</tr>
</table>
</form>
</td>
</tr>
<% else %>
<tr class="cellbg">
<td colspan="2"><span style="color:red;">CV Uploaded - it will be forwarded with your application when you submit the Application.</span></td>
</tr>
<% end if %>
<!-- End of CV code -->
<!-- Submit -->
<tr>
<td colspan="2"><hr class="dashed"></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Submit >>" name="submit2" class="bttn" ID="Submit2" onclick="document.Form1.submit();"></td>
</tr>
</table>
<!--************************************************-->
<!-- end of form structure *************************-->
<%else%>
<h2>Thank you for submitting your CV</h2>
<%end if%>
</td>
</tr>
</table>
</body>
</HTML>
Help would be great.
Ben