Click to See Complete Forum and Search --> : how would I add <options>dropdown, other text fields to this ASP form?


The Cobbler
06-10-2005, 04:03 PM
Hi All:

I have a standard asp contact code to go with an email form that has the following input areas: email, subject, and body. How would I add additional functionality and obtain more information through the form, such as address, phone number, a category dropdown box, etc? It looks like with this code that the ObjSendMail only allows ObjSendMail.To, ObjSendMail.From, and ObjSendMail.Body, these are the only fields I can have. So how would I add my own specialized fields? BTW, I'm a total newbie at ASP, and I think the server supports CDOSYS, not CDONTS, if that makes a difference.

Here's my form code:

<form action="contact_us.asp" method="POST">
<input type="hidden" name="Action" value="SendEmail">

<font size="2">Contact Us:</font>
<br><br>
<table border="0" cellspacing="1">
<tr>
<td valign="top">
Name:
</td>
<td colspan="2">
<input type="text" name="ContactUs_Name" size="35">
</td>
</tr>
<tr>
<td valign="top">
Email:
</td>
<td colspan="2">
<input type="text" name="ContactUs_Email" size="35">
</td>
</tr>
<tr>
<td>Address</td>
<td><input size="50" name="Address1"></td>
</tr>
<tr>
<td valign="top">
Picture Number <br />(this is the second string of numbers<br /> under your picture at the top of the page, <br />for example, BrewPub050604_0002P079.JPG):
</td>
<td colspan="2">
<input type="text" name="ContactUs_Subject" size="35">
</td>
</tr>
<tr>
<td valign="top">
Your contact information <br />(your street address, city, state, and ZIP):
</td>
<td valign="top">
<textarea rows="10" name="ContactUs_Body" cols="40"></textarea>
</td>
</tr>
<tr>
<td valign="top">
&nbsp;
</td>
<td colspan="2">
<input type="submit" value="Send Message">
</td>
</tr>
</table>
</form>

As you can see, right now I'm asking for all the contact info in one place, when in fact I'd like to have separate boxes for address, phone, etc.

Here's contact_us.asp:

<%@ LANGUAGE="VBSCRIPT" %>
<% option explicit %>
<% Response.Buffer = True %>



<%
'Declaring Variables
Dim smtpserver,youremail,yourpassword,ContactUs_Name,ContactUs_Email
Dim ContactUs_Subject,ContactUs_Body,Action,IsError

' Edit these 3 values accordingly
smtpserver = "mail.mydomain.com"
youremail = "info@mydomain.com"
yourpassword = "xxxxxx"

' Grabbing variables from the form post
ContactUs_Name = Request("ContactUs_Name")
ContactUs_Email = Request("ContactUs_Email")
ContactUs_Subject = Request("ContactUs_Subject")
ContactUs_Body = Request("ContactUs_Body")
Action = Request("Action")

' Used to check that the email entered is in a valid format
Function IsValidEmail(Email)
Dim

ValidFlag,BadFlag,atCount,atLoop,SpecialFlag,UserName,DomainName,atChr,tAr

y1
ValidFlag = False
If (Email <> "") And (InStr(1, Email, "@") > 0) And (InStr(1,

Email, ".") > 0) Then
atCount = 0
SpecialFlag = False
For atLoop = 1 To Len(Email)
atChr = Mid(Email, atLoop, 1)
If atChr = "@" Then atCount =

atCount + 1
If (atChr >= Chr(32)) And (atChr

<= Chr(44)) Then SpecialFlag = True
If (atChr = Chr(47)) Or (atChr =

Chr(96)) Or (atChr >= Chr(123)) Then SpecialFlag = True
If (atChr >= Chr(58)) And (atChr

<= Chr(63)) Then SpecialFlag = True
If (atChr >= Chr(91)) And (atChr

<= Chr(94)) Then SpecialFlag = True
Next
If (atCount = 1) And (SpecialFlag = False) Then
BadFlag = False
tAry1 = Split(Email, "@")
UserName = tAry1(0)
DomainName = tAry1(1)
If (UserName = "") Or (DomainName = "") Then

BadFlag = True
If Mid(DomainName, 1, 1) = "." then BadFlag =

True
If Mid(DomainName, Len(DomainName), 1) =

"." then BadFlag = True
ValidFlag = True
End If
End If
If BadFlag = True Then ValidFlag = False
IsValidEmail = ValidFlag
End Function
%>

<html>

<head>
<title>Contact Us Form ( Powered By PowerASP.com )</title>
</head>

<body style="font-family: Arial; font-size: 12px">

<%
If Action = "SendEmail" Then

' Here we quickly check/validate the information entered
' These checks could easily be improved to look for more things
If IsValidEmail(ContactUs_Email) = "False" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a

valid email address.</font><br>")
End If

If ContactUs_Name = "" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a

Name.</font><br>")
End If

If ContactUs_Subject = "" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a

Picture Number.</font><br>")
End If

If ContactUs_Body = "" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter

Your Mailing Address and Phone Number.</font><br>")
End If

End If

' If there were no input errors and the action of the form is "SendEMail" we send the

email off
If Action = "SendEmail" And IsError <> "Yes" Then

Dim strBody

' Here we create a nice looking html body for the email
strBody = strBody & "<font face=""Arial"">Contact Us Form submitted

at " & Now() & vbCrLf & "<br><br>"
strBody = strBody & "From http://" &

Request.ServerVariables("HTTP_HOST") & vbCrLf & "<br>"
strBody = strBody & "IP " &

Request.ServerVariables("REMOTE_ADDR") & vbCrLf & "<br>"
strBody = strBody & "Name" & " : " & " " &

Replace(ContactUs_Name,vbCr,"<br>") & "<br>"
strBody = strBody & "Email" & " : " & " " &

Replace(ContactUs_Email,vbCr,"<br>") & "<br>"
strBody = strBody & "Subject" & " : " & " " &

Replace(ContactUs_Subject,vbCr,"<br>") & "<br>"
strBody = strBody & "<br>" & Replace(ContactUs_Body,vbCr,"<br>")

& "<br>"
strBody = strBody & "</font>"

Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")

'This section provides the configuration information for the remote SMTP

server.

ObjSendMail.Configuration.Fields.Item

("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message

using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item

("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpserver
ObjSendMail.Configuration.Fields.Item

("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item

("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for

the connection (True or False)
ObjSendMail.Configuration.Fields.Item

("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

' If your server requires outgoing authentication uncomment the lines

bleow and use a valid email address and password.
ObjSendMail.Configuration.Fields.Item

("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic

(clear-text) authentication
ObjSendMail.Configuration.Fields.Item

("http://schemas.microsoft.com/cdo/configuration/sendusername") = youremail
ObjSendMail.Configuration.Fields.Item

("http://schemas.microsoft.com/cdo/configuration/sendpassword") = yourpassword

ObjSendMail.Configuration.Fields.Update

'End remote SMTP server configuration section==

ObjSendMail.To = youremail
ObjSendMail.Subject = ContactUs_Subject
ObjSendMail.From = ContactUs_Email

' we are sending a html email.. simply switch the comments around to

send a text email instead
ObjSendMail.HTMLBody = strBody
'ObjSendMail.TextBody = strBody

ObjSendMail.Send

Set ObjSendMail = Nothing


%>
<%

Response.redirect "http://www.lasvegaspics.com/thankyou.html"

%>
<% Else %>


<% End If %>

All of the above works, but it seems like too much of a hack. I know there is a better and more elegant way to do this, so, all you experts out there (like PHPNovice, for instance :) )

Any help would be muchly appreciated!

THanks so much,

Sincerely,

Vickie

phpnovice
06-10-2005, 04:08 PM
If you're talking about sending controls in an email, then you have to send them as HTML (in the body of the email). If you're talking about sending the selected values from an HTML FORM in an email, then you just have to extract the data from the form and concatenate it into a string -- with other text you supply -- and then assign that resulting string to the body of the email.

The Cobbler
06-10-2005, 04:22 PM
HI PHPNovice!!!
Man I'm glad you're around. But alas, what you're saying is too advanced for my tiny non-programmer's mind. Could you give me an example in code of how I would add an Address1 field, and a Zip Code field? Then I would understand.

Also, I need to pass a variable from that HTML page to the form and then to the email. For example, this is a page where people buy or claim pictures. When the customers want to buy, they go through paypal, and the particular picture they want is passed to that form through @file.

Here is an example:

<tr>
<td class="border"><p><strong>Ultimate Combo Pak--$49.99</strong><br />
Includes 2 (two) Beautiful 8X10 Prints plus 5 (five) 4X6 Prints of the same photo. All of the photos are printed on the finest 10 mil Gloss Paper available, and each of the seven prints is enclosed in its own protective clear envelope.</p>
</td>
<td class="border">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="paypal">
<input type="hidden" name="bn" value="AMPPFPWZ.255">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="business" value="PhotoOrder@LasVegasPics.com">
<input type="hidden" name="item_name" value="Ultimate Combo Pak 2(two) 8x10 Prints and 5(five) 4x6 Prints @file@ @caption@">

<input type="hidden" name="item_number" value="@year@@month@@file@@IPTC-jobID@-UCP-1">

<input type="hidden" name="amount" value="49.99">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="undefined_quantity" value="0">
<input type="hidden" name="return" value="http://LasVegasPics.com/locations.html">
<input type="hidden" name="cancel_return" value="http://LasVegasPics.com/Authorize_not.html">
<p>
<input type="image" name="submit" src="addcart.gif" alt="Order these prints using PayPal" width="106" height="24">
</p>

A separate program called BreezeBrowser generates this template with all the various 'tokens', @file, @IPTC-jobID, etc. Then these are passed to paypal so the merchant knows exactly which picture was purchased. So what I'm trying to do, in addition to having more input fields in this ASP script, is to pass the exact parameters (is that the right word?) of the picture through to the email so the customer doesn't have to type it in (it's a really long number), and the merchant will then know exactly which picture is being claimed.

D'oh! That's a mouthful! Sorry if this is a long post. As I said, I'm a web designer and new to programming so I'm sorta winging it here.

Maybe I would be better off finding a cgi script I can use??? It's just that when I get started on something I like to stick with it until it works and I sorta understand it.

Thanks for any assistance,

Sincerely,

Vickie

phpnovice
06-10-2005, 04:25 PM
First you have to resolve my initial confusion. Which of the two scenarios I mentioned are you actually seeking to accomplish?

The Cobbler
06-10-2005, 04:31 PM
Sorry, I want to send the selected values from an HTML FORM in an email, the latter.

:)Vickie

phpnovice
06-10-2005, 05:25 PM
To concatenate FORM values received from the client into a string:

<%
Dim str1
str1 = "First name: " & Request.Form("firstname") & vbCrLf
str1 = "Last name: " & Request.Form("lastname") & vbCrLf
str1 = "Address: " & Request.Form("address") & vbCrLf
str1 = "City: " & Request.Form("city") & vbCrLf
str1 = "State: " & Request.Form("state") & vbCrLf
str1 = "Zip: " & Request.Form("zipcode") & vbCrLf
' etc.
%>