<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"
>

<channel>
	<title>LiquidFoot &#187; AJAX</title>
	<atom:link href="http://www.liquidfoot.com/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.liquidfoot.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 17 Apr 2010 16:36:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Form Validation</title>
		<link>http://www.liquidfoot.com/2006/09/21/form-validation/</link>
		<comments>http://www.liquidfoot.com/2006/09/21/form-validation/#comments</comments>
		<pubDate>Thu, 21 Sep 2006 16:17:42 +0000</pubDate>
		<dc:creator>Wayne</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[coldfusion]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.liquidfoot.com/?p=202</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<div class="body">
<p>I&#8217;ve been playing with some form validation stuff for CF. I had been usign , but I wanted the HTML interface to act a bit more like the Flash interface, but I don&#8217;t really want to use Flash. I&#8217;ve also been doing a lot more work with some of the DHTML libraries that AJAX has made popular, so I figured there had to be a relatively elegent way to do form validations with something like <a href="http://prototype.conio.net/%3Eprototype%3C/a%3E.%3C/p%3E%3Cp%3EI%20remembered%20seeing%20something%20on%20%3Ca%20href=">Ajaxian</a> about easy form validation and decided to give it a try. The article on <a href="http://tetlaw.id.au/view/blog/really-easy-field-validation-with-prototype/">Dexagogo</a> shows how they created a library to handle form-validations that doesn&#8217;t require any other work than creating a form. This was just what I was looking for!</p>
<p>Basically, you just need the latest files from <a href="http://script.aculo.us/">script.aclo.us</a> with the latest prototype version (the 1.5 release candidate is included in the latest script.aculo.us lib folder), and the validation library. Convienently, they&#8217;re all included <a href="http://tetlaw.id.au/upload/dev/validation/validation1.5.3.zip">in the demo file on the site</a>.</p>
<p>To use this, you really only need prototype and the validation library (script.aculo.us adds a nice effect – much like the Flash format in cfform). For me, I made these calls:</p>
<div class="code"><span style="color: #000080;">&lt;head&gt;</span><br />
<span style="color: #000080;"><span style="color: #800000;">&lt;script type=<span style="color: #0000ff;">&#8220;text/javascript&#8221;</span> src=<span style="color: #0000ff;">&#8220;/scripts/scriptaculous/lib/prototype.js&#8221;</span>&gt;</span></span><span style="color: #000080;"><span style="color: #800000;">&lt;/script&gt;</span></span><br />
<span style="color: #000080;"><span style="color: #800000;">&lt;script type=<span style="color: #0000ff;">&#8220;text/javascript&#8221;</span> src=<span style="color: #0000ff;">&#8220;/scripts/validator.js&#8221;</span>&gt;</span></span><span style="color: #000080;"><span style="color: #800000;">&lt;/script&gt;</span></span><br />
<span style="color: #000080;"><span style="color: #800000;">&lt;script type=<span style="color: #0000ff;">&#8220;text/javascript&#8221;</span> src=<span style="color: #0000ff;">&#8220;/scripts/scriptaculous/scriptaculous.js?load=effects&#8221;</span>&gt;</span></span><span style="color: #000080;"><span style="color: #800000;">&lt;/script&gt;</span></span><br />
<span style="color: #000080;">&lt;/head&gt;</span></div>
<p>This is slightly different than the example on their page; they load the effects.js file directly, I&#8217;m calling the library via script.aculo.us with the load parameter. This isn&#8217;t really a big deal for one library, but it is convenient when you want to use several, but not all, of the libraries (e.g. scriptaculous.js?load=effects,dragdrop,slider).</p>
<p>Anyway, to actually use this, you need to create a form with an id attribute:</p>
<div class="code"><span style="color: #000080;"><span style="color: #ff8000;">&lt;form name=<span style="color: #0000ff;">&#8220;feedback&#8221;</span> id=<span style="color: #0000ff;">&#8220;feedback&#8221;</span> action=<span style="color: #0000ff;">&#8220;#cgi.script_name#&#8221;</span> method=<span style="color: #0000ff;">&#8220;post&#8221;</span>&gt;</span></span><br />
&#8230;<br />
<span style="color: #000080;"><span style="color: #ff8000;">&lt;/form&gt;</span></span></div>
<p>Now, we add some fields and use the class attribute to call the validator:</p>
<div class="code">Name: <span style="color: #000080;"><span style="color: #ff8000;">&lt;input type=<span style="color: #0000ff;">&#8220;text&#8221;</span> name=<span style="color: #0000ff;">&#8220;name&#8221;</span> id=<span style="color: #0000ff;">&#8220;name&#8221;</span> class=<span style="color: #0000ff;">&#8220;required&#8221;</span> /&gt;</span></span><span style="color: #000080;">&lt;br/&gt;</span><br />
Email: <span style="color: #000080;"><span style="color: #ff8000;">&lt;input type=<span style="color: #0000ff;">&#8220;text&#8221;</span> name=<span style="color: #0000ff;">&#8220;email&#8221;</span> id=<span style="color: #0000ff;">&#8220;email&#8221;</span> class=<span style="color: #0000ff;">&#8220;required validate-email&#8221;</span> /&gt;</span></span><br />
<span style="color: #000080;"><span style="color: #ff8000;">&lt;input type=<span style="color: #0000ff;">&#8220;submit&#8221;</span> /&gt;</span></span></div>
<p>There are 11 options for use in the validation library (this is directly off their page):</p>
<ul>
<li>required (not blank)</li>
<li>validate-number (a valid number)</li>
<li>validate-digits (digits only)</li>
<li>validate-alpha (letters only)</li>
<li>validate-alphanum (only letters and numbers)</li>
<li>validate-date (a valid date value)</li>
<li>validate-email (a valid email address)</li>
<li>validate-url (a valid URL)</li>
<li>validate-date-au (a date formatted as; dd/mm/yyyy)</li>
<li>validate-currency-dollar (a valid dollar value)</li>
<li>validate-one-required (At least one textbox/radio element must be selected in a group)</li>
</ul>
<p>This is really nice, because if you want to allow an optional field, but validate it, you can do:</p>
<div class="code"><span style="color: #000080;"><span style="color: #ff8000;">&lt;input type=<span style="color: #0000ff;">&#8220;text&#8221;</span> name=<span style="color: #0000ff;">&#8220;email&#8221;</span> class=<span style="color: #0000ff;">&#8220;validate-email&#8221;</span> /&gt;</span></span></div>
<p>There&#8217;s one more piece of the pie&#8230;to call the validation library. At the bottom of your page add:</p>
<div class="code"><span style="color: #000080;"><span style="color: #800000;">&lt;script type=<span style="color: #0000ff;">&#8220;text/javascript&#8221;</span>&gt;</span></span><br />
new Validation(&#8216;feedback&#8217;, {immediate:true});<br />
<span style="color: #000080;"><span style="color: #800000;">&lt;/script&gt;</span></span></div>
<p>The first argument is the id attribute of the form you&#8217;re wanting to validate. The second tells the Validator object what to do. This particular example enables validation on each field as you leave it (which I find useful). Some of the other options are:</p>
<ul>
<li>stopOnFirst (boolean): Stop on the first validation failure; default: false</li>
<li>onSubmit (boolean): Override the default behavior of adding an even listener to the onsubmit event (set to false if you want to make sure your onsubmit method gets called no matter what); default: true</li>
<li>immediate (boolean): validate when the cursor leaves the field; default: false</li>
<li>focusOnError (boolean): place the focus on the first field with an error; default: true</li>
<li>useTitles (boolean): make field validators use form element title attributes as error advice message; default: false</li>
<li>onFormValidate (string function): call a function when the form is validated</li>
<li>onElementValidate (string function): call a function when an element is validated</li>
</ul>
<p>What I thought was really cool was the ability to add custom validation types via an API. Say you only want folks to use capital letters for their names, you simply add a new validation type like:</p>
<div class="code"><span style="color: #000080;"><span style="color: #800000;">&lt;script type=<span style="color: #0000ff;">&#8220;javascript&#8221;</span>&gt;</span></span><br />
Validation.add(&#8216;validate-ucase&#8217;, &#8216;Please only use upper-case letters (A-Z) in this field.&#8217;, function(v){<br />
return Validation.get(&#8216;IsEmpty&#8217;).test(v) || /^[A-Z]+$/.test(v);<br />
}<br />
<span style="color: #000080;"><span style="color: #800000;">&lt;/script&gt;</span></span></div>
<p>Want to add several? You can do that too:</p>
<div class="code"><span style="color: #000080;"><span style="color: #800000;">&lt;script type=<span style="color: #0000ff;">&#8220;javascript&#8221;</span>&gt;</span></span><br />
Validation.addAllThese([<br />
['validate-lcase', 'Please only use lower-case (a-z) letters in this field', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^[a-z]+$/.test(v);<br />
}],<br />
['validate-zip', 'Please check your zip code', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^(\d{5})(( |-)?(\d{4}))?$/.test(v);<br />
}],<br />
['validate-phone', 'Please check your phone number', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^(([0-9]{3}-)|\([0-9]{3}\) ?)?[0-9]{3}-[0-9]{4}$/.test(v);<br />
}],<br />
['validate-ssn', 'Please check the Social Security Number. It should follow the format 999-99-9999', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^([0-9]{3}(-?)[0-9]{2}(-?)[0-9]{4})$/.test(v);<br />
}],<br />
['validate-ip', 'Please check the IP address', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/.test(v);<br />
}],<br />
['validate-uuid', 'Please check the UUID', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{16}$/.test(v);<br />
}],<br />
['validate-guid', 'Please check the GUID', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^[0-9a-f]{8,<span style="color: #0000ff;">8</span>}-[0-9a-f]{4,<span style="color: #0000ff;">4</span>}-[0-9a-f]{4,<span style="color: #0000ff;">4</span>}-[0-9a-f]{4,<span style="color: #0000ff;">4</span>}-[0-9a-f]{12,<span style="color: #0000ff;">12</span>}]$/.test(v);<br />
}],<br />
['validate-float', 'Please only use floating point numbers in this field', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^(\b[0-9]+\.([0-9]+\b)?|\.[0-9]+\b)$/.test(v);<br />
}],<br />
['validate-visa', 'Please check your credit card number', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/.test(v);<br />
}],<br />
['validate-mastercard', 'Please check your credit card number', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/.test(v);<br />
}],<br />
['validate-discovery', 'Please check your credit card number', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^6011-?\d{4}-?\d{4}-?\d{4}$/.test(v);<br />
}],<br />
['validate-amex', 'Please check your credit card number', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^3[4,<span style="color: #0000ff;">7</span>]\d{13}$/.test(v);<br />
}],<br />
['validate-diners', 'Please check your credit card number', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^3[0,<span style="color: #0000ff;">6</span>,<span style="color: #0000ff;">8</span>]\d{12}$/.test(v);<br />
}],<br />
['validate-time', 'Please only use time in this field', function(v){<br />
return Validation.get('IsEmpty').test(v) || /^\d{1,<span style="color: #0000ff;">2</span>}[:]\d{2}([:]\d{2})?( [aApP][mM]?)?$/.test(v);<br />
}]<br />
]);<br />
<span style="color: #000080;"><span style="color: #800000;">&lt;/script&gt;</span></span></div>
<p>This should be all of the normal items included in  (plus a couple extra for good measure). Now the only thing left is to make it look pretty. One of the nice things about the Flash format in  is that it color codes required fields with the different halo effects. To obtain a similar effect in the forms, we&#8217;ll use style sheets instead.</p>
<p>This is a rather light stylesheet, but it&#8217;ll give you something to start with (based on the default haloGreen skin):</p>
<div class="code">input.required, textarea.required {<br />
border: 1px solid #ffbf2b;<br />
}<br />
input.validation-failed, textarea.validation-failed{<br />
border: 1px solid #ff3300;<br />
color: #ff3300;<br />
}<br />
input.validation-passed, textarea.validation-passed{<br />
border: 1px solid #00cc00;<br />
color: #000;<br />
}<br />
.validation-advice {<br />
margin: 5px 0;<br />
padding: 5px;<br />
background-color: #FF3300;<br />
color: #fff;<br />
font-weight: bold;<br />
}<br />
.custom-advice {<br />
margin: 5px 0;<br />
padding: 5px;<br />
background-color: #c8aa00;<br />
color: #fff;<br />
font-weight:bold;<br />
}</div>
<p>I made a short example of some of the validations at <a href="http://swem.wm.edu/blogs/waynegraham/examples/validation/">http://swem.wm.edu/blogs/waynegraham/examples/validation/</a>. I have to say that I&#8217;ve found this to be a bit better solution (at least for my needs) than using !</div>
]]></content:encoded>
			<wfw:commentRss>http://www.liquidfoot.com/2006/09/21/form-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting XML from MSSQL Server</title>
		<link>http://www.liquidfoot.com/2006/08/21/getting-xml-from-mssql-server/</link>
		<comments>http://www.liquidfoot.com/2006/08/21/getting-xml-from-mssql-server/#comments</comments>
		<pubDate>Mon, 21 Aug 2006 18:49:57 +0000</pubDate>
		<dc:creator>Wayne</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[coldfusion]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.liquidfoot.com/?p=210</guid>
		<description><![CDATA[I&#8217;ve been playing with all the AJAX stuff that&#8217;s been coming out lately. I suppose that like a lot of folks, I was creating a query, then having a generic function that created the XML in a proxy file for the JavaScript (Ray Camden has a really nice function for transforming a query to XML). [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing with <a href="http://openrico.org/">all</a> <a href="http://swem.wm.edu/blogs/waynegraham/index.cfm/2006/scriptaculous">the</a> <a href="http://labs.adobe.com/technologies/spry/">AJAX</a> <a href="http://dojotoolkit.org/">stuff</a> <a href="http://developer.yahoo.com/yui/">that&#8217;s</a> <a href="http://code.google.com/webtoolkit/">been</a> <a href="http://mochikit.com/">coming</a> <a href="http://www.aflax.org/">out</a> <a href="http://jquery.com/">lately</a>. I suppose that like a lot of folks, I was creating a query, then having a generic function that created the XML in a proxy file for the JavaScript (<a href="http://ray.camdenfamily.com/index.cfm/2006/7/13/ToXML-Update">Ray Camden has a really nice function for transforming a query to XML</a>).</p>
<p>Last week I was doing some research to find a way to do some XML searching and stumbled upon the <a href="http://msdn2.microsoft.com/en-us/library/ms190922.aspx">FOR XML</a> statement. I knew that most RDBMSs were capable of dealing with XML record sets, but it&#8217;s been years since I&#8217;ve even looked at any of the XML stuff for MSSQL.</p>
<p>The FOR XML statement returns a query result and transforms rows into XML elements. There are three arguments that this can take:</p>
<ul>
<li><a href="http://msdn2.microsoft.com/en-us/library/ms175140.aspx">RAW</a>: Transforms each row into an element with a generic identifier (&lt;row/&gt;) as the element tag.</li>
<li><a href="http://msdn2.microsoft.com/en-us/library/ms188273.aspx">AUTO</a>: Returns the results in a simple nested XML tree</li>
<li><a href="http://msdn2.microsoft.com/en-us/library/ms175140.aspx">EXPLICIT</a>: Allows you to define the XML tree returned</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.liquidfoot.com/2006/08/21/getting-xml-from-mssql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
