DreamweaverFAQ.com
Search the site!Search DWfaq.com | Print This PagePrinter Friendly Page
Current: Default | Default: ZOot3


DreamweaverFAQ.com » Tutorials » Forms » Asp Data Collection Forms- Creating The Response Page


ASP Data Collection Forms- Creating the Response Page

Coding the Response Page: VB Script

The response is initiated entirely with VB Script, we have no forms or anything else to add on this page. Your response page will doubtless incorporate the rest of your design, however the response information can be dragged around your page in design view so don't worry about complications in fitting this data into your design, because there aren't any!

OK so lets get this tutorial finished... nearly done now!

Once again we need to declare our use of VBScript, we know that this goes above the opening <html> tag so we'll add this to our page without further ado!

<%@LANGUAGE="VBSCRIPT"%>
<html>

Creating the Workhorse

The following section is the block of script that does all the work for us, it calls the form elements from the previous page using a method called Request.Form. The way we lay out the code on the response page will also reflect how the data is returned to the client, as I mentioned earlier we will lay the returned data out in such a way that it remains legible to the client without them having to squint at the information to find where one section starts and another finishes.

The code block below sits in the body of our page:

<% 
my_from=request("mail-fromName") 
my_fromAddress=request("mail-fromaddress")
my_to=request("mail-toName")
my_toAddress=request("mail-toaddress")
my_subject=request("mail-subject")
my_relay=request("mail-relay") Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = my_relay
Mailer.FromName = my_from
Mailer.FromAddress = my_fromAddress
Mailer.AddRecipient my_to, my_toaddress
Mailer.Subject = my_subject
sBodyText = "The following is feedback from my web site." & vbcrlf & vbcrlf
sBodyText = sBodyText & "First Name: " & Request.Form("firstname") & vbCrLf
sBodyText = sBodyText & "Last Name: " & Request.Form("lastname") & vbCrLf
sBodyText = sBodyText & "Company: " & Request.Form("company") & vbCrLf
sBodyText = sBodyText & "E-Mail Address: " & Request.Form("email") sBodyText = sBodyText & vbCrLf & Chr(13) & Chr(10) & Chr(13) & Chr(10)
sBodyText = sBodyText & "" & Request.Form("feedback") & vbCrLf
sBodyText = sBodyText & "" & Request.Form("comment") & vbCrLf
Mailer.BodyText = sBodyText If Mailer.SendMail then Msg = "Thank you for your enquiry.<br> A member of staff will contact you shortly." Else MSG = "mail was not sent successfully<br> MSG = MS G& mailer.response & "<br>" End If response.write MSG %>

Understanding the Code

The first section of code should be looking quite familiar by now, this is calling the information that we inserted on the form.asp page about where the mail goes to, who it is from etc. Can you see the request statements? They are the ones set out like this request("mail-fromName"), look familiar? they should. These are the names we gave to our hidden fields on the form.asp page, and they are asking for the value that those hidden fields supplied.

my_from=request("mail-fromName")
my_fromAddress=request("mail-fromaddress")
my_to=request("mail-toName")
my_toAddress=request("mail-toaddress")
my_subject=request("mail-subject")
my_relay=request("mail-relay")

Lets look at the next section of code:

Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = my_relay
Mailer.FromName = my_from 
Mailer.FromAddress = my_fromAddress 
Mailer.AddRecipient my_to, my_toaddress 
Mailer.Subject = my_subject 

The first line of code Set Mailer = Server.CreateObject("SMTPsvg.Mailer") is creating an instance of the SMTP out going mail object, this will allow our form data to be sent on to the client.

Server.CreateObject
is the command or instruction ("SMTPsvg.Mailer") is the object that will be created.

Retrieving the information the viewer inserted:

sBodyText = "The following is feedback from my web site."
sBodyText = sBodyText & vbcrlf & Chr(13) & Chr(10) & Chr(13) & Chr(10)
sBodyText = sBodyText & "First Name: " & request.form("firstname") & vbCrLf
sBodyText = sBodyText & "Last Name: " & request.form("lastname") & vbCrLf
sBodyText = sBodyText & "Company: " & request.form("company") & vbCrLf
sBodyText = sBodyText & "E-mail Address: " & request.form("email") 
sBodyText = sBodyText & vbCrLf & Chr(13) & Chr(10) & Chr(13) & Chr(10)
sBodyText = sBodyText & "" & request.form("feedback") & vbCrLf
sBodyText = sBodyText & "" & request.form("comment") & vbCrLf 

A closer look at the code above, using the firstname string as an example:

sBodyText = sBodyText & "First Name: " & Request.Form("firstname") & vbCrLf 
  1. Firstly it is declaring that the information to follow is text that will sit in the body of the email.

  2. & "First Name: " will be the first text shown on this line, use this to create a title or header for the following information.

  3. & Request.Form("firstname") is saying any information entered into the form element called firstname will be inserted here.

  4. & vbCrLf ends that line of text.

  5. & Chr(13) & Chr(10) this section of code does the same job as the <br> tag, you will notice that on occasions the code above has this repeated. Two & Chr(13) & Chr(10) straight after each other, this will give us a clear line after this declaration, breaking the returned data into sections.

Adding a Section Title

sBodyText = sBodyText & "" & Request.Form("feedback") & vbCrLf 

On the line of code above (our seventh hidden field) you will notice that the line title is blank, this is because we do not need any information here. This will be a section header and it will take its value from the value we gave it on the form.asp page, when the form is submitted.

If Mailer.SendMail then
  	MSG = "Thank you for your enquiry.<br> A member of staff will contact you shortly." 
Else
	MSG = "mail was not sent successfully<br>"
	MSG = MSG& mailer.response & "<br>"
End If

response.write MSG

The response page will let the user know what has happened to the information they supplied. Iit does this by displaying one of two preset messages on the page using the response.write statement. If the mail is sent successfully it will display the thank you message, should the mail fail to be sent it will display the mail was not sent message. Both of these messages can be customized as you wish.

The Returned Data

The following is feedback from my web site.

First Name: JoJo
Last Name: Caine
Company: Webade
Email Address: jojo@webade.co.uk


:: Feedback on the web site ::
I like your web site, I think it has a
good use of colour. I would like to
see the text a little bit bigger though!

The data from the form & response pages we have just made would return the data as above. You can see what I was driving at in making sections of returned data to keep the information ordered, you can make as many blocks of information as you wish using this method.

Well that's it! you can now make your own ASP data collection forms and to get you on your way you can download a starting point that consists of the pages we have just made.

That completes the tutorial.

The Download(s)

Download a data collection form starting point from here.

::This page last modified 8/13/2013 at 03:37::

Copyright © 2001-2024 DreamweaverFAQ.com All Rights Reserved.
All brands, trademarks, tutorials, extensions, code, and articles are the property of their respective owners.
A production of Site Drive Inc.
Legal Notice | Privacy Policy | Disclaimer & Notice