WebRef Update: Featured Article: Adding Features to Your ASP Site | WebReference

WebRef Update: Featured Article: Adding Features to Your ASP Site


Adding Features to Your ASP Site

During the last few years the number of Web sites has grown dramatically, as well as the level of quality demanded from these sites. To succeed today, it's not enough to place some content on a static site. You need to have more and more features to attract new visitors and make them return again and again. Some of these features are not directly related to increasing the interest of your visitors and the level of traffic. Sometimes they are even not visible to the user, but are nonetheless crucial to getting your site's quality to the top.

In this article, I will try to show you how to implement some of today's most popular site features in ASP. Let's start with working examples of three commonly used features: a feedback form, a "recommend to a friend" feature and a 404 error reporter. The main function in the implementation of these three features is sending email from the ASP script. There are no built-in capabilities to send email from ASP, but there are lots of free and commercial components enabling you to do this. In this article, I'll use the JMail component available for free from www.dimac.net. You may use any other component available on your host; it shouldn't be difficult to adapt these examples to work on your site.

Feedback form

One of the most important elements of a great site is the ability to satisfy user needs, and the easiest way to know what your users need and want is by getting their feedback. From my own experience, I know that simply displaying your contact information doesn't guarantee much feedback. There are a variety of reasons why people might not send you email even if they want to tell you something: they're not browsing your site from their own computer; they don't have their email software properly configured; an email message tends to require some formal things like greetings and more; they don't want to give you their email but still have something important to say... Having a feedback form solves most of these problems, enabling you to get more information from your users and build a better site.

Implementation of feedback form in ASP is quite easy:
1) create HTML form
2) get fields
3) send email.

So let's start by creating basic HTML form (formatting skipped):

<FORM METHOD="POST" ACTION="sendmail.asp"> Name:<INPUT TYPE="TEXT" NAME="fromname" SIZE="32"><BR> Email:<INPUT TYPE="TEXT" NAME="fromaddr" SIZE="32"><BR> Subject:<INPUT TYPE="TEXT" NAME="subject" SIZE="50"><BR> Message:<TEXTAREA NAME="body" COLS="40" ROWS="6"></TEXTAREA><BR> <INPUT TYPE="SUBMIT" VALUE="Send"><INPUT TYPE="RESET" VALUE="Clear"> </FORM>

And now we will get the fields from that form and send them to our email:

<% Set jmail=Server.CreateObject("jmail.smtpmail") jmail.ServerAddress="mail.company.com" jmail.AddRecipient "webmaster@company.com" jmail.Sender=Request.Form("fromaddr") jmail.SenderName=Request.Form("fromname") jmail.Subject=Request.Form("subject") jmail.Body=Request.Form("body") jmail.Execute %>

This is the simplest implementation of a feedback form. You may use it on your site as is. However, I would recommend customizing it to be more universal. You can make the form accept not only the name and email of the sender, subject and body, but also allow a choice of email address of the recipient (you) so you may use it from various parts of your site or on various sites. In this manner, you will be able to add a select box (dropdown) to your HTML form, so your visitor may choose the theme of the message and send the message to a specific responsible person. To be even more universal, you may want the script to redirect to a specific "thank you" page after processing.

Now our HTML form will look something like this:

<FORM METHOD="POST" ACTION="sendmail.asp"> <INPUT TYPE="HIDDEN" NAME="redir" VALUE="/index.html"> Name:<INPUT TYPE="TEXT" NAME="fromname" SIZE="32"><BR> Email:<INPUT TYPE="TEXT" NAME="fromaddr" SIZE="32"><BR> Theme: <SELECT NAME="toaddr" SIZE="1"> <OPTION VALUE="sales@company.com">Product sales <OPTION VALUE="webmaster@company.com">Bugs, dead links, etc. </SELECT><BR> Subject:<INPUT TYPE="TEXT" NAME="subject" SIZE="50"><BR> Message:<TEXTAREA NAME="body" COLS="40" ROWS="6"></TEXTAREA><BR> <INPUT TYPE="SUBMIT" VALUE="Send"><INPUT TYPE="RESET" VALUE="Clear"> </FORM>

And the processing script:

<% Set jmail=Server.CreateObject("jmail.smtpmail") jmail.ServerAddress="mail.company.com" jmail.AddRecipient Request.Form("toaddr") jmail.Sender=Request.Form("fromaddr") jmail.SenderName=Request.Form("fromname") jmail.Subject=Request.Form("subject") jmail.Body=Request.Form("body") jmail.Execute

Response.Redirect Request.Form("redir") %>

Note: Response.Redirect should be used before any content has been passed to the client.

Next: Recommend to a Friend, 404 Error Reporter, Conclusion

This article originally appeared in the January 27, 2000 edition of the WebReference Update Newsletter.

http://www.internet.com

Comments are welcome
Written by Alan Mendelevich and

Revised: May 10, 2000

URL: http://webreference.com/new/addasp.html