<?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>CSSKarma &#187; forms</title>
	<atom:link href="http://www.csskarma.com/blog/tag/forms/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.csskarma.com/blog</link>
	<description>display your &#60;style&#62;</description>
	<lastBuildDate>Sun, 11 Jul 2010 04:57:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Sliding Labels v2 &#8211; Patch</title>
		<link>http://www.csskarma.com/blog/sliding-labels-v2/</link>
		<comments>http://www.csskarma.com/blog/sliding-labels-v2/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 15:51:37 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.csskarma.com/blog/?p=772</guid>
		<description><![CDATA[window.location = "http://www.csskarma.com/blog/sliding-labels-plugin/" Please use version 3 of sliding labels with updated options and bug fixes at: http://www.csskarma.com/blog/sliding-labels-plugin/ Last week I wrote an article about sliding form labels that got quite a bit of attention. Many of the commenters brought up a couple good points/bug in the Sliding Label code that I wanted to address [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.csskarma.com/blog/wp-content/uploads/banner_slidinglabel2.jpg" alt="banner"></p>
<p><script>
window.location = "http://www.csskarma.com/blog/sliding-labels-plugin/"
</script></p>
<div style="background: #fffcdB; padding: 10px; margin: 0 0 30px; border: 1px solid #bebf6b; clear: both; font-size: 16px;">Please use <strong>version 3</strong> of sliding labels with updated options and bug fixes at: <a href="http://www.csskarma.com/blog/sliding-labels-plugin/">http://www.csskarma.com/blog/sliding-labels-plugin/</a></div>
<p>Last week I wrote an article about sliding form labels that got quite a bit of attention. Many of the commenters brought up a couple good points/bug in the Sliding Label code that I wanted to address and provide a patch for:</p>
<ul>
<li>The sliding label was barfing out in <strong>Safari</strong> when auto-fill was active</li>
<li>The default scripting didn&#8217;t work on <strong>textareas</strong></li>
</ul>
<p>I sat down yesterday and wrote a patch/new version of sliding labels which I think addresses these two problems.</p>
<p class="demo"><a href="http://www.csskarma.com/lab/plugin_slidinglabels/">View the Demo</a></p>
<h3>The new jQuery</h3>
<pre><code>$(function(){
$('form#info .slider label').each(function(){
	var labelColor = '#999';
	var restingPosition = '5px';

	<span>// style the label with JS for progressive enhancement</span>
	$(this).css({
		'color' : labelColor,
		 	'position' : 'absolute',
	 		'top' : '6px',
			'left' : restingPosition,
			'display' : 'inline',
    		        'z-index' : '99'
	});

	var inputval = $(this).next().val();

	<span>// grab the label width, then add 5 pixels to it</span>
	var labelwidth = $(this).width();
	var labelmove = labelwidth + 5 +'px';

	<span>// onload, check if a field is filled out, if so, move the label out of the way</span>
	if(inputval !== ''){
		$(this).stop().animate({ 'left':'-'+labelmove }, 1);
	}    	

	<span>// if the input is empty on focus move the label to the left
	// if it's empty on blur, move it back</span>
	$('input, textarea').focus(function(){
		var label = $(this).prev('label');
		var width = $(label).width();
		var adjust = width + 5 + 'px';
		var value = $(this).val();

		if(value == ''){
			label.stop().animate({ 'left':'-'+adjust }, 'fast');
		} else {
			label.css({ 'left':'-'+adjust });
		}
	}).blur(function(){
		var label = $(this).prev('label');
		var value = $(this).val();

		if(value == ''){
			label.stop().animate({ 'left':restingPosition }, 'fast');
		}	

	});
}); <span>// End "each" statement</span>
}); <span>// End loaded jQuery</span></code></pre>
<h3>Textarea HTML</h3>
<p>The HTML for the textarea follows the same convention as the rest of the inputs, in only needing a wrapping element.</p>
<pre><code>&lt;div id="comment-wrap"  class="slider"&gt;
    &lt;label for="comment"&gt;Comment&lt;/label&gt;
    &lt;textarea cols="53" rows="10" id="comment"&gt;&lt;/textarea&gt;
&lt;/div&gt;&lt;!--/#comment-wrap--&gt;</code></pre>
<p>There are no major changes to the plugin, just a few tweaks. If you find anymore bug, please let me know.</p>
<p class="demo"><a href="http://www.csskarma.com/lab/plugin_slidinglabels/">View the Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csskarma.com/blog/sliding-labels-v2/feed/</wfw:commentRss>
		<slash:comments>115</slash:comments>
		</item>
		<item>
		<title>Form Design with Sliding Labels</title>
		<link>http://www.csskarma.com/blog/sliding-labels/</link>
		<comments>http://www.csskarma.com/blog/sliding-labels/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 19:01:56 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.csskarma.com/blog/?p=689</guid>
		<description><![CDATA[Please use version 3 of sliding labels with updated options and bug fixes at: http://www.csskarma.com/blog/sliding-labels-plugin/ A few weeks ago I was reading an article on form UI by Luke Wroblewski of Yahoo!. For those who aren&#8217;t familiar with Luke, he (quite literally) wrote the book on good form design. In the article, one certain section [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.csskarma.com/blog/wp-content/uploads/banner_slidinglabel.jpg" alt="Sliding Label banner"></p>
<div style="background:#fffcdB;padding:10px;margin:0 0 30px;border:1px solid #bebf6b;clear:both;font-size:16px;">Please use <strong>version 3</strong> of sliding labels with updated options and bug fixes at: <a href="http://www.csskarma.com/blog/sliding-labels-plugin/">http://www.csskarma.com/blog/sliding-labels-plugin/</a></div>
<p>A few weeks ago I was reading an <a href="http://www.lukew.com/ff/entry.asp?968">article</a> on form UI by <a href="http://www.lukew.com/">Luke Wroblewski</a> of <a href="http://www.yahoo.com/">Yahoo!</a>.  For those who aren&#8217;t familiar with Luke, he (<a href="http://rosenfeldmedia.com/books/webforms/">quite literally</a>) wrote the book on good form design.</p>
<p>In the article, one certain section about placing labels inside of form fields stood out to me:</p>
<blockquote cite="http://www.lukew.com/ff/entry.asp?968"><p>Because labels within fields need to go away when people are entering their answer into an input field, the context for the answer is gone. So if you suddenly forget what question you’re answering, tough luck—the label is nowhere to be found. As such, labels within inputs aren’t a good solution for long or even medium-length forms. When you’re done filling in the form, all the labels are gone! That makes it a bit hard to go back and check your answers. <cite>Luke Wroblewski</cite></p></blockquote>
<p>He brings up a good point. Generally speaking, you can look at a field that says &#8220;Tim Wright&#8221; and know that it was a field for your (my) name. But for long forms, yea, I do agree that you can forget some of the questions you answered.</p>
<p>For best practice, Luke talks about leaving your labels outside the form field so it&#8217;s always available to the user. I do think it&#8217;s a pretty good solution, but <strong>I think we can get a little more creative than that</strong>.</p>
<h3>Enter: Sliding Labels</h3>
<p>After reading that article it occurred to me that there&#8217;s no reason we can&#8217;t have the best of both worlds. I like how inline labels look, and I see Luke&#8217;s point about them disappearing as you fill out the form. But, we have jQuery, we know about progressive enhancement, and we have creative minds, so let&#8217;s build something that allows us to keep the label inline, but <strong>slide it off to the left</strong> (or up, whichever you prefer) rather than going away on click.</p>
<p class="demo"><a href="http://www.csskarma.com/lab/plugin_slidinglabels/">View demo (version 2)</a></p>
<h4>The HTML</h4>
<pre><code>&lt;form action="" method="post" id="info"&gt;
   &lt;h2&gt;Contact Information&lt;/h2&gt;
   &lt;div id="name-wrap" class="slider"&gt;
      &lt;label for="name"&gt;Name&lt;/label&gt;
      &lt;input type="text" id="name" name="name"&gt;
   &lt;/div&gt;<span>&lt;!--/#name-wrap--&gt;</span>

   &lt;div id="email-wrap"  class="slider"&gt;
      &lt;label for="email"&gt;E&amp;ndash;mail&lt;/label&gt;
      &lt;input type="text" id="email" name="email"&gt;
   &lt;/div&gt;<span>&lt;!--/#email-wrap--&gt;</span>

   &lt;div id="street-wrap"  class="slider"&gt;
      &lt;label for="st"&gt;Street&lt;/label&gt;
      &lt;input type="text" id="st" name="st"&gt;
   &lt;/div&gt;<span>&lt;!--/#street-wrap--&gt;</span>

   &lt;div id="city-wrap"  class="slider"&gt;
      &lt;label for="city"&gt;City &amp;amp; State&lt;/label&gt;
      &lt;input type="text" id="city" name="city"&gt;
   &lt;/div&gt;<span>&lt;!--/#city-wrap--&gt;</span>

   &lt;div id="zip-wrap"  class="slider"&gt;
      &lt;label for="zip"&gt;Zip code&lt;/label&gt;
      &lt;input type="text" id="zip" name="zip"&gt;
   &lt;/div&gt;<span>&lt;!--/#zip-wrap--&gt;</span>

   &lt;input type="submit" id="btn" name="btn" value="submit"&gt;
&lt;/form&gt;</code></pre>
<p>The only necessary items to make sliding labels (as I built it) work are the wrapper element (<code>DIV</code> in my case) and applying a class of &#8220;slider&#8221; to it (you can change this easily in the JavaScript).</p>
<p>At this point we have a pretty basic, and ugly form</p>
<p><img src="http://www.csskarma.com/blog/wp-content/uploads/slidinglabels_nocss.png" alt="slidinglabels no css" /></p>
<h4>The CSS</h4>
<pre><code>body                       { font:12px/1.3 Arial, Sans-serif; }
form                       { width:380px;padding:0 90px 20px;margin:auto;background:#f7f7f7;border:1px solid #ddd; }
div                        { clear:both;position:relative;margin:0 0 10px; }
label                      { cursor:pointer;display:block; }
input[type="text"]         { width:300px;border:1px solid #999;padding:5px;-moz-border-radius:4px; }
input[type="text"]:focus   { border-color:#777; }
input[name="zip"]          { width:150px; }

/* submit button */
input[type="submit"]       { cursor:pointer;border:1px solid #999;padding:5px;-moz-border-radius:4px;background:#eee; }
input[type="submit"]:hover,
input[type="submit"]:focus { border-color:#333;background:#ddd; }
input[type="submit"]:active{ margin-top:1px; }
</code></pre>
<p>The only 100% necessary CSS in there is the <code>position:relative</code> on the wrapper element (<code>DIV</code>). The rest is basically cosmetic and you can mess with it as you see fit.</p>
<p>At this point you should have a pretty normal looking form with labels on top of their respective inputs.</p>
<p><img src="http://www.csskarma.com/blog/wp-content/uploads/labelslider_nojs.png" alt="labelslider no js" /></p>
<h4>The jQuery</h4>
<p>Now for the section everyone skipped to, provided you didn&#8217;t go straight to the demo (which I usually do).</p>
<pre><code>$(function(){
$('form#info .slider label').each(function(){
	var labelColor = '#999';
	var restingPosition = '5px';

	<span>// style the label with JS for progressive enhancement</span>
	$(this).css({
		'color' : labelColor,
		 	'position' : 'absolute',
	 		'top' : '6px',
			'left' : restingPosition,
			'display' : 'inline',
    	               'z-index' : '99'
	});

	<span>// grab the input value</span>
	var inputval = $(this).next('input').val();

	<span>// grab the label width, then add 5 pixels to it</span>
	var labelwidth = $(this).width();
	var labelmove = labelwidth + 5;

	<span>//onload, check if a field is filled out, if so, move the label out of the way</span>
	if(inputval !== ''){
		$(this).stop().animate({ 'left':'-'+labelmove }, 1);
	}    	

	<span>// if the input is empty on focus move the label to the left</span>
	<span>// if it's empty on blur, move it back</span>
	$('input').focus(function(){
		var label = $(this).prev('label');
		var width = $(label).width();
		var adjust = width + 5;
		var value = $(this).val();

		if(value == ''){
			label.stop().animate({ 'left':'-'+adjust }, 'fast');
		} else {
			label.css({ 'left':'-'+adjust });
		}
	}).blur(function(){
		var label = $(this).prev('label');
		var value = $(this).val();
		if(value == ''){
			label.stop().animate({ 'left':restingPosition }, 'fast');
		}
	});
})
});</code></pre>
<p>At this point, you should have a fully working sliding label form!</p>
<p><img src="http://www.csskarma.com/blog/wp-content/uploads/labelslider_final.png" alt="labelslider final" /></p>
<p class="demo"><a href="http://www.csskarma.com/lab/plugin_slidinglabels/">View demo (version 2)</a></p>
<p>Making sure everything is still usable without JavaScript is important (no matter what people say), it&#8217;s just a basic principle of progressive enhancement. Believe it or not, there are still people browsing without JavaScript (blackberry users &#8211; turned off by default). So creating the interaction in layers, as we did, will help it be <strong>past-proof</strong>.</p>
<p>Try it out and let me know what you think. So far I&#8217;ve used it on a password change form, so definitely let me know if you find a place to use it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.csskarma.com/blog/sliding-labels/feed/</wfw:commentRss>
		<slash:comments>140</slash:comments>
		</item>
		<item>
		<title>Quick Tip #3 &#8211; Textarea Fonts</title>
		<link>http://www.csskarma.com/blog/qt3-textarea-fonts/</link>
		<comments>http://www.csskarma.com/blog/qt3-textarea-fonts/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 02:28:27 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[quick tip]]></category>

		<guid isPermaLink="false">http://www.csskarma.com/blog/?p=558</guid>
		<description><![CDATA[The Problem The font family in this text area default to Courier New, but that&#8217;s pretty ugly. The Goal Look at the nice font in this textarea! The Solution You have to redefine the font-family for a textarea. Just a weird quirk. textarea{ font-family:Verdana, Arial, Sans-Serif; }]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.csskarma.com/images/articles/textarea-fonts.jpg" alt="article banner"/></p>
<h4>The Problem</h4>
<p><textarea cols="40" rows="10" class="testfield courier">The font family in this text area default to Courier New, but that&#8217;s pretty ugly.</textarea></p>
<h4>The Goal</h4>
<p><textarea cols="40" rows="10" style="font-family: verdana">Look at the nice font in this textarea!</textarea></p>
<h4>The Solution</h4>
<p>You have to redefine the font-family for a <code>textarea</code>. Just a weird quirk.</p>
<pre><code>textarea{
font-family:Verdana, Arial, Sans-Serif;
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.csskarma.com/blog/qt3-textarea-fonts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Form Security with Autocomplete</title>
		<link>http://www.csskarma.com/blog/autocomplete-off/</link>
		<comments>http://www.csskarma.com/blog/autocomplete-off/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 15:57:04 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.csskarma.com/blog/?p=480</guid>
		<description><![CDATA[I was looking through my blog this morning because I could have sworn I already wrote this post. I know I&#8217;ve had this conversation with Phil Nash of Unintentionally Blank. But I guess I never wrote it down? Oh well&#8230; One of my pet peeves when filling out a form is when I click in [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.csskarma.com/images/articles/autocomplete.jpg" alt="article banner"/></p>
<p>I was looking through my blog this morning because I could have sworn I already wrote this post. I know I&#8217;ve had this conversation with Phil Nash of <a href="http://www.unintentionallyblank.co.uk/">Unintentionally Blank</a>. But I guess I never wrote it down? Oh well&#8230;</p>
<p>One of my pet peeves when filling out a form is when I click in the payment field and my credit crard / bank account number drops down because it was saved in the browser from last time I made a payment on that site. How is it that developers on these sites overlook that <strong>huge</strong> security issue?</p>
<p>There&#8217;s a very simple fix for it, and it&#8217;s called &#8220;autocomplete off&#8221;:</p>
<h5>The XHTML</h5>
<pre><code>&lt;input id="pmt" name="payment" type="text" autocomplete="off"/&gt;</code></pre>
<p>The <code>autocomplete="off"</code> makes sure the text field doesn&#8217;t expose any saved data. Of course, it would be too easy if this was valid XHTML so it&#8217;s not. If you&#8217;re concerned with writing 100% valid XHTML, there are valid ways to do this.</p>
<h4>Writing valid code</h4>
<p>To make this valid, we need to do it with JavaScript. Since I&#8217;m pretty sure most people who read this are jQuery freaks (like me), I&#8217;ll show the jQuery version of this:</p>
<h5>The XHTML</h5>
<pre><code>&lt;input id="pmt" name="payment" type="text" /&gt;</code></pre>
<h5>The jQuery</h5>
<pre><code>$(function() {
$("input#pmt").attr("autocomplete","off");
});</code></pre>
<h4>The problem with added security with JavaScript</h4>
<p>I don&#8217;t really recommend using javaScript for this, only because it&#8217;s easily disabled. And then you&#8217;re back at square one with the payment info dropping down in the text field</p>
<p>Ideally, I&#8217;d like to use PHP to do this, but I can&#8217;t find it anywhere so I&#8217;m using &lt;noscript&gt;:</p>
<h5>The jQuery</h5>
<pre><code>$(function() {
$("form#paymentform").html("&lt;input id="pmt" name="payment" type="text" autocomplete="off"/&gt;);
});</code></pre>
<h5>The XHTML (placed inside the form)</h5>
<pre><code>&lt;label for="pmt"&gt;Credit Card Number&lt;/label&gt;
&lt;noscript&gt;</code><code>&lt;input id="pmt" name="payment" type="text" autocomplete="off"/&gt;</code><code>&lt;/noscript&gt;</code></pre>
<p>That way, if javascript is enabled you&#8217;ll use the jQuery to write the textfield, and if it&#8217;s not, you&#8217;ll just write it out normally, which will be invalid, but more secure.</p>
<p>Let me know if anyone knows the PHP way to check for JS.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.csskarma.com/blog/autocomplete-off/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
