Forums

This topic is locked

Any suggestions why my form results are returned i

Posted 13 Jan 2006 13:41:30
1
has voted
13 Jan 2006 13:41:30 Malcolm X posted:
Any suggestions why my form results are returned in a mess?

--------------------------------------------------------------------------------

Can anyone suggest why my form results are being sent to me in a complete mess. I have used the following with an psmail.asp page to return the results. I have included some of the code of each page.

An example of what is being returned to me is this.
Suburb: Brunswick
Country: Australia
Surname: Romeo
State: Victoria
Address: 11 David Street
Post Code: 3000
Name: Mally

What we would like to see returned is this.
Name: Mally
Address: 11 David Street
Suburb: Brunswick
State: Victoria
Country: Australia
Post Code: 3000<%
FromAddress = ""
AllowedHosts = "www.example.com"
AllowedReferrers = ""

Allow = False
AllowedHosts = Replace(AllowedHosts, " ", ""
AllowedReferrers = Replace(AllowedReferrers, " ", ""
AllowedHosts = Replace(AllowedHosts, Chr(9), ""
AllowedReferrers = Replace(AllowedReferrers, Chr(9), ""
Hosts = Split(AllowedHosts, ","
Referrers = Split(AllowedReferrers, ","
strTo = Trim(CStr(Request.Form("psmto"))
strFrom = Trim(CStr(Request.Form("Email"))
strSubject = Trim(CStr(Request.Form("psmsubject"))
strRedirect = Trim(CStr(Request.Form("psmredirect"))
if strSubject = "" then
strSubject = "Website feedback from " & Request.ServerVariables ("HTTP_REFERER"
end if
if strFrom = "" then
strFrom = FromAddress
end if
strTo = Replace(strTo, ";", ","
Rcpt = Split(strTo, ","
RebuildToString(Rcpt)
Allow = Allowed(Hosts, BaseHost(Request.ServerVariables ("HTTP_REFERER"))
if Allow <> True then
Allow = Allowed(Referrers, Request.ServerVariables ("HTTP_REFERER")
end if
if strTo = "" or strFrom = "" then
Response.Write("<br><b>Invalid or missing to or from field(s)</b><br>"
elseif AllowedHosts = "" and AllowedReferrers = "" then
Response.Write("<br><b>Configuration error: AllowedHosts or AllowedReferrers must not be empty</b><br>"
elseif Allow = False then
Response.Write("<br><b>You are not authorized to use this script. [referrers]</b><br>" & Request.ServerVariables ("HTTP_REFERER")
elseif strFrom <> "" and IsEmail(strFrom) = false then
Response.Write("<br><b>Invalid sender.</b><br>"
else
strBody = strBody & "to: " & strTo & vbCRLF
strBody = strBody & "from: " & strFrom & vbCRLF
strBody = strBody & "subject: " & strSubject & vbCRLF & vbCRLF
for each name in Request.Form
if LCase(name) <> "psmto" and LCase(name) <> "Email" and LCase(name) <> "psmsubject" and LCase(name) <> "psmredirect" then
strBody = strBody & name & ": " & CStr(Request.Form(name)) & vbCRLF & vbCRLF
end if
next
strBody = strBody & vbCRLF & vbCRLF
strBody = strBody & "date: " & Now & vbCRLF
strBody = strBody & "remote host: " & Request.ServerVariables ("REMOTE_ADDR" & vbCRLF
strBody = strBody & "source URL: " & Request.ServerVariables ("HTTP_REFERER" & vbCRLF
strBody = strBody & "hostname: " & Request.ServerVariables ("HTTP_HOST" & vbCRLF
Set objMessage = Server.CreateObject("CDO.Message"
objMessage.Subject = strSubject
objMessage.Sender = strFrom
objMessage.To = strTo
objMessage.TextBody = strBody
objMessage.Send
Set objMessage = Nothing
if strRedirect <> "" then
response.redirect(CStr(strRedirect))
else
Response.Write("<br><b>Message sent.</b><br>"
end if
end if
Function BaseHost(host)
Dim x, tempstring
If InStr(host, "://" <> 0 Then
host = Mid(host, InStr(host, "://"+3)
End If
host = strreverse(host)
tmpstring = host
x = Len(host)
for y = x to 1 step -1
if mid(host, y, 1) = "/" Then
tmpstring = mid(host, y+1)
exit for
end if
next
BaseHost = strreverse(tmpstring)
End Function
Function ValidateDomain(strRef)
dim x
ValidateDomain = false
for each x in Hosts
if x <> "" and Instr(1, strRef, x, 1) > 0 then
ValidateDomain = true
exit for
end if
next
End Function
Function IsEmail(sEmail)
Dim regEx, retVal
IsEmail = false
Set regEx = New RegExp
regEx.Pattern ="^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$"
regEx.IgnoreCase = true
retVal = regEx.Test(sEmail)
If not retVal Then
exit function
End If
IsEmail = true
End Function
Function Allowed(ThisArray(), ThisString)
Allowed = False
for each x in ThisArray
if LCase(ThisString)= LCase(x)then
Allowed = True
exit for
end if
next
End Function
Sub RebuildToString(Rcpt())
Dim x
strTo = ""
for each x in Rcpt
if IsEmail(trim(x)) = True then
strTo = strTo & trim(x) & ", "
end if
next
x = Len(strTo)
if x > 0 then
strTo = Trim(strTo)
strTo = ChopChar(strTo, ","
end if
End Sub
Function ChopChar(strString, strChar)
Dim x
x = Len(strString)
if mid(strString, x) = strChar then
ChopChar = mid(strString, 1, x -1)
else
ChopChar = strString
end if
End Function
%>

Replies

Replied 13 Jan 2006 17:58:08
13 Jan 2006 17:58:08 Lee Diggins replied:
Hi Malcolm

What do you mean a complete mess? Are you referring to the order? You might find that somewhere the page is looping through the form items to get the name/value pairs, if you want them returned in a specific order, you'll need to get a bit more specific with the code.

Web servers, do not guarantee the order in which the items in a form or querystring collection are returned, they only guarantee they will be returned.

Maybe I've got the wrong end of the stick, don't know, post back.

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>

Reply to this topic