Expected end of statement

Discussion in 'C#' started by raith, Jun 4, 2007.

  1. #1
    I am trying to test this asp email form but am getting errors and am trying to solve them so I can see the output. Can someone look at my code and make some suggestions? BTW I think I need to replace my reference to CDONTS due to the fact that I'm testing with Windows Server 2003 and ASP 3.0. Might have to find some sample code online to replace that.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <% 'Check for form data.
       if Request.ServerVariables("Content_Length") = 0 then
         call AddErrorMsg("No form data submitted.")
       end if
       'Check if referer is allowed.
       validReferer = false
       referer = GetHost(Request.ServerVariables("HTTP_REFERER"))
       for each host in referers
         if host = referer then
           validReferer = true
         end if
       next
       if not validReferer then
         if referer = "" then
           call AddErrorMsg("No referer.")
         else
           call AddErrorMsg("Invalid referer: '" & referer & "'.")
         end if
       end if
       'Check for the recipients field.
       if Request.Form("_recipients") = "" then
         call AddErrorMsg("Missing email recipient.")
       end if %>
    
    <% 'Check all recipient email addresses.
       recipients = Split(Request.Form("_recipients"), ",")
       for each name in recipients
         name = Trim(name)
         if not IsValidEmailAddress(name) then
           call AddErrorMsg("Invalid email address in " _
             & "recipient list: " name & ".")
         end if
       next
       recipients = Join(recipients, ",") %>
    
    <% 'Get replyTo email address from specified field, if given, and
       'check it.
       name = Trim(Request.Form("_replyToField"))
       if name <> "" then
         replyTo = Request.Form(name)
       else
         replyTo = Request.Form("_replyTo")
       end if
       if replyTo <> "" then
         if not IsValidEmailAddress(replyTo) then
           call AddErrorMsg("Invalid email address in " _
             & "reply-to field: " & replyTo & ".")
         end if
       end if %gt;
    
     'If required fields are specified, check for them.
       if Request.Form("_requiredFields") <> "" then
         required = Split(Request.Form("_requiredFields"), ",")
         for each name in required
           name = Trim(name)
           if Left(name, 1) <> "_" and Request.Form(name) = "" then
           call AddErrorMsg("Missing value for " & name)
           end if
         next
       end if %gt;
    
    % 'Build table of form fields and values.
       body = "<table border=""0"" cellpadding=""2""" _
            & cellspacing=""0"">" & vbCrLf
       for each name in fieldOrder
         body = body _
              & "<tr valign=""top"">" _
              & "<td><b>" & name & ":</b></td>" _
              & "<td>" & Request.Form(name) & "</td>" _
              & "</tr>" & vbCrLf
       next
       body = body & "</table>" & vbCrLf %>
    
    <% function FormFieldList()
         dim str, i, name
         'Build an array of form field names ordered as they
         'were received.
         str = ""
         for i = 1 to Request.Form.Count
           for each name in Request.Form
             if Left(name, 1) <> "_" and _
                Request.Form(name) is Request.Form(i) then
               if str <> "" then
                 str = str & ","
               end if
               str = str & name
               exit for
             end if
           next
         next
         FormFieldList = Split(str, ",")
       end function %>
    
    <% 'Add a table for any requested environmental variables.
       if Request.Form("_envars") <> "" then
         body = body _
              & "<p>&nbsp;</p>" & vbCrLf _
              & "<table border=""0"" cellpadding=""2""" _
              & "cellspacing=""0"">" & vbCrLf
         envars = Split(Request.Form("_envars"), ",")
         for each name in envars
           name = Trim(name)
           body = body _
                & "<tr valign=""top"">" _
                & "<td><b>" & name & ":</b></td>" _
                & "<td>" & Request.ServerVariables(name) & "</td>" _
                & "</tr>" & vbCrLf
         next
         body = body & "</table>" & vbCrLf
       end if %>
    
    <% if mailComp = "CDONTS" then
         set mailObj = Server.CreateObject("CDONTS.NewMail")
         mailObj.BodyFormat = 0
         mailObj.MailFormat = 0
         mailObj.From = fromAddr
         mailObj.Value("Reply-To") = replyTo
         mailObj.To = recipients
         mailObj.Subject = subject
         mailObj.Body = body
         mailObj.Send
         set mailObj = Nothing
         exit function
       end if %>
    
    <body>
    <form action="/scripts/formmail.asp" method="post">
    <p>
    <input name="_recipients" type="hidden" value="testuser@mycompany.org" />
    <input name="_requiredFields" type="hidden"
      value="Name,Customer ID,Email,Comments" />
    Name: <input name="Name" type="text" /><br />
    Customer ID: <input name="Customer ID" type="text" /><br />
    Email Address: <input name="Email" type="text" /><br />
    Comments:<br />
    <textarea name="Comments" rows=5 cols=50></textarea>
    <input type="submit" value="Submit" />
    <input type="reset" value="Clear" />
    </p>
    </form>
    </body>
    </html>
    
    Code (markup):
    Your thoughts?
     
    raith, Jun 4, 2007 IP
  2. sunpost

    sunpost Peon

    Messages:
    23
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
         if not IsValidEmailAddress(name) then
           call AddErrorMsg("Invalid email address in " _
             & "recipient list: " name & ".")
         end if
    Code (markup):
    should be

         if not IsValidEmailAddress(name) then
           call AddErrorMsg("Invalid email address in " _
             & "recipient list: " & name & ".")
         end if
    Code (markup):
    check out the brainjar version...it can use cdosys to send the message.
    http://www.brainjar.com/asp/formmail/
     
    sunpost, Jun 4, 2007 IP
  3. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Nice catch sunpost:

    Yup, I would definitely swtich from cdonts to cdosys as well :)
     
    ccoonen, Jun 8, 2007 IP