[thelist] ASP and form question

Sharon F. Malone sfmalo at 24caratdesign.com
Mon Jul 8 01:44:01 CDT 2002


Hi, Guys!

The Head Lemur sent me an ASP script which I am now using ... and everything is working in it except for the strBody portion. In other words, I am now receiving my test emails but they are missing the Body portion which should be the readout of all fields answered in the form. In the original script he sent me, the strBody variable was missing so I wrote it in on line 25 (but am not sure that I did so properly). It didn't work with strBody variable missing so I wrote in a strBody and it still didn't work. So I tried strDefBody and it still isn't working. So I'm missing something here.

Could it be the reference to Request.Form in
line 25 strDefBody = "Sent by: " & Request.Form("require") & vbCrlf & vbCrlf_    & Request.Form("order")? I'm not sure what "Request.Form" refers to in relation to my form, so I may have that wrong. And I think I have "require" and "order" correct but not sure.

I've made corrections to the form code as you all have suggested (which I hope are correct).  So here's what I have. What do you think?

First, the beginning portion of the form:
<.script Language="JavaScript"><!--
function Order_Form_Validator(theForm)
{

  if (theForm.name.value == "")
  {
    alert("Please enter a value for the \"name\" field.");
    theForm.name.focus();
    return (false);
   }
    return (true);
}
//--></script>
<.form name="InfoOrderForm" action="process.asp" method="post" enctype="text/plain" onSubmit="return Order_Form_Validator(this)"><input type="hidden" name="require" value="fullname"><.input type="hidden" name="order"
value="fullname,address,city,state,zip,home phone,work phone,fax,email,Best Sellers,Special Gifts,Seasonal Selections,Corporate Gifts,Party Favors,Other Items,Comments">

Now the VBscript:

<%@language = "VBscript"%>
<%
Dim strError
Response.Buffer = True
If ScriptEngineMajorVersion < 2 Then
ReportError "Host system needs scripting engine upgrade to use this script"
End If
Set objFM = CreateObject("Scripting.Dictionary")
If IsObject(objFM) = False Then
ReportError "Host system lacks component(s) required by this script"
End If
Set objMailx = CreateObject("CDONTS.Newmail")
If IsObject(objMailx) = False Then
ReportError "Host system lacks component(s) required by this script"
End If
Set objMailx = Nothing
%>
<%
strRcpt = "The Chocolate Foundry<sfmalo at 24caratdesign.com>"
strBCC = "cheftrain at yahoo.com"
strFromVar = "Email"
strDefFrom = "webmaster at 24caratdesign.com"
strDefSubject = "Web Site Form Request"
strDefBody = "Sent by: " & Request.Form("require") & vbCrlf & vbCrlf_         & Request.Form("order")
strRedirect = "http://www.chefsteve.com/chocfoundry/html/confirm.html"
%>
<%
ParseForm
CheckForm
If Len(strError) > 0 Then
ReportError strError
End If
strOutX = SeqForm
If Len(strOutX) < 1 Then
strOutX = FormToString
End If
If Len(strOutX) < 1 Then
ReportError "Submitted form is empty"
End If
strSubject = strDefSubject
If objFM.Exists("subject") Then
strSubject = objFM.Item("subject")
End If
strFrom = strDefFrom
If Len(strFromVar) > 0 Then
If objFM.Exists(strFromVar) Then strFrom = objFM.Item(strFromVar) End If
End If
SendMail strFrom,strRcpt,strBCC,strSubject,strOutX
If Len(strRedirect) > 0 Then
Response.redirect(strRedirect)
Response.End
End If
If objFM.Exists("redirect") = True Then
If Len(objFM.Item("redirect")) > 0 Then
Response.redirect(objFM.Item("redirect"))
Response.End
End If
End If
%>

<%
Credit
Response.End
%>
<%
Function IsValidEmail(Email)
Dim Temp,Temp2
strNotValid = "<br>Email address not valid"
strTooLong = "<br>Email address too long"
If Len(Email) > 50 Then '[5000 not necessary anymore]
ReportError strTooLong
End If
Email = LCase(Email)
Temp = Split(Email,"@",2,1)
If UBound(Temp) < 1 Then
ReportError strNotValid
End If
Temp2 = Split(Temp(1),".",-1,1)
If UBound(Temp2) < 1 Then
ReportError strNotValid
End If
End Function
%>

<%
Function SendMail(From,Rcpt,Blind,Subject,Body)
Trim(From)
Trim(Rcpt)
If Len(From) < 1 Then
ReportError strError & "<br>No Reply-to address (From) for this letter"
End If
If Len(Rcpt) < 1 Then
ReportError strError & "<br>No recipient for this letter"
End If
'IsValidEmail Rcpt '[commented out as not necessary as it's hardcoded]
IsValidEmail From
Set objMailer = CreateObject("CDONTS.Newmail")
objMailer.From = From
objMailer.To = Rcpt
objMailer.BCC = Blind
objMailer.Subject = Subject
objMailer.Body = Body
objMailer.Send
Set objMailer = Nothing
End Function
%>
<%
Function CheckForm()
Dim Temp,strTmp,strForce
strInputReq = "<br>Input required for "
If objFM.Exists("require") = False Then
Exit Function
ElseIf isEmpty(objFM.Item("require")) Then
Exit Function
End If
strForce = objFM.Item("require")
Temp = Split(strForce,",",-1,1)
For Each strTmp in Temp
If objFM.Exists(strTmp) = False Then
strError = strError & strInputReq & strTmp
ElseIf Len(objFM.Item(strTmp)) < 1 Then
strError = strError & strInputReq & strTmp
End If
Next
End Function
%>
<%
Function ParseForm()
For Each Item in Request.Form
If objFM.Exists(Item) Then
objFM.Item(Item) = objFM.Item(Item) & "," & Request.QueryString(Item)
Else
objFM.Add Item,Request.Form(Item)
End If
Next
For Each Item in Request.QueryString
If objFM.Exists(Item) Then
objFM.Item(Item) = objFM.Item(Item) & "," & Request.QueryString(Item)
Else
objFM.Add Item,Request.QueryString(Item)
End If
Next
End Function
%>
<%
Function SeqForm()
Dim Temp,strTmp,strOrder,strOut
If objFM.Exists("order") = False Then
Exit Function
ElseIf isEmpty(objFM.Item("order")) Then
Exit Function
End If
strOrder = objFM.Item("order")
Temp = Split(strOrder,",",-1,1)
For Each strTmp in Temp
If objFM.Exists(strTmp) Then
strOut = strOut & strTmp & ": " & objFM.Item(strTmp) & Chr(10)
End If
Next
SeqForm = strOut
End Function
%>
<%
Function FormToString()
Dim strOut
strKeys = objFM.Keys
strValues = objFM.Items
For intCnt = 0 To objFM.Count -1
strOut = strOut & strKeys(intCnt) & ": " & strValues(intCnt) & Chr(10)
Next
FormToString = strOut
End Function
%>
<%
Function ReportError(strMess)
If Len(strMess) < 1 Then
strMess = strError
End If
strErr = "The following error(s) happened: <br>" & strMess
Response.Clear
End Function
%>

----- Original Message -----
From: "Madhu Menon" <webguru at vsnl.net>
To: <thelist at lists.evolt.org>
Sent: Sunday, July 07, 2002 11:13 PM
Subject: RE: [thelist] ASP and form question


> At 10:02 AM 7/8/2002, Joel Canfield wrote:
> >Agh! I missed that completely.
>
> As did I. I was looking at the ASP code too much.
>
> However, I did suggest in one of my earlier mails (sent within minutes of
> Sharon posting) that:
>
> <quote>
>
> a) Have you tried running the script with hard coded values for all fields
> instead of the form values? (e.g., "objmail.from = "someone at example.com")?
> Does that not work either?
>
> b) Is the SMTP service properly configured on your server? If not, your
> mail will never get anywhere.
>
> </quote>
>
> Sharon's answer seems to suggest that b) is OK, so it must be a)
>
> Sharon, this is standard debugging procedure for me:
>
> a) Eliminate the chances of invalid input causing the problem. First check
> if your script works by replacing all variables with hard-coded values. If
> this sends a mail properly, your basic script is fine, as is your server
> SMTP config.
>
> b) Ensure that all variables are returning the expected values. Comment out
> the portion of the code that sends the mail. Then Response.Write each
> variable to the screen. For example:
> Response.Write "From address: " & strFromAddress
>
> (Incidentally, I consider it better to assign variables to all form input
> and then reference the variables in the following code. So do strMessage =
> Request.Form("message") first, for instance, and then refer to strMessage
> from there onwards.)
>
> At this stage, you should be able to figure out what form values are
> causing problems. 90% of the time, fixing that will cure your script. Like
> Marc pointed out, maybe the names you're using in the HTML form aren't the
> same ones you're requesting in your form handler.
>
> c) If everything is fine now, uncomment the mail sending part of your
> script and try again. I'm sure it will work.
>
>
> >Also, better not to use 'name' as a name ;) I use RealName or split it,
> >FirstName and LastName.
>
> Good practice in general, although she's not writing to a db, which usually
> causes the problems. :)
>
> Regards,
>
> Madhu
>
---------------------------------------------------------------------------
Sharon F. Malone
"web design and Internet writing services"
http://www.24caratdesign.com
sfmalo at 24caratdesign.com




More information about the thelist mailing list