![]() |
|
|
Published: Saturday, May 15, 1999 By Christopher Miller Cookies Problem: Some folks have reported problems saving/reading cookies with this article's code examples. There is a "fix" or "workaround" that might work for you.... Read More... One of the best ways to make your visitors feel like they are part of an Online "community" and to add interactivity to your site, is to offer them a way to create custom homepages. Often called a "portal", this homepage will be your visitor's gateway to the internet and contain their favorite colors, links, email addresses, and much more. If you have a commerce site, You can take this concept a step further and add targeted marketing information based on a survey you have your visitors fill out. The possibilities are endless.
In this example, we will create this homepage by setting a series of cookies that contain the customized information. We will gather this information through a form that the visitor is sent to after clicking on an "edit" button. The working example of this code can be found at the following address. http://www.askasp.com/4guys/four_guys/article_one/my_homepage.asp Lets start by creating two pages, my_homepage.asp and edit.asp. The first page will be the page that is getting the customization, and the second page is where we collect the data. You need to then decide what information you want the user to be able to edit and customize. In this example, the user is able to edit the following items:
We then need to create a simple HTML form on the edit page to collect the values to be passed to the cookies (I am assuming you know how to do this already). To collect the data, simply write the contents of the form field to the cookie (For more information about cookies, read "Cookie Monster: Using Cookies in ASP", by Ian Stallings):
Response.Cookies("CookieName") = Request.Form("FieldName") There are two ways of collecting the data from the form, we can write each cookie individually (as show above), or we can use a for...each method:
For Each Item In Request.Form The for...each method will save you a lot of time and effort. Keep in mind however, the cookie name will correspond with the form input name which you will need to remember for the my_homepage file. Now that we have a method of collecting all of the values, we need to create the customized home page. Lets start by using the Option Explicit function. By using option explicit, you are forced to declare all of the variables you are going to use in your application. This is handy trick to avoid misspellings. We will then declare our variables:
Dim myName, myBGColor, myTableColor, myTextColor The next step is to check for cookies and set all of the values for the variables. You can use a default value if there is no cookie set.
IF Request.Cookies("cookieName") = "" THEN
IF request.Cookies("cookieBGColor") = "" THEN
IF Request.Cookies("cookieTableBGColor") = "" THEN
IF Request.Cookies("cookieTextColor") = "" THEN
IF Request.Cookies("cookieLinkColor") = "" THEN
IF Request.Cookies("cookieVLinkColor") = "" THEN You then need to set up the links to be clickable: myLinks = "<a href='" & Request.Cookies("cookieLinkOne") & "'>" & Request.Cookies("cookieLinkOne") & "</a><br>" I use a simple Response.Redirect to send the user to the edit.asp page if the edit button is clicked.
IF Request.Form("cmdEdit") = "Edit" THEN In the body of the page, you want to use the values you define earlier for the customization. Below is an example of what the body of the page looks like: <body bgcolor="<%Response.Write(myBGColor)%>" text="<%Response.Write(myTextColor)%>" link="<%Response.Write(myLinkColor)%>" vlink="<%Response.Write(myVLinkColor)%>"> To make the page a little more interactive, I have set up a Email form using the addresses set by the user in a drop-down menu for the To field. I used a simple CDONTS script to accomplish this:
IF Request.Form("cmdSend") = "Send" THEN
It is as simple at that. Keep in mind, the code and example I have provided have no error checking, so you will want to add your own handlers. You may also want to pass the values of the cookies into session variables to be used throughout the site, rather that just on the single page. Enjoy :o}
Cookies Problem: Some folks have reported problems saving/reading cookies with this article's code examples. There is a "fix" or "workaround" that might work for you.... Read More...
Attachments:
Christopher Miller
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||