** Form Help **

Results 1 to 3 of 3

Thread: ** Form Help **

  1. #1
    Join Date
    Dec 1969
    Posts
    12

    Default ** Form Help **

    At this page:<BR>http://www.expressmicro.com/config.asp - I am trying to get the dropdown where the user selects a sales rep to directly mail that user, and also when the user checks the CC box it will email them - they already put their email address at the top of the form. The formmail script is below. Anyhelp is appreciated. Please email natacha@racksaver.com<BR><BR>Thanks,<BR>Natacha<BR ><BR>// The script is below.<BR><BR>&#060;%@ LANGUAGE="VBScript" %&#062;<BR><BR>&#060;% &#039;******************************************** *******************************<BR> &#039;* ASP FormMail *<BR> &#039;* *<BR> &#039;* Do not remove this notice. *<BR> &#039;* *<BR> &#039;* Copyright 1999, 2000 by Mike Hall. *<BR> &#039;* Please see http://www.brainjar.com for documentation and terms of use. *<BR> &#039;******************************************** *******************************<BR><BR> &#039;- Customization of these values is required, see documentation. -----------<BR><BR> referers = Array("www.expressmicro.com", "expressmicro.com","racksaver.com","www.racksaver. com")<BR> mailComp = "ASPMail"<BR> smtpServer = "mail.expressmicro.com."<BR> fromAddr = "natacha@racksaver.com"<BR><BR> &#039;- End required customization section. -------------------------------------<BR><BR> Response.Buffer = true<BR> errorMsgs = Array()<BR><BR> &#039;Check for form data.<BR><BR> if Request.ServerVariables("Content_Length") = 0 then<BR> call AddErrorMsg("No form data submitted.")<BR> end if<BR><BR> &#039;Check if referer is allowed.<BR><BR> validReferer = false<BR> referer = GetHost(Request.ServerVariables("HTTP_REFERER"))<B R> for each host in referers<BR> if host = referer then<BR> validReferer = true<BR> end if<BR> next<BR> if not validReferer then<BR> if referer = "" then<BR> call AddErrorMsg("No referer.")<BR> else<BR> call AddErrorMsg("Invalid referer: &#039;" & referer & "&#039;.")<BR> end if<BR> end if<BR><BR> &#039;Check for the recipients field.<BR><BR> if Request.Form("_recipients") = "" then<BR> call AddErrorMsg("Missing email recipient.")<BR> end if<BR><BR> &#039;Check all recipient email addresses.<BR><BR> recipients = Split(Request.Form("_recipients"), ",")<BR> for each name in recipients<BR> name = Trim(name)<BR> if not IsValidEmail(name) then<BR> call AddErrorMsg("Invalid email address in recipient list: " & name & ".")<BR> end if<BR> next<BR> recipients = Join(recipients, ",")<BR><BR> &#039;Get replyTo email address from specified field, if given, and check it.<BR><BR> name = Trim(Request.Form("_replyToField"))<BR> if name &#060;&#062; "" then<BR> replyTo = Request.Form(name)<BR> else<BR> replyTo = Request.Form("_replyTo")<BR> end if<BR> if replyTo &#060;&#062; "" then<BR> if not IsValidEmail(replyTo) then<BR> call AddErrorMsg("Invalid email address in reply-to field: " & replyTo & ".")<BR> end if<BR> end if<BR><BR> &#039;Get subject text.<BR><BR> subject = Request.Form("_subject")<BR><BR> &#039;If required fields are specified, check for them.<BR><BR> if Request.Form("_requiredFields") &#060;&#062; "" then<BR> required = Split(Request.Form("_requiredFields"), ",")<BR> for each name in required<BR> name = Trim(name)<BR> if Left(name, 1) &#060;&#062; "_" and Request.Form(name) = "" then<BR> call AddErrorMsg("Missing value for " & name)<BR> end if<BR> next<BR> end if<BR><BR> &#039;If a field order was given, use it. Otherwise use the order the fields were<BR> &#039;received in.<BR><BR> str = ""<BR> if Request.Form("_fieldOrder") &#060;&#062; "" then<BR> fieldOrder = Split(Request.Form("_fieldOrder"), ",")<BR> for each name in fieldOrder<BR> if str &#060;&#062; "" then<BR> str = str & ","<BR> end if<BR> str = str & Trim(name)<BR> next<BR> fieldOrder = Split(str, ",")<BR> else<BR> fieldOrder = FormFieldList()<BR> end if<BR><BR> &#039;If there were no errors, build the email note and send it.<BR><BR> if UBound(errorMsgs) &#060; 0 then<BR><BR> &#039;Build table of form fields and values.<BR><BR> body = "&#060;table border=0 cellpadding=2 cellspacing=0&#062;" & vbCrLf<BR> for each name in fieldOrder<BR> body = body _<BR> & "&#060;tr valign=top&#062;" _<BR> & "&#060;td&#062;&#060;b&#062;" _<BR> & name _<BR> & ":&nbsp;&#060;/b&#062;&#060;/font&#062;&#060;/td&#062;" _<BR> & "&#060;td&#062;" _<BR> & Request.Form(name) _<BR> & "&#060;/td&#062;" _<BR> & "&#060;/tr&#062;" & vbCrLf<BR> next<BR> body = body & "&#060;/table&#062;" & vbCrLf<BR><BR> &#039;Add a table with any environmental variables.<BR><BR> if Request.Form("_envars") &#060;&#062; "" then<BR> body = body _<BR> & "&#060;p&#062;" _<BR> & "&#060;table border=0 cellpadding=2 cellspacing=0&#062;" & vbCrLf<BR> envars = Split(Request.Form("_envars"), ",")<BR> for each name in envars<BR> name = Trim(name)<BR> body = body _<BR> & "&#060;tr valign=top&#062;" _<BR> & "&#060;td&#062;&#060;b&#062;" _<BR> & name _<BR> & ":&nbsp;&#060;/b&#062;&#060;/td&#062;" _<BR> & "&#060;td&#062;" _<BR> & Request.ServerVariables(name) _<BR> & "&#060;/td&#062;" _<BR> & "&#060;/tr&#062;" & vbCrLf<BR> next<BR> body = body & "&#060;/table&#062;" & vbCrLf<BR> end if<BR><BR> &#039;Send it.<BR><BR> str = SendMail()<BR> if str &#060;&#062; "" then<BR> AddErrorMsg(str)<BR> end if<BR><BR> &#039;Redirect if a URL was given.<BR><BR> if Request.Form("_redirect") &#060;&#062; "" then<BR> Response.Redirect(Request.Form("_redirect"))<BR> end if<BR><BR> end if %&#062;<BR><BR>&#060;html&#062;<BR>&#060;head&#062 ;<BR>&#060;title&#062;Form Mail&#060;/title&#062;<BR>&#060;style style="text/css"&#062;<BR><BR>body {<BR> background-color: #ffffff;<BR> color: #000000;<BR> font-family: Arial, Helvetica, sans-serif;<BR> font-size: 10pt;<BR>}<BR><BR>table {<BR> border: solid 1px #000000;<BR> border-collapse: collapse;<BR>}<BR><BR>td, th {<BR> border: solid 1px #000000;<BR> border-collapse: collapse;<BR> font-family: Arial, Helvetica, sans-serif;<BR> font-size: 10pt;<BR> padding: 2px;<BR> padding-left: 8px;<BR> padding-right: 8px;<BR>}<BR><BR>.error {<BR> color: #c00000;<BR>}<BR><BR>&#060;/style&#062;<BR>&#060;/head&#062;<BR>&#060;body&#062;<BR><BR>&#060;% if UBound(errorMsgs) &#062;= 0 then %&#062;<BR>&#060;p class="error"&#062;Form could not be processed due to the following errors:&#060;/p&#062;<BR>&#060;ul&#062;<BR>&#060;% for each msg in errorMsgs %&#062;<BR> &#060;li class="error"&#062;&#060;% = msg %&#062;<BR>&#060;% next %&#062;<BR>&#060;/ul&#062;<BR>&#060;/td&#062;&#060;/tr&#062;&#060;/table&#062;<BR>&#060;% else %&#062;<BR>&#060;table cellpadding=0 cellspacing=0 width=450&#062;<BR>&#060;tr style="background-color:#c0c0c0;"&#062;<BR> &#060;th colspan=2 valign=bottom&#062;<BR> Thank you, the following information has been sent:<BR> &#060;/th&#062;<BR>&#060;/tr&#062;<BR>&#060;% for each name in fieldOrder %&#062;<BR>&#060;tr style="background-color:#ffffff;" valign=top&#062;<BR> &#060;td&#062;&#060;b&#062;&#060;% = name %&#062;&#060;/b&#062;&nbsp;&#060;/td&#062;<BR> &#060;td&#062;&#060;% = Request.Form(name) %&#062;&nbsp;&#060;/td&#062;<BR>&#060;/tr&#062;<BR>&#060;% next %&#062;<BR>&#060;/table&#062;<BR>&#060;% end if %&#062;<BR><BR>&#060;/body&#062;<BR>&#060;/html&#062;<BR><BR>&#060;% &#039;---------------------------------------------------------------------------<BR> &#039; Subroutines and functions.<BR> &#039;---------------------------------------------------------------------------<BR><BR> sub AddErrorMsg(msg)<BR><BR> dim n<BR><BR> &#039;Add an error message to the list.<BR><BR> n = UBound(errorMsgs)<BR> Redim Preserve errorMsgs(n + 1)<BR> errorMsgs(n + 1) = msg<BR><BR> end sub<BR><BR> function GetHost(url)<BR><BR> dim i, s<BR><BR> GetHost = ""<BR><BR> &#039;Strip down to host or IP address and port number, if any.<BR><BR> if Left(url, 7) = "http://" then<BR> s = Mid(url, 8)<BR> elseif Left(url, 8) = "https://" then<BR> s = Mid(url, 9)<BR> end if<BR> i = InStr(s, "/")<BR> if i &#062; 1 then<BR> s = Mid(s, 1, i - 1)<BR> end if<BR><BR> getHost = s<BR><BR> end function<BR><BR> function IsValidEmail(email)<BR><BR> dim names, name, i, c<BR><BR> &#039;Check for valid syntax in an email address.<BR><BR> IsValidEmail = true<BR> names = Split(email, "@")<BR> if UBound(names) &#060;&#062; 1 then<BR> IsValidEmail = false<BR> exit function<BR> end if<BR> for each name in names<BR> if Len(name) &#060;= 0 then<BR> IsValidEmail = false<BR> exit function<BR> end if<BR> for i = 1 to Len(name)<BR> c = Lcase(Mid(name, i, 1))<BR> if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) &#060;= 0 and not IsNumeric(c) then<BR> IsValidEmail = false<BR> exit function<BR> end if<BR> next<BR> if Left(name, 1) = "." or Right(name, 1) = "." then<BR> IsValidEmail = false<BR> exit function<BR> end if<BR> next<BR> if InStr(names(1), ".") &#060;= 0 then<BR> IsValidEmail = false<BR> exit function<BR> end if<BR> i = Len(names(1)) - InStrRev(names(1), ".")<BR> if i &#060;&#062; 2 and i &#060;&#062; 3 then<BR> IsValidEmail = false<BR> exit function<BR> end if<BR> if InStr(email, "..") &#062; 0 then<BR> IsValidEmail = false<BR> end if<BR><BR> end function<BR><BR> function FormFieldList()<BR><BR> dim str, i, name<BR><BR> &#039;Build an array of form field names ordered as they were received.<BR><BR> str = ""<BR> for i = 1 to Request.Form.Count<BR> for each name in Request.Form<BR> if Left(name, 1) &#060;&#062; "_" and Request.Form(name) is Request.Form(i) then<BR> if str &#060;&#062; "" then<BR> str = str & ","<BR> end if<BR> str = str & name<BR> exit for<BR> end if<BR> next<BR> next<BR> FormFieldList = Split(str, ",")<BR><BR> end function<BR><BR> function SendMail()<BR><BR> dim mailObj<BR> dim addrList<BR><BR> &#039;Send email based on mail component. Uses global variables for parameters<BR> &#039;because there are so many.<BR><BR> SendMail = ""<BR><BR> &#039;Send email (CDONTS version), doesn&#039;t support reply-to address and has<BR> &#039;no error checking.<BR><BR> if mailComp = "CDONTS" then<BR> set mailObj = Server.CreateObject("CDONTS.NewMail")<BR> mailObj.BodyFormat = 0<BR> mailObj.MailFormat = 0<BR> mailObj.From = fromAddr<BR> mailObj.To = recipients<BR> mailObj.Subject = subject<BR> mailObj.Body = body<BR> mailObj.Send<BR> end if<BR><BR> &#039;Send email (JMail version).<BR><BR> if mailComp = "JMail" then<BR> set mailObj = Server.CreateObject("JMail.SMTPMail")<BR> mailObj.Silent = true<BR> mailObj.ServerAddress = smtpServer<BR> mailObj.Sender = fromAddr<BR> mailObj.ReplyTo = replyTo<BR> mailObj.Subject = subject<BR> addrList = Split(recipients, ",")<BR> for each addr in addrList<BR> mailObj.AddRecipient Trim(addr)<BR> next<BR> mailObj.ContentType = "text/html"<BR> mailObj.Body = body<BR> if not mailObj.Execute then<BR> SendMail = "Email send failed: " & mailObj.ErrorMessage & "."<BR> end if<BR> end if<BR><BR> &#039;Send email (ASPMail version).<BR><BR> if mailComp = "ASPMail" then<BR> set mailObj = Server.CreateObject("SMTPsvg.Mailer")<BR> mailObj.FromAddress = fromAddr<BR> mailObj.RemoteHost = smtpServer<BR> mailObj.ReplyTo = replyTo<BR> for each addr in Split(recipients, ",")<BR> mailObj.AddRecipient "", Trim(addr)<BR> next<BR> mailObj.Subject = subject<BR> mailObj.ContentType = "text/html"<BR> mailObj.BodyText = body<BR> if not mailObj.SendMail then<BR> SendMail = "Email send failed: " & mailObj.Response & "."<BR> end if<BR> end if<BR><BR> end function %&#062;

  2. #2
    Join Date
    Dec 1969
    Posts
    1,686

    Default lol

    .

  3. #3
    Join Date
    Dec 1969
    Posts
    96,118

    Default After all that...

    ...you don&#039;t even show a check box on the page, so how can you get its value???<BR><BR>And I see at least one bug in that SendMail code, in any case.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •