<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Design Blog &#124; ModernBlue.com &#187; Code</title>
	<atom:link href="http://www.modernblue.com/web-design-blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.modernblue.com/web-design-blog</link>
	<description>Web and Graphics Studio</description>
	<lastBuildDate>Tue, 21 Jun 2011 07:34:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Used Car Dealership Project</title>
		<link>http://www.modernblue.com/web-design-blog/used-car-dealership-project/</link>
		<comments>http://www.modernblue.com/web-design-blog/used-car-dealership-project/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 06:57:45 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Corporate News]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[cars]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.modernblue.com/web-design-blog/?p=67</guid>
		<description><![CDATA[About 6 months ago, me and my parter Mike Annable launched undertook a new project. It is without argument that the auto industry is in dire circumstances. Many argue that causes have to do with leaders not doing enough to &#8230; <a href="http://www.modernblue.com/web-design-blog/used-car-dealership-project/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>About 6 months ago, me and my parter Mike Annable launched undertook a new project. It is without argument that the auto industry is in dire circumstances. Many argue that causes have to do with leaders not doing enough to provide for a green future. Although that may be true, there is a major problem with car dealerships across the country: they are way behind in optimizing their websites to achieve any exposure.</p>
<p>Knowing this, we undertook to create a software solution with certain goals in mind. For one, we wanted to help out smaller dealerships, who may not have the money or know-how of ranking their sites on major search engines. Secondly, we wanted to create a new standard of web site optimization across the car industry. We found a market that was in need of a solution. A market that has been overlooked.</p>
<p>So, I personally took on task of creating a system that could scale as big as our dream. A system that would ensure dealerships exposure on the web, with a management system that would only require little or no training. About 2 weeks ago, I finished the project, and we launched our first website in a target city in Florida. The site lists all the dealers with <a href="http://lakeland.used-cars-fl.com">Used Cars in Lakeland Florida</a>. The site itself provides a really simple experience for the car buyer. They can easily view the dealers in that area, view inventory and specials, and easily get in contact with the various dealerships. We now also have <a href="http://orlando.used-cars-fl.com">used cars in orlando florida</a>. <a href="http://www.buyusedcarsca.com">used cars in California</a>, and <a href="http://www.used-cars-utah.com">used cars in Utah</a>.</p>
<p>Our hope is that we can start partnering with others to bring these websites to other cities across the nation. We are open for discussion with dealerships and individuals who may be interested in pursuing this opportunity with us.</p>
<p><a href="http://www.used-cars-lakeland.com"><img class="aligncenter size-full wp-image-68" title="Used Cars Lakeland" src="http://www.modernblue.com/web-design-blog/wp-content/uploads/2009/01/gal-ucl.jpg" alt="" width="500" height="252" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.modernblue.com/web-design-blog/used-car-dealership-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress tips and the functions file</title>
		<link>http://www.modernblue.com/web-design-blog/wordpress-tips-and-the-functions-file/</link>
		<comments>http://www.modernblue.com/web-design-blog/wordpress-tips-and-the-functions-file/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 17:16:20 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.modernblue.com/web-design-blog/?p=61</guid>
		<description><![CDATA[I think it&#8217;s time I focus a bit on WordPress, a terrific blogging platform. It&#8217;s what I use for all of my clients&#8217; sites because of it&#8217;s compatibility, flexibility, and nice admin. I have a lot of experience creating custom &#8230; <a href="http://www.modernblue.com/web-design-blog/wordpress-tips-and-the-functions-file/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I think it&#8217;s time I focus a bit on <a href="http://www.wordpress.org">WordPress</a>, a terrific blogging platform. It&#8217;s what I use for all of my clients&#8217; sites because of it&#8217;s compatibility, flexibility, and nice admin. I have a lot of experience creating custom themes for WordPress. This is actually pretty easy. When I recently designed <a href="http://5ones.com">5ones.com</a> , one thing we really wanted was to show recent posts from each category. In the industries 5ones covers, media-rich content is very important. So, we wanted to take these excerpts one step further however, and extract the first image of a post, and convert it to a cropped thumbnail to keep things uniform. I am very pleased with the result.</p>
<p><strong>A word on WordPress Themes:</strong><br />
One very important file when creating a WordPress theme, is the &#8220;functions.php&#8221; file. This works like the plugin section in WordPress. Basically, when your template is loaded, so are these functions. It&#8217;s a great way to create specific functions you can use in your template files, without having to create a plugin for each one. And sense the &#8220;functions.php&#8221; file is only connected to that specific template, you can choose a different template, and those functions will no longer be loaded.</p>
<p><strong>Ok, so how did you do it?</strong><br />
The first step was to show the post title as a link, the author, and then a small except WITHOUT an image. If the author put an image at the top of their post, I didn&#8217;t want this to show up. So, in my index.php file, which acts as the home page, I put in this code:</p>
<p><code><br />
&lt;?php<br />
//get the latest 3 posts for surfing<br />
query_posts('category_name=Surfing&amp;showposts=3');<br />
while (have_posts()) :<br />
the_post();<br />
//execute the output function<br />
show_post($post);<br />
endwhile;<br />
?&gt;</code></p>
<p>WordPress has a lot of functions built in. So I used their &#8220;query_posts&#8221; function to get the latest 3 posts in the category &#8220;Surfing&#8221; (I repeated this later on for Skating and Snow). Then, in the famous WordPress &#8220;while loop&#8221;, I execute the function &#8220;show_post($post)&#8221;. The &#8220;$post&#8221; variable comes again from wordpress, which is actually a post object, containing all the post info (ie content, author, date, permalink, etc&#8230;). So, then in my &#8220;functions.php&#8221; file, I have my &#8220;show_post()&#8221; function:</p>
<p><code><br />
//show the post<br />
function show_post($post) {<br />
echo "&lt;div class=\"post\"&gt;\n";<br />
echo "&lt;div class=\"img\"&gt;\n";<br />
//checks for image<br />
getImage($post-&gt;post_content);<br />
echo "&lt;/div&gt;\n";<br />
echo "&lt;div class=\"body\"&gt;\n";<br />
echo "\t&lt;h3&gt;&lt;a href=\"".$post-&gt;guid."\"&gt;".$post-&gt;post_title."&lt;/a&gt; - &lt;small&gt;By ".author($post-&gt;post_author)."&lt;/small&gt;&lt;/h3&gt;\n";<br />
echo "\t&lt;p&gt;".summary($post-&gt;post_content)."&lt;a href=\"".$post-&gt;guid."\"&gt;Read Full&lt;/a&gt;&lt;/p&gt;";<br />
echo "&lt;/div&gt;\n";<br />
echo "&lt;div class=\"date\"&gt;".dateFormat($post-&gt;post_date)."&lt;br /&gt;&lt;br /&gt;";<br />
echo "&lt;br /&gt;&lt;a href=\"".$post-&gt;guid."#respond\"&gt;(".$post-&gt;comment_count.") Comments&lt;/a&gt;&lt;/div&gt;\n";<br />
echo "&lt;/div&gt;\n";<br />
}<br />
</code></p>
<p>For the most part, I didn&#8217;t have to do anything new here. I basically used WordPress&#8217;s $post object to access specific information I wanted, and put then put it exactly where I wanted it in my XHTML.  There are only 4 functions being called that I had to create.</p>
<p>The being called is &#8220;getImage()&#8221;. This is the function I use to display the small thumbnail next to the post. Here is the function:</p>
<p><code><br />
//checks to see if there is an image in the post<br />
// if yes, it displays the image in a box<br />
function getImage ($hay) {<br />
$path = explode("&lt;img",$hay);<br />
if(sizeof($path) &gt; 1) {<br />
$src = explode("alt",$path[1]);<br />
$file = explode("src=",$src[0]);<br />
$url = str_replace('"','',$file[1]);<br />
$url = str_replace("'",' ',$url);<br />
$link = explode("/uploads/",$url);<br />
echo "&lt;img src=\"http://5ones.com/dev/wp-content/themes/5ones-v2/gen_thumb.php?x=62&amp;y=39&amp;src=".$link[1]."\" /&gt;\n";<br />
}<br />
}<br />
</code><br />
I am not saying this is the easiest, nor best way to do this part. However, it works great for my purposes. Anyways, here is what is going on. I use the variable $hay to hold the actual post content (which I passed in my show_post() function. I then used the <a href="http://www.php.net/explode">explode</a> function to separate any possible image tags in a post. Then, I am able to check the size of the array created, and if it&#8217;s large than zero, I know an image exists and continue on with the function. All I am trying to do, is get the path for the image in the post. So, I do a series of explodes and string replaces to isolate the path. Then, I pass the image path I finally get to my image resizing script (maybe I will share later), that crops the image and outputs it. Beauty.</p>
<p>The next function I use is &#8220;summary()&#8221; which takes the content, strips out html tags and image tags, truncates the length, and then returns the result. It looks like this:</p>
<p><code><br />
//returns a summary of the content and strips html tags<br />
function summary($copy) {<br />
$new = strip_tags($copy);<br />
ereg_replace("&lt;img[^&gt;]*&gt;", "", $new);<br />
$new = substr($new,0,200);<br />
$new .= "...";<br />
return $new;<br />
}<br />
</code></p>
<p>The last function I use returns the name of the author. Since the post only gives the id of the author, I do a simple DB query to get the authors&#8217; name:<br />
<code><br />
//returns the name of the author based on id<br />
function author($id) {<br />
$sql = "SELECT display_name FROM wp_users<br />
WHERE ID = '$id'";<br />
$q = mysql_query($sql);<br />
$r = mysql_fetch_array($q);<br />
return $r["display_name"];<br />
}<br />
</code><br />
These are the functions I use to create the home page you see on 5ones. Hopefully these functions can be beneficial to someone trying to create the same thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.modernblue.com/web-design-blog/wordpress-tips-and-the-functions-file/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Using Spry to Show Clean Error Messages</title>
		<link>http://www.modernblue.com/web-design-blog/using-spry-to-show-clean-error-messages/</link>
		<comments>http://www.modernblue.com/web-design-blog/using-spry-to-show-clean-error-messages/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 14:27:35 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[spry]]></category>

		<guid isPermaLink="false">http://www.modernblue.com/web-design-blog/?p=59</guid>
		<description><![CDATA[Today&#8217;s post is pretty simple. For those of you who would like to jump ahead, here is your link. Website error messages are always something that seem a bit clunky on most websites. They either show up as crappy looking &#8230; <a href="http://www.modernblue.com/web-design-blog/using-spry-to-show-clean-error-messages/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s post is pretty simple. For those of you who would like to jump ahead, here is <a href="http://www.modernblue.com/web-design-blog/case-studies/spry/msg/success.php">your link</a>. Website error messages are always something that seem a bit clunky on most websites. They either show up as crappy looking alert boxes, or mess up the pages design somehow. I would like to show you an easy way to display nice-looking error messages, using the <a href="http://labs.adobe.com/technologies/spry/samples/effects/fade_sample.html">&#8220;fade&#8221; effect</a> from you guest it, <a href="http://labs.adobe.com/technologies/spry/">Spry</a>. This is really simple to do, and in my example I show how you can create a function in PHP, as well as use javascript to display your messages.</p>
<p><strong>Fade via Javascript:<br />
</strong>Calling a spry effect is very simple. You first need to create a variable which sets up the fade parameters, and then call that variable again and start the fade. It goes a little something like this:</p>
<p><code><br />
var error_fade = new Spry.Effect.Highlight('errorBox', {duration: '1500', from:'#ffffff', to:'#ff3300', toggle: true});<br />
error_fade.start();<br />
</code></p>
<p>What&#8217;s going on here? In english it would read like this. Create the variable &#8220;error_fade&#8221; and attach a spry effect to it. Make the effect effect the div on my page with the id &#8220;errorBox&#8221;. Fade the effect for 1500 milliseconds, starting with the color white and fading to a reddish color. The great thing about setting it up in the variable &#8220;error_fade&#8221; is that I can call it at anytime. I could set up another variable called &#8220;success_fade&#8221; and give it a different set of parameters. Actually, I end up doing this with php.</p>
<p><strong>Fade via php function:<br />
</strong>Obviously the php isn&#8217;t going to do the fade. All it will do is call the fade via a function. The great thing about this, is you could put this function in a class and use it to display any type of message, error or not throughout your application. On an app I am currently working on, this function is in my main file of functions used throughout the site. When I want to show a fade, for example on a successful form submission, I will call it. To see an example, submit the form in <a href="http://www.modernblue.com/web-design-blog/case-studies/spry/msg/success.php">my example</a>. You can put anything for your email, I am not validating it&#8217;s structure. Here is the function that is being used:</p>
<p><code><br />
function success($message,$time,$from, $to) {<br />
echo '&lt;div class="success" id="suc"&gt;'."\n";<br />
echo "&lt;p&gt;$message&lt;/p&gt;";<br />
echo '&lt;/div&gt;'."\n".'<br />
&lt;script type="text/javascript"&gt;<br />
var sts_fade = new Spry.Effect.Highlight("suc", {duration: "'.$time.'", from:"'.$from.'", to:"'.$to.'"});<br />
sts_fade.start();<br />
&lt;/script&gt;';<br />
}<br />
</code></p>
<p>Then you can call the function like this, and set all the parameters you want. For the success box on my example:</p>
<p><code><br />
$message = "&lt;h2&gt;Your message was sent!&lt;/h2&gt;&lt;p&gt;A representative will contact you as soon as possible!&lt;/p&gt;";<br />
success($message,'1500','#f5fa73','#cfebf7');<br />
</code></p>
<p>Using this function is very easy. I can call it at anytime, reusing the code for you recyclers out there, and being able to set the parameters however I would like. One function to handle all of my needs. Well, I hope you enjoy. If you have any problems adding it to your site, let me know. Let&#8217;s all make error messages friendlier, and better looking.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.modernblue.com/web-design-blog/using-spry-to-show-clean-error-messages/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>UPS Rates and Services API and Spry</title>
		<link>http://www.modernblue.com/web-design-blog/ups-rates-and-services-api-and-spry/</link>
		<comments>http://www.modernblue.com/web-design-blog/ups-rates-and-services-api-and-spry/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 13:16:35 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[spry]]></category>

		<guid isPermaLink="false">http://www.modernblue.com/web-design-blog/?p=58</guid>
		<description><![CDATA[Two days in a row. This is the best I have done in a while. I&#8217;m not sure what you will be most excited about today, whether it&#8217;s going to be for showing you how to use the UPS Rates &#8230; <a href="http://www.modernblue.com/web-design-blog/ups-rates-and-services-api-and-spry/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Two days in a row. This is the best I have done in a while. I&#8217;m not sure what you will be most excited about today, whether it&#8217;s going to be for showing you how to use the UPS Rates and Services API, or whether it&#8217;s using Spry to do it in real-time, or whether it&#8217;s the fact that my stuff makes you smile. Anyways, here is a link to a working sample of my <a href="http://www.modernblue.com/web-design-blog/case-studies/spry/ups/ship.html">Spry&#8217;d UPS Rates and Service API</a> form.</p>
<p><strong>The Problem:<br />
</strong>Too often checkout pages are too many steps and too long. Without me getting into it personally, I will give you a tip that will make your online stores more successful: Limit the checkout process to one page. Recently I had a client I built a custom shopping cart for. She didn&#8217;t need a robust system like Os Commerce or Zen Cart, so I built one in from scratch. When I came to building the checkout page, I kept asking myself &#8220;how can I make this easier for the front-end user&#8221;. After fitting everything into one page, and realizing I could use Spry to get shipping rates RIGHT after they put in their zip, I knew I was on my way to land a home run.</p>
<p><strong>The Solution:<br />
</strong>I guess there are two parts to this one. The first is how the freak do I use the UPS API of which they supply close to 70 pages of documentation? Well, first off read <a href="http://www.marksanborn.net/php/calculating-ups-shipping-rate-with-php/">this article</a> and download his code. I am not going to take credit in creating the function I use. He also takes you through what you need to do on the UPS website, how to configure his script, and how to use his function.</p>
<p>Mark&#8217;s script however, simply returns one rate. I wanted to create a way to display several rate options to my customer. You can see what I did on the <a href="http://www.modernblue.com/web-design-blog/case-studies/spry/ups/ship.html">example page</a>, below the form. So basically, I create an array with all of the  shipping options I want to display. Then I run a foreach statement, to read the array one by one and complete Mark&#8217;s function. Each one returns a result that I can then display back to the user. However, I added in a radio button for each one, as well as the name of the shipping method next to it with the returned price from the API.</p>
<p>The next step was to integrate it using Spry&#8217;s updateContent utility. Like I showed yesterday this is fairly simple. I use the &#8220;onblur&#8221; handler again for their zip code, and place the zip code as the second input box to give it some time to load. Here is the &#8220;checkShipping&#8221; function that is called:<br />
<code><br />
var checkShipping = function () {<br />
//get their zip from the ship_zip box<br />
var zip = document.shipping.ship_zip.value;<br />
document.getElementById("Rates").innerHTML="<strong style="color:red">Loading shipping options for Zip: " + zip + " ...</strong>";<br />
//only check the zip if it's more than 4 characters<br />
if(zip.length &gt; 4) {<br />
window.Spry.Utils.updateContent('Rates', 'getUps.php?zip=' + zip);<br />
}<br />
}<br />
</code><br />
It&#8217;s pretty simple. Basically I get the value of their zip, and then display some temporary data into my loading div, to alert the user that something is coming. Then I check that their zip is more than 4 characters, and then I use my getUps.php script to retrieve the info. I pass that same zip variable that is being used to show the customer I am retrieving info for that zip, into the php script and then into the function to be used in calculating shipments.</p>
<p>As always, I am sure you are already thinking of ways to extend this further. Better validation maybe? Using sessions to remember their selection and display it if they have to come back and edit the page again? Maybe putting an awesome animated gif of a flying eagle above the form? Hopefully this will help you on your journey, and you won&#8217;t be forced to use OS Commerce or Zen Cart just because they have a plugin that does this same thing.</p>
<p>Stay tuned tomorrow as I discuss how Spry can be used to display very nice alert messages. I might even wrap it up into a PHP class.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.modernblue.com/web-design-blog/ups-rates-and-services-api-and-spry/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Spry week intro and login example</title>
		<link>http://www.modernblue.com/web-design-blog/spry-week-intro-and-login-example/</link>
		<comments>http://www.modernblue.com/web-design-blog/spry-week-intro-and-login-example/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 16:40:02 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[spry]]></category>

		<guid isPermaLink="false">http://www.modernblue.com/web-design-blog/?p=57</guid>
		<description><![CDATA[I have committed many times to be more active in being a more active &#8220;blogger&#8221;. Some of my posts have been very successful, like &#8220;Fighting Spam With CSS&#8221; and &#8220;Tweak that Gamma&#8220;. Also, with being featured on Elance.com recently about &#8230; <a href="http://www.modernblue.com/web-design-blog/spry-week-intro-and-login-example/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have committed many times to be more active in being a more active &#8220;blogger&#8221;. Some of my posts have been very successful, like &#8220;<a href="http://www.modernbluedesign.com/web-design-blog/fighting-spam-with-css/">Fighting Spam With CSS</a>&#8221; and &#8220;<a href="http://www.modernbluedesign.com/web-design-blog/tweak-that-gamma/">Tweak that Gamma</a>&#8220;.  Also, with being featured on Elance.com recently about <a href="http://www.modernblue.com/web-design-blog/patrick-bennett-featured-on-elance-for-wordpress-tips/">wordpress blogs</a>, I have decided to recommit. My new approach, and hopefully this works, is choosing a topic to cover each week. Each day (M-F) I will demonstrate a small example within that topic, that will hopefully be beneficial to you.</p>
<p><strong>This week is <a href="http://labs.adobe.com/technologies/spry/">Spry</a>.<br />
</strong>You can follow the link to learn more about it, but basically it&#8217;s another javascript library created by Adobe. Some things I like about it, is 1. It&#8217;s completely free (no donations requested from a large company like Adobe); 2. It&#8217;s easy to impliment and use; 3. Their examples are really good and cover a wide variety of topics.</p>
<p>Recently, with a large project I have been working on, Spry has been very important in helping me use AJAX to enhance functionality and user-interaction. Recently, I created the registration pages for this same project. I wanted to make it as simple as possible. So for today, I am going to cover how to use <a href="http://labs.adobe.com/technologies/spry/samples/utils/update_content.html">Spry&#8217;s updateContent utility</a>, to help me out with user login id&#8217;s.</p>
<p><strong>The problem:</strong><br />
Like many sites where a login id is required, it can be frustrating once thousands of users are populating the database, to find a unique login id that hasn&#8217;t been taken. I am sure you can share my frustration with trying to create a unique account in Xbox live or yahoo chat. On many websites, the user types in their desire username, selects and confirms their password, and then clicks submit. The form then passes the information to a server-side script which checks the database to see if it&#8217;s unique, and then either sends back the form with a very disappointing error, or sends a very gratifying page that says &#8220;sexyMomma2007&#8243; is available.  When the user id is not unique, it can be frustrating. However, when a user has to continually try new ones and resubmit the form, then wait for a response from the server, that only builds on the frustration&#8230; until finally the user snaps and chooses a login that makes no sense and forever will be dissapointing.</p>
<p><strong>The solution:<br />
</strong>With this in mind, I thought to myself &#8220;Is there anything that can be done. Is there any hope&#8221;. Then I remembered the new buzzword &#8220;Ajax&#8221;, and realized, yes&#8230; There is a solution. Why don&#8217;t you <a href="http://www.modernblue.com/web-design-blog/case-studies/spry/user/form.html">take a look</a> (I hate it when tutorials only put the finished link at the bottom&#8230; if you know enough about how it works just by looking at the code, then copy and paste the freaking code and use it in your own site. If you need more love, keep reading).</p>
<p>The instructions are there, but basically put in a username in the &#8220;Create login&#8221; box, and then click on the password box. You will then see a response of whether it&#8217;s ok or not. Also, you will notice if the username is taken, the &#8220;register&#8221; button becomes disabled, as another reminder they should try another name to continue. You will be happy to know that only 3 usernames are taken on this example: admin (me), modernblue (me), ferris-bueller (me, I wish). So, get some gratification by typing in your favorite user names and obtaining the best response you&#8217;ve had in weeks.</p>
<p><strong>Where does spry come in?</strong><br />
First off, I include the spry script (spryData.js) between the &lt;head&gt; tags. Then, I call sprys &#8220;updateContent&#8221; function using only one line of code. Let&#8217;s look at my full function &#8212; read the comments:</p>
<p><code><br />
var checkLogin = function () {<br />
//get the value of their login name<br />
var login = document.user.login.value;<br />
//check the db to see if its available<br />
window.Spry.Utils.updateContent('response', 'checkLogin.php?login=' + login);<br />
}<br />
</code></p>
<p>The &#8220;checkLogin&#8221; function is the function I call with the &#8220;onblur&#8221; handler on my input text field. &#8220;onblur&#8221; is triggered when your cursor first enters the field, and then is clicked somewhere else (focus-&gt;blur).  So simply, I get their awesome login name, then via spry, I load my &#8220;checkLogin.php&#8221; script (which you can see below the example) to see if a username is taken. I then pass the variable into my php script, in this case check an array of usernames (I know many of you are rolling your eyes bc I am using an array, rather than a MySQL &#8220;SELECT&#8221; statement), and then display the response based on it&#8217;s availability. I then call the valid login function, which then checks to see whether the response was available, or taken. Let&#8217;s take a look at this function:</p>
<p><code><br />
//check to see if the username is unique<br />
var validLogin = function () {<br />
//get the class of the response span<br />
var answer = document.getElementById('response').className;<br />
if(answer != "success") {<br />
//change the background of the text box to red<br />
document.getElementById('login').className = 'sorryBg';<br />
//disable the register button<br />
document.user.register.disabled=true;<br />
} else {<br />
//change the background of the text box to green<br />
document.getElementById('login').className = 'successBg';<br />
//enable the register button<br />
document.user.register.disabled=false;<br />
}<br />
}</code></p>
<p>Simply, this login checks the class name of the returned span I sent from my &#8220;checkLogin.php&#8221; script. If the class is not &#8220;success&#8221;, I assign the input box the class of &#8220;sorryBg&#8221;, which makes the background color of the input box red (international error color), and I also disable the register button for people who don&#8217;t notice the obvious red box and red error letters. If the class is &#8220;success&#8221;, then I assign the input box the class of &#8220;successBg&#8221;, which makes the background green, as well as enable the register button.</p>
<p><strong>Any other ideas?<br />
</strong>Of course with this example I am only touching the surface of using spry within forms. I would suggest using a javascript function to make sure the username is the required length, and has the required characters of for your application. Also, don&#8217;t forget everything you do user-side, should be re-validated server-side. I am sure some are rolling their eyes, but when you are doing a site for a client whose users are un-trusting (won&#8217;t have javascript enabled) you need to accommodate to them. For that same reason you should also accommodate to users who would always have javascript enabled, and especially want to have a quick and easy process. I would recommend looking at <a href="http://labs.adobe.com/technologies/spry/samples/validationwidgets/TextfieldValidationSample.html">this page</a> as well, to learn about Sprys very cool form validation methods.</p>
<p><strong>What&#8217;s up for tomorrow?<br />
</strong>I am going to share another example of using Spry.Utils.updateContent to show your users shipping rates based on their zip. I am guessing some of you are already starting to think of how this could be handled. I am also going to include a really simple function for connecting to the UPS api, to get immediate quotes.</p>
<p>If any of you need a little more help explanation, let me know via comments. I will try and help the best I can. And please, remember I left out a lot of things for brevity sake, so please keep comments about validation, compliance, security and politics to yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.modernblue.com/web-design-blog/spry-week-intro-and-login-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

