Click to See Complete Forum and Search --> : Calling a function from with a function error?


pablooliva
09-11-2008, 06:34 PM
Very fresh to ASP, so a lot of questions. But in this case, from within Function SaveFiles I'm calling validateEmail(cc_to) and the script seems to die at that point. Can anyone offer any suggestions?

<%
option explicit
Response.Expires = -1
Server.ScriptTimeout = 600
%>
<!-- #include file="freeaspupload.asp" -->
<%

' directory with write permissions, for example "C:\Inetpub\wwwroot"
Dim uploadsDirVar
uploadsDirVar = "d:\Inetpub\uploads\"

Function validateEmail (HTMLstring)
'make sure email entered is a valid email
Set RegularExpressionObject = New RegExp
With RegularExpressionObject
.Pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
.IgnoreCase = true
.Global = True
End With
Set expressionmatch = RegularExpressionObject.Execute(HTMLstring)
If expressionmatch.Count > 0 Then
validateEmail = HTMLString
Else
validateEmail = "CityWeb-Server@cop.net"
End If
Set RegularExpressionObject = nothing
End Function

SaveFiles()

function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey

Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)

' If something fails inside the script, but the exception is handled
If Err.Number<>0 then Exit function

ks = Upload.UploadedFiles.keys
if (UBound(ks) <> -1) then
SaveFiles = "<B>Files uploaded:</B> "
for each fileKey in Upload.UploadedFiles.keys
SaveFiles = SaveFiles & "<a href='" & "http://www/uploads/" & Upload.UploadedFiles(fileKey).FileName & "'>" & Upload.UploadedFiles(fileKey).FileName & "</a>" & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
next
else
SaveFiles = "The file name specified in the upload form does not correspond to a valid file in the system."
end if

' *** send email code *** '

'***** edit values here to filter emails ****'
Dim bad_words, hyperlink_occurances, email_address, cc_to, thanks, email_subject, default_thanks_page, default_error_page, cc, phoneNumber
bad_words = "viagra,rulez005,cialis,<street>"
hyperlink_occurances = 2
'***** end of editable values ****'

email_address = ""
cc_to = ""
thanks = ""
email_subject = ""
default_thanks_page = "email_thanks.asp"
default_error_page = "email_error.asp"
cc = false
phoneNumber = ""

cc_to = trim(Upload.Form("cc_to")) & "@cop.net"

response.write "this is validated " & validateEmail(cc_to)
response.end

' if validateEmail(cc_to) <> "CityWeb-Server@cop.net" then cc = true

email_address = trim(Upload.Form("send_to"))
email_address = email_address & "@cop.net"

if validateEmail(email_address) = "CityWeb-Server@cop.net" then email_address = "webmaster@cop.net"

strResponse = trim(Upload.Form("form_thanks"))

if strResponse = "" then strResponse = default_thanks_page
if not(check_file_exists(strResponse)) then strResponse = default_thanks_page

email_subject = trim(Upload.Form("form_subject"))
if email_subject = "" then email_subject = "Web Comment"

goodMsg = false
strMsgBody = ""

for x = 1 to Upload.Form.count()
field_lower_case = Lcase(Upload.Form.key(x))
if instr(field_lower_case, "form_thanks") OR instr(field_lower_case, "form_subject") OR instr(field_lower_case, "cc_to") OR instr(field_lower_case, "send_to") OR instr(field_lower_case, "submit") then
' nothing
else
strMsgBody = strMsgBody & Upload.Form.key(x) & ": " & Upload.Form.item(x) & chr(13)
end if
next

'add time
strMsgBody = "***************************************************************" & chr(13) & strMsgBody & chr(13) & "Date: " & FormatDateTime(Now) & chr(13)

bad_words_array = split(bad_words,",")
firstRecord = 0 'The first record to display
lastRecord = ubound(bad_words_array)

dump_the_email = false
for i = firstRecord to lastRecord
if dumpIt(strMsgBody, bad_words_array(i), 1) then dump_the_email = true
next
if dumpIt(strMsgBody, "http", hyperlink_occurances) then dump_the_email = true

phoneNumber = trim(Upload.Form("phoneNumber"))
if (phoneNumber = "") OR ( Len(phoneNumber) > 12) OR ( Len(phoneNumber) < 10) then dump_the_email = true

if dump_the_email then Response.Redirect default_error_page

' send notification
goodMsg = sendMail(strMsgBody,email_address,cc_to,email_subject,cc)

if goodMsg then ' no errors occured sending the mail
Response.Redirect strResponse
else
Response.Redirect default_error_page
end if


' *** end send email code *** '

end function

pablooliva
09-11-2008, 06:35 PM
And just to clarify, response.end is there to debug, the response.write never executes.

Bullschmidt
09-15-2008, 07:27 PM
Perhaps try changing this:
function SaveFiles

To be more like this instead (i.e. with parentheses):
Function SaveFiles()

sstalder
09-18-2008, 03:31 PM
Function something()
Call anotherFunction() ' Must be in this syntax
End Function

Function anotherFunction()

End Function