Tech Musings

Friday, January 12, 2007

A Cookie Monster!

Oh, what a week. My desire to distribute a marketing E-mail to our school district regarding ETR's Spring Technology Workshops (2007) using Gammadyne Mailer has forced me into learning about things I think I would have rather have left in the shadows of Web development (Just kidding it was high time I learned more about cookie implementation and this gave me the opportunity to do just that).

After testing the HTML/text E-mail generated from Gammadyne, I quickly realized I wouldn't be able to send our standard enrollment registration page as the HTML fork because GroupWise client seemingly does not permit form processing in HTML E-mail. I would need to instead create a static HTML page with links to each class 's details page in our mass mailer. But, alas; a problem. We didn't have an enrollment button on the details page that would allow people to easily register for a class after clicking on it from the HTML E-mail. Instead, they would need to know (or figure out) that they would need to navigate to the main enrollment page to actually register for said class. Obviously, this wasn't acceptable from a usability perspective and would confuse the hell out of our staff and faculty.

To make a long story short (too late!!), I first attempted to address this problem by creating a form button on the details page that would pass back the class's schedule id to the enrollment page which would in turn check the corresponding checkbox in the dynamically generated class list on the enrollment page. It worked, but if a visitor then clicked on another class title, looked at the details, and decided to enroll, he/she would be returned to the main enrollment page and the first checkbox would no longer be checked, thereby confusing the visitor who was under the impression that he/she already had selected that class in the list. I tried using a neat little javascript cookie that saves form information (written by Nick Baker available at javascript.internet.com) to preserve the status of the checkboxes, but it didn't jive well with the pass back PHP function I wrote which seemed to take precedent and overwrite the cookie function.

Begrudgingly, I knew I needed to finally tackle a solution that would solve my problem; that being the development of a "shopping cart" cookie to track each and every class a visitor enrolls in while they browse individual class detail page(s), and then use this cookie to manage or "check" checkboxes on the enrollment form based on stored information from the cookie. I've been wanting to do this for a long time but knew it would take me many hours to develop this functionality because I haven't taken the time until now to thoroughly examine the world of client-side browser cookies. I've implemented code snippets that utilize cookies many times, but these scripts were written by others and I hadn't bothered to figure out how a javascript cookie actually works. I fooled around and after a bit of frustration posted a question in the javascript forum on webdeveloper.com related to how cookies work. As before, no response. I'm finally getting the picture that people contributing in these forums aren't really interested in explaining how things work conceptually. They're not educators like me but nuts-&-bolts coders (i.e. post your code and we'll tell you what's wrong with it but don't ask the "whys or hows" related to your issue because we really don't care about your understanding of the big picture).

I use the NOP Shopping Cart javascript when helping the El Cajon Valley High School students with their Virtual Enterprise projects, so this seemed to be the logical place to start. However, this would be my first crack at utilizing the code in a project of my own which would require me to analyze the code to understand how it actually works. It is a very well written, nifty script that I modified to fit my needs. However, I ran into a problem because of it is illegal to place a form inside of another form, so I posted ANOTHER question on webdeveloper.com asking for help. At least this time I got a few responses, but nothing substantial that helped me figure out what to do next.

I was trying to mix a javascript, client-side shopping cart cookie with server-side PHP code. Eventually, I got it to work but I couldn't figure out how to easily modify the shopping cart cookie if a user decided to just check the checkbox to enroll in a class on the main enrollment page without actually navigating to the class details page and clicking the "Enroll me!" form button.

After some thought I figured it would be best to look for a totally server-side solution that utilized a PHP shopping cart function. Luckily, I found it via hotscripts; it is called the Webforce Cart and it was the answer to my prayers! It is an excellent, free PHP shopping cart class that provided EXACTLY the type of functionality I needed! With the wfcart, I was able to easily add the functionality to add and delete items from the cookie as the user checks and unchecks the enrollment checkboxes (i.e. adds, modifies or deletes items from the cookie) on the main enrollment page, or if the users decides to click the form button to "enroll" or "remove [the class] from the list" on the individual details page for that workshop!

Check it out here!
http://edtech.guhsd.net/enroll.php

Needless to say I'm quite proud of getting this to finally work and admit it turned out to be worthwhile investment of time as I'm sure I'll utilize this type of functionality again in future applications I develop.