<?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>Interactive IQ : The Hessler Design Blog &#187; html</title>
	<atom:link href="http://www.hesslerdesign.com/blog/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hesslerdesign.com/blog</link>
	<description>Smart Developers = Smart Websites</description>
	<lastBuildDate>Thu, 26 Jan 2012 23:00:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>FileLoader: A Flash Preloader &amp; Container File (with Cache Buster Option)</title>
		<link>http://www.hesslerdesign.com/blog/flash/fileloader-a-flash-preloader-container-file-with-cache-buster-option/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/fileloader-a-flash-preloader-container-file-with-cache-buster-option/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 05:06:04 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=711</guid>
		<description><![CDATA[Recently, I had a client whose server had its own cache that only cleared once a day, which ended up posing problems for updating content, as the server cache would either needed to be flushed, or we&#8217;d just have to wait it out and wait for the cache to clear on its own.  The content [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I had a client whose server had its own cache that only cleared once a day, which ended up posing problems for updating content, as the server cache would either needed to be flushed, or we&#8217;d just have to wait it out and wait for the cache to clear on its own.  The content I was working on was a Flash file, so rather than having to flush the server cache every time I made an update, I came up with another solution for the Flash file.</p>
<p>The solution was to make a &#8220;container&#8221; SWF file that would load in the actual content for the page.  This was nice because the container ended up also acting as a preloader for the main content.  All I had to do in the container file was to append a query string to the end of the content to load in (i.e. &#8220;photo.jpg?id=12345678&#8243;), which effectively acted as a &#8220;cache buster&#8221; that would make the browser and server think it was loading a new file each time the page was loaded.</p>
<p>The result was this little nugget of Flash goodness: <strong>FileLoader</strong>.</p>
<p>I polished up the container file I made in my solution above, adding in a couple of customizable variables, and am making it freely available for download.</p>
<p><span id="more-711"></span></p>
<h4>Version Information:</h4>
<ul>
<li><strong>Version:</strong> 1.0</li>
<li><strong>Release Date:</strong> 1/12/11</li>
</ul>
<h4>Download:</h4>
<p>Like what you see? Want to use FileLoader with your own Flash projects? Click the button below to download the most recent version of FileLoader, including a demo file with full instructions.</p>
<div style="margin-top: 9px;"><a href="http://www.hesslerdesign.com/downloads/fileloader/FileLoader.zip"><img class="aligncenter size-full wp-image-426" title="Download FileLoader" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2011/01/btn_downloadFileLoader.png" alt="Download FileLoader" width="166" height="29" /></a></div>
<h4>License:</h4>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="100" valign="top"><a rel="license" href="http://creativecommons.org/licenses/by/3.0/us/" target="_blank"><img style="border-width: 0; margin-top: 3px;" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" alt="Creative Commons License" /></a></td>
<td valign="top">
<p style="float: left; margin-top: 0px;">FileLoader is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/" target="_blank">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>, and is free to use. Links back to <strong>hesslerdesign.com</strong> are always appreciated. Permissions beyond the scope of this license may be available by submitting a <a rel="cc:morePermissions" href="http://www.hesslerdesign.com/contact/">Contact Request</a>.</p>
</td>
</tr>
</tbody>
</table>
<h4>Description:</h4>
<p>FileLoader is a simple, lightweight, easy-to-implement FLA/SWF file that acts as a preloader and container for files. It is made to load a specified URL, can enable &#8220;cache busting&#8221;, and provides the ability to change the hex color of the preloader and text. It can load any type of file that the built-in Loader class loads (SWF, JPG, PNG, GIF).</p>
<h4>Example:</h4>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="534" height="442" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.hesslerdesign.com/blog/wp-content/uploads/2011/01/fileLoaderDemo.swf" /><embed type="application/x-shockwave-flash" width="534" height="442" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2011/01/fileLoaderDemo.swf"></embed></object></p>
<h4>Instructions:</h4>
<p>To use this file, simply update any/all of the customizable variables located on the aptly-named &#8220;Customizable Variables&#8221; layer (in .fla file). These variables include:</p>
<ol>
<li><strong>contentURL (String):</strong> URL path of the content you wish to load into FileLoader. (Default = &#8220;&#8221;)</li>
<li><strong>tintHex (uint):</strong> Hex value to tint the preloader and error message. (Default = &#8220;0&#215;000000&#8243;)</li>
<li><strong>cacheBuster (Boolean):</strong> Enables/Disables &#8220;cache busting&#8221; on your content. (Default = &#8220;false&#8221;)</li>
</ol>
<p>Once the variables are updated, just export the SWF and it&#8217;s ready to be embedded into your HTML page for the web.</p>
<h4>Notes:</h4>
<ol>
<li>FileLoader is set up to resize itself to 100% of the stage width and height, making it flexible to be used at any size. This means you don&#8217;t have to worry about changing the dimensions of the file, and when embedding this file into your HTML page, you can specify any width and height you wish. The Preloader and Load Error (if applicable) will automatically center themselves to the stage. The content, however, has no special positioning logic, and will be placed at the (0,0) point of the stage. Thus, it is intended that this file will be embedded at the exact size of the content you&#8217;re loading into it, as this file is only intended to be a preloader and container for the contents of one file.</li>
<li>The Preloader and Load Error elements (where applicable) are automatically added to and removed from the file when needed. Your content will automatically be placed into the file when it&#8217;s loaded, and be the only item on the stage at that point. You don&#8217;t have to do anything special to get your content to display other than specifying a valid content URL.</li>
<li>When you&#8217;re ready to post the files to your website, just make sure you upload this file along with the content it loads. Also, <strong><span style="text-decoration: underline;">make sure your pathing is set up appropriately for the content URL</span></strong> or your content may not load correctly.</li>
<li>If you update or change any of the MovieClips in the library, or update, append or change any of the code in the main Actions layer, this file may break. If you know what you&#8217;re doing with Flash and ActionScript, you shouldn&#8217;t have any problem figuring out how things work and can be edited. If you&#8217;re a beginner or novice, you may have a harder time editing. With that said, edit the non-customizable elements at your own risk.</li>
<li>If the &#8220;cacheBuster&#8221; variable is set to &#8220;true&#8221;, a random 8-digit ID will be appended as a query string to the &#8220;contentURL&#8221; variable (i.e. &#8220;<em>photo.jpg?id=12345678</em>&#8220;). When the cache buster is enabled, it will force the FileLoader to load a fresh version of the content URL each time it is loaded. This is helpful if you are posting your Flash content on a server with its own cache settings that would result in updated content not being immediately visible until the server cache clears. If this variable is set to &#8220;false&#8221;, no ID will be appended to the content URL, and the loaded content will be cached as normal.</li>
<li><strong><span style="text-decoration: underline;">Important:</span></strong> Use the cache busting sparingly and only when necessary, as it may end up bogging down the server with unnecessary calls to the server to reload the content.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/fileloader-a-flash-preloader-container-file-with-cache-buster-option/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Build a Customized Progress Bar Using CSS and JQuery</title>
		<link>http://www.hesslerdesign.com/blog/tutorials/build-a-customized-progress-bar-using-css-and-jquery/</link>
		<comments>http://www.hesslerdesign.com/blog/tutorials/build-a-customized-progress-bar-using-css-and-jquery/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 19:30:02 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[stylesheet]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=590</guid>
		<description><![CDATA[One nice feature that many websites have is a progress bar.  They come in many shapes and sizes, whether they are showing a user what step they&#8217;re on in a process, what percent of the way through a process the user is, etc.  And today, with the use of trusted CSS and JavaScript (in the [...]]]></description>
			<content:encoded><![CDATA[<p>One nice feature that many websites have is a progress bar.  They come in many shapes and sizes, whether they are showing a user what step they&#8217;re on in a process, what percent of the way through a process the user is, etc.  And today, with the use of trusted CSS and JavaScript (in the form of the jQuery library), a progress bar has never been easier to create with a minimal amount of images needed.  (Truthfully, you don&#8217;t need any images, but in the example below the tutorial, I&#8217;ve used a few to add some nice styling to the example.)</p>
<p>With that said, on with the code!</p>
<h4>Step 1: Set Up HTML Code</h4>
<p>The first thing you want to do is to create two div tags in your file, each with unique IDs.  One will be the &#8220;container&#8221; for the progress bar, and the other will be located inside of it, and will be the one getting sized to show the progress.  Here&#8217;s how I have set it up:</p>
<p><code><span style="color: #000099;">&lt;div id=</span><span style="color: #0000ff;">"progress-bar"</span><span style="color: #000099;">&gt;</span><br />
&nbsp; &nbsp;<span style="color: #000099;">&lt;div id=</span><span style="color: #0000ff;">"status"</span><span style="color: #000099;">&gt;&lt;/div&gt;</span><br />
<span style="color: #000099;">&lt;/div&gt;</span></code></p>
<h4>Step 2: Add Some Style</h4>
<p>Now that the basic HTML is set up (and seriously, how easy was that HTML setup?), we&#8217;ll add some CSS magic to make it look better.  Here&#8217;s how I have styled our example:</p>
<p><code><span style="color: #ff00ff;">#progress-bar</span> <span style="color: #ff00ff;">{</span><span style="color: #000099;">border</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">1px solid #bebebe</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">background</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">#ffffff</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">width</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">300px</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">height</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">14px</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">-moz-border-radius</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">10px</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">-webkit-border-radius</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">10px</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">-khtml-border-radius</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">10px</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">border-radius</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">10px</span><span style="color: #ff00ff;">;</span><span style="color: #ff00ff;">}</span><br />
<span style="color: #ff00ff;">#status</span> {<span style="color: #000099;">background</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">#0066cc</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">width</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">50%</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">height</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">14px</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">-moz-border-radius</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">10px</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">-webkit-border-radius</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">10px</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">-khtml-border-radius</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">10px</span><span style="color: #ff00ff;">;</span> <span style="color: #000099;">border-radius</span><span style="color: #ff00ff;">:</span><span style="color: #0000ff;">10px</span><span style="color: #ff00ff;">;</span><span style="color: #ff00ff;">}</span></code></p>
<p>The important thing to note here is that the <code>#status</code> ID has a percentage-based width.  Since it is contained within the fixed width <code>#progress-bar</code> div, it&#8217;ll automatically calculate how wide it has to be.  Oh the magic of CSS!</p>
<p>Another thing to note here is the use of the multiple &#8220;radius&#8221; attributes for different browsers.  It&#8217;s a bit out of the scope of this post, but to make a long story short, if your browser supports one of these attributes, you&#8217;ll get a nice rounded look.  If not, it&#8217;ll just be a normal rectangle.  Your call on whether you like the rounded corners or not.</p>
<p>If you decide to use the &#8220;radius&#8221; attributes for styling, be warned that if the percent width on your status bar is at or lower than the radius amount, it may throw off the look of the edges, as the browser will try to &#8220;make up&#8221; the shape with corners as best it can with the radius values included.  This isn&#8217;t a factor when the corners are squared off, but it&#8217;s a good thing to know up front, just in case you need small percentages used.</p>
<p>Also, feel free to style these with background images, with taller heights, different colors, etc.  As you&#8217;ll see in the included sample below, I&#8217;ve gone ahead and added in some background images to spice up the design a bit.</p>
<h4>3. Jazz It Up with jQuery</h4>
<p>Once your HTML and CSS are in place, you&#8217;re all done.  Unless, however, you want to update the progress bar on the spot in front of the user.  If that&#8217;s what you&#8217;re going for, then here&#8217;s where you can use some jQuery goodness to animate the bar however you need.</p>
<p>First, you&#8217;ll need the most recent version of the jQuery library.  Link it into your HTML file, and then whenever you need to change the width of the <code>#status</code> bar, just call a JavaScript function like this (with the &#8220;80%&#8221; width attribute set to whatever you need it set to):</p>
<p><code>$<span style="color: #000099;">(</span><span style="color: #0000ff;">"#status"</span><span style="color: #000099;">)</span>.animate<span style="color: #000099;">( {</span> width: <span style="color: #0000ff;">"80%"</span> <span style="color: #000099;">}</span>, <span style="color: #ff0000;">500</span><span style="color: #000099;">)</span>;</code></p>
<h4>Wrapping It Up</h4>
<p>That&#8217;s really all there is to it.  Pretty basic stuff.  But it&#8217;s definitely a nice trick to have up your sleeve.  And with a little extra work on styling and JavaScript logic, you can have some pretty robust logic that does some really cool things.  The example below shows you how the extra styling looks, and will allow you to see how the #status bar animates when the jQuery function is called.</p>
<p>Until next time, happy coding!</p>
<h4>Example</h4>
<p><iframe id="progress_bar_example" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2010/08/progress_bar/index.html" width="100%" height="190" scrolling="auto" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/tutorials/build-a-customized-progress-bar-using-css-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bulletproof Your Online Forms for Mobile Devices with PHP – Part 2</title>
		<link>http://www.hesslerdesign.com/blog/tutorials/bulletproof-your-online-forms-for-mobile-devices-with-php-%e2%80%93-part-2/</link>
		<comments>http://www.hesslerdesign.com/blog/tutorials/bulletproof-your-online-forms-for-mobile-devices-with-php-%e2%80%93-part-2/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 16:50:54 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[validation]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=566</guid>
		<description><![CDATA[In the last post, we explored how to set up an online form using HTML and PHP. In this post, we&#8217;re going to finish setting up the logic to store form field values and validate the form.  If you haven&#8217;t read the last post and want to catch up, please click here to go to [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.hesslerdesign.com/blog/tutorials/bulletproof-your-online-forms-for-mobile-devices-with-php-part-1/">last post</a>, we explored how to set up an online form using HTML and PHP.  In this post, we&#8217;re going to finish setting up the logic to store form field values and validate the form.  If you haven&#8217;t read the last post and want to catch up, please <a href="http://www.hesslerdesign.com/blog/tutorials/bulletproof-your-online-forms-for-mobile-devices-with-php-part-1/" target="_self">click here to go to part 1</a>.</p>
<h4>Step 1: Add PHP Functions for Setting/Resetting Variables</h4>
<p>In the last post, we set the form up so the value for each form field is set to a corresponding PHP variable. Now we need to make sure that when the form field changes and a user action (like submitting the form) takes place, the PHP variables get set to the newly updated form field values.  This is a simple process, as we just have to create a function to set the PHP variables.  And while we&#8217;re at it, we can create another function to reset the PHP variables for our &#8216;Clear Form&#8217; button.  Here are the functions we&#8217;ll use.  Note that we need to use the &#8216;global&#8217; keyword inside the functions to access and successfully update the variables.</p>
<p><code><span style="color: #0000ff;">function</span> setVariables<span style="color: #000099;">() {</span><br />
&nbsp; &nbsp;<span style="color: #006600;">global</span> $user_name;<br />
&nbsp; &nbsp;$user_name <span style="color: #0000ff;">=</span> <span style="color: #0066ff;">$_POST</span><span style="color: #000099;">[</span><span style="color: #cc0000;">"user_name"</span><span style="color: #000099;">]</span>;<br />
&nbsp; &nbsp;<span style="color: #006600;">global</span> $user_email;<br />
&nbsp; &nbsp;$user_email <span style="color: #0000ff;">=</span> <span style="color: #0066ff;">$_POST</span><span style="color: #000099;">[</span><span style="color: #cc0000;">"user_email"</span><span style="color: #000099;">]</span>;<br />
&nbsp; &nbsp;<span style="color: #006600;">global</span> $user_message;<br />
&nbsp; &nbsp;$user_message <span style="color: #0000ff;">=</span> <span style="color: #0066ff;">$_POST</span><span style="color: #000099;">[</span><span style="color: #cc0000;">"user_message"</span><span style="color: #000099;">]</span>;<br />
<span style="color: #000099;">}</span><br />
<span style="color: #0000ff;">function</span> resetVariables<span style="color: #000099;">() {</span><br />
&nbsp; &nbsp;<span style="color: #006600;">global</span> $user_name;<br />
&nbsp; &nbsp;$user_name <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">""</span>;<br />
&nbsp; &nbsp;<span style="color: #006600;">global</span> $user_email;<br />
&nbsp; &nbsp;$user_email <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">""</span>;<br />
&nbsp; &nbsp;<span style="color: #006600;">global</span> $user_message;<br />
&nbsp; &nbsp;$user_message <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">""</span>;<br />
<span style="color: #000099;">}</span></code></p>
<p>Again, these functions will eventually get called when a user clicks on the Submit or Reset button, respectively.</p>
<p><span id="more-566"></span></p>
<h4>Step 2: Add PHP Functions for Form Field Validation</h4>
<p>Now it&#8217;s time to write out the validation functions for the form.  In our example, we have three fields.  The name and message fields will be a simple character count for their validation.  In the email validation, we will use one of the well known regular expressions that will check the email value for correct syntax.</p>
<p>For the simple text input, we&#8217;ll create a function that accepts two arguments.  The first argument will be the value to get validated, and the second will be the minimum number of characters that need to be present in the first value.  Inside the function, there will be some simple conditional logic that will check the string length of the first value to the minimum number of characters.  We&#8217;ll also set a return value of &#8216;y&#8217; or &#8216;n&#8217; so we&#8217;ll know whether or not our value is valid.  Here&#8217;s what our simple text input validation function will look like:</p>
<p><code><span style="color: #0000ff;">function</span> validateTextInput<span style="color: #000099;">(</span>$str, $minLength<span style="color: #0000ff;">=</span><span style="color: #ff0000;">1</span><span style="color: #000099;">) {</span><br />
&nbsp; &nbsp;<span style="color: #006600;">if</span> <span style="color: #000099;">(</span><span style="color: #0000ff;">strlen</span><span style="color: #000099;">(</span>$str<span style="color: #000099;">)</span> <span style="color: #0000ff;">&lt;</span> $minLength<span style="color: #000099;">) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;$lValid <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">'n'</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span> <span style="color: #006600;">else</span> <span style="color: #000099;">{</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;$lValid <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">'y'</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span><br />
&nbsp; &nbsp;<span style="color: #006600;">return</span> $lValid;<br />
<span style="color: #000099;">}</span></code></p>
<p>For the email validation function, we&#8217;ll simply pass in the value to check as the one and only argument.  Inside the function, the conditional logic checks the value against the aforementioned regular expression.  And, like the text input validation function above, this one also returns a &#8216;y&#8217; or &#8216;n&#8217; value telling us whether or not the value is valid.  Here&#8217;s what our email validation function will look like:</p>
<p><code><span style="color: #0000ff;">function</span> validateEmail<span style="color: #000099;">(</span>$str<span style="color: #000099;">) {</span><br />
&nbsp; &nbsp;<span style="color: #006600;">if</span> <span style="color: #000099;">(</span><span style="color: #0000ff;">!eregi</span><span style="color: #000099;">(</span><span style="color: #cc0000;">"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"</span>, $str<span style="color: #000099;">)) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;$lValid <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">'n'</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span> <span style="color: #006600;">else</span> <span style="color: #000099;">{</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;$lValid <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">'y'</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span><br />
&nbsp; &nbsp;<span style="color: #006600;">return</span> $lValid;<br />
<span style="color: #000099;">}</span></code></p>
<h4>Step 3: Add PHP Function for Overall Form Validation</h4>
<p>Now that we have set up the individual form field validation functions, we&#8217;ll need a master function that will be called when the user clicks the Submit button.  It will validate all of our fields, and will hold logic to either show an error or send the form.  Here&#8217;s what the function will look like.  An explanation of the function is below the function.</p>
<p><code><span style="color: #0000ff;">function</span> validateForm<span style="color: #000099;">() {</span><br />
&nbsp; &nbsp;$default_error <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">"There was a problem with your entry. Please correct the following fields."</span>;<br />
&nbsp; &nbsp;$error <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">""</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #999999;">// Set up global variables to check</span><br />
&nbsp; &nbsp;<span style="color: #006600;">global</span> $user_name;<br />
&nbsp; &nbsp;<span style="color: #006600;">global</span> $user_email;<br />
&nbsp; &nbsp;<span style="color: #006600;">global</span> $user_message;<br />
<br />
&nbsp; &nbsp;<span style="color: #999999;">// Perform validation for fields</span><br />
&nbsp; &nbsp;$valid_user_name <span style="color: #0000ff;">=</span> validateTextInput<span style="color: #000099;">(</span>$user_name, <span style="color: #ff0000;">1</span><span style="color: #000099;">)</span>;<br />
&nbsp; &nbsp;$valid_user_email <span style="color: #0000ff;">=</span> validateEmail<span style="color: #000099;">(</span>$user_email<span style="color: #000099;">)</span>;<br />
&nbsp; &nbsp;$valid_user_message <span style="color: #0000ff;">=</span> validateTextInput<span style="color: #000099;">(</span>$user_message, <span style="color: #ff0000;">5</span><span style="color: #000099;">)</span>;<br />
<br />
&nbsp; &nbsp;<span style="color: #006600;">if</span> <span style="color: #000099;">(</span>$valid_user_name <span style="color: #0000ff;">!=</span> <span style="color: #cc0000;">'y'</span><span style="color: #000099;">) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;$error <span style="color: #0000ff;">.=</span> <span style="color: #cc0000;">"&lt;li&gt;Your Name&lt;/li&gt;"</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span><br />
&nbsp; &nbsp;<span style="color: #006600;">if</span> <span style="color: #000099;">(</span>$valid_user_email <span style="color: #0000ff;">!=</span> <span style="color: #cc0000;">'y'</span><span style="color: #000099;">) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;$error <span style="color: #0000ff;">.=</span> <span style="color: #cc0000;">"&lt;li&gt;Your Email&lt;/li&gt;"</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span><br />
&nbsp; &nbsp;<span style="color: #006600;">if</span> <span style="color: #000099;">(</span>$valid_user_message <span style="color: #0000ff;">!=</span> <span style="color: #cc0000;">'y'</span><span style="color: #000099;">) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;$error <span style="color: #0000ff;">.=</span> <span style="color: #cc0000;">"&lt;li&gt;Message&lt;/li&gt;"</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span><br />
<br />
&nbsp; &nbsp;<span style="color: #999999;">// Return error value or send form</span><br />
&nbsp; &nbsp;<span style="color: #006600;">if</span> <span style="color: #000099;">(</span>$error<span style="color: #000099;">) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;div class=\"error\"&gt;"</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;label&gt;"</span> . $default_error . <span style="color: #cc0000;">"&lt;/label&gt;"</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;ul&gt;"</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> $error;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;/ul&gt;"</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;/div&gt;"</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span> <span style="color: #006600;">else</span> <span style="color: #000099;">{</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;sendForm<span style="color: #000099;">()</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span><br />
<span style="color: #000099;">}</span></code></p>
<p>First, the function will have two variables: <code>$default_error</code> and <code>$error</code>.  As you noticed, the <code>$default_error</code> has the general text calling out that there&#8217;s an error, and the <code>$error</code> variable is blank by default.</p>
<p>Next, we set up the global variables that we need to check.</p>
<p>Third, we set up a unique variable that will be set to the return value of our individual field validation functions.  After these variables are set up, we put in conditional logic that appends the <code>$error</code> variable with <code>&lt;li&gt;</code> tags if the variable isn&#8217;t set to &#8216;y&#8217;.</p>
<p>Finally, there is conditional logic that checks the <code>$error</code> variable.  If this variable is set to anything other than its default blank value, we echo out some HTML markup that writes out our <code>$default_error</code> message, and then lists out each individual form field that is invalid.  If the variable is still blank, we call the <code>sendForm()</code> function (not included in this article &#8211; you can write that out depending on the needs of your project).</p>
<h4>Step 4: Add Markup and Logic for Submit and Reset Button Actions</h4>
<p>Now that we have everything set up, we obviously need to be able to call our validation and reset functions, based on what button the user clicks.  I am a fan of putting this logic inside of a <code>&lt;div&gt;</code> tag at the top of the form.  Since the validation function echos out a message if invalid, it will thus echo out to a div tag that we can style however we want.  Same with the reset logic, as we will first display a &#8220;are you sure you want to reset?&#8221; message with a &#8216;Yes&#8217; and &#8216;No&#8217; button.  Here&#8217;s the markup we&#8217;ll insert for this logic, that we&#8217;ll place between the opening <code>&lt;form&gt;</code> tag and the first <code>&lt;label&gt;</code>.</p>
<p><code><span style="color: #999999;">&lt;!-- Error Message --&gt;</span><br />
<span style="color: #000099;">&lt;div id=</span><span style="color: #0000ff;">"error-message"</span><span style="color: #000099;">&gt;</span><br />
&nbsp; &nbsp;<span style="color: #ff0000;">&lt;?php</span><br />
&nbsp; &nbsp;<span style="color: #006600;">if</span> <span style="color: #000099;">(</span><span style="color: #0066ff;">$_POST</span><span style="color: #000099;">[</span><span style="color: #cc0000;">"submit"</span><span style="color: #000099;">]) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;setVariables<span style="color: #000099;">()</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;validateForm<span style="color: #000099;">()</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span><br />
&nbsp; &nbsp;<span style="color: #ff0000;">?&gt;</span><br />
<span style="color: #000099;">&lt;/div&gt;</span></code></p>
<p><code><span style="color: #999999;">&lt;!-- Reset Confirmation Message --&gt;</span><br />
<span style="color: #000099;">&lt;div id=</span><span style="color: #0000ff;">"confirm-reset"</span><span style="color: #000099;">&gt;</span><br />
&nbsp; &nbsp;<span style="color: #ff0000;">&lt;?php</span><br />
&nbsp; &nbsp;<span style="color: #006600;">if</span> <span style="color: #000099;">(</span><span style="color: #0000ff;">isset</span><span style="color: #000099;">(</span><span style="color: #0066ff;">$_POST</span><span style="color: #000099;">[</span><span style="color: #cc0000;">'reset'</span><span style="color: #000099;">])) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;setVariables<span style="color: #000099;">()</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;div class=\"confirm\"&gt;"</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;label&gt;Are you sure you want to reset?&lt;/label&gt;"</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;div class=\"hidden\"&gt;&lt;br /&gt;&lt;/div&gt;"</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;input type=\"submit\" class=\"button\" name=\"reset-yes\" value=\"Yes\" /&gt;"</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;div style=\"display:inline; width:16px;\"&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;"</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;input type=\"submit\" class=\"button\" name=\"reset-no\" value=\"No\" /&gt;"</span>;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"&lt;/div&gt;"</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span> <span style="color: #006600;">else if</span> <span style="color: #000099;">(</span><span style="color: #0000ff;">isset</span><span style="color: #000099;">(</span><span style="color: #0066ff;">$_POST</span><span style="color: #000099;">[</span><span style="color: #cc0000;">'reset-no'</span><span style="color: #000099;">])) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;setVariables<span style="color: #000099;">()</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span> <span style="color: #006600;">else if</span> <span style="color: #000099;">(</span><span style="color: #0000ff;">isset</span><span style="color: #000099;">(</span><span style="color: #0066ff;">$_POST</span><span style="color: #000099;">[</span><span style="color: #cc0000;">'reset-yes'</span><span style="color: #000099;">])) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;resetVariables<span style="color: #000099;">()</span>;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span><br />
&nbsp; &nbsp;<span style="color: #ff0000;">?&gt;</span><br />
<span style="color: #000099;">&lt;/div&gt;</span></code></p>
<p>As you see, the error message <code>&lt;div&gt;</code> tag has conditional logic that checks for <code><span style="color: #0066ff;">$_POST</span>[<span style="color: #cc0000;">"submit"</span>]</code>.  If our submit button is clicked, the two functions inside this conditional statement are fired off.  First, we call the <code>setVariables()</code> function, which as outlined above, sets all of our global PHP variables to the value of the form fields.  After we have called this function, we call our <code>validateForm()</code> function that validates each field and checks whether to display an error message or send the form.</p>
<p>The reset <code>&lt;div&gt;</code> tag is a bit more detailed.  Our form &#8216;Reset&#8217; button is set up with name &#8216;reset&#8217;, which is equivalent to <code><span style="color: #0066ff;">$_POST</span>[<span style="color: #cc0000;">'reset'</span>]</code>.  This is the first check of our conditional logic here, which calls the <code>setVariables()</code>, and echos out a <code>&lt;div&gt;</code> tag with the reset confirmation message and accompanying &#8216;Yes&#8217; and &#8216;No&#8217; buttons.</p>
<p>The second and third checks of the reset conditional logic check for the &#8216;Yes&#8217; and &#8216;No&#8217; button clicks.  If the &#8216;No&#8217; button is clicked, we simply call the <code>setVariables()</code> function.  If the &#8216;Yes&#8217; button is clicked, we call the <code>resetVariables()</code> function which as outlined above, resets all variables and therefore erases the form field values.</p>
<h4>Wrapping It Up</h4>
<p>As I mentioned at the beginning of the article, this is useful because all of the logic is done with PHP, and can thus be used on any browser and device, regardless of how the settings are configured.  What I like to do is to put all of the logic in its own file, and then include it in the page wherever I need it.  That way, if I have a completely separate set of files for full web vs. mobile, for instance, I can still use the same one file that contains the form, and style it with CSS depending on what version of the site the user is seeing.</p>
<p>Also, at this point, feel free to add in your own CSS and/or other HTML markup for how the form is set up and will be displayed.</p>
<p>Also, since there&#8217;s A LOT of code and logic here, I have gone ahead and packaged up the files in a zip file that you can download for your convenience.  The zip file includes some sample CSS styles that I have set up to customize the look of the form.</p>
<p>Until next time, happy coding!</p>
<p><a title="Download Source Files" href="http://www.hesslerdesign.com/blog/wp-content/uploads/2010/08/hd_php_form.zip"><img class="alignleft size-full wp-image-572" title="Download Source Files" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2010/08/btn_downloadSourceFiles.png" alt="" width="176" height="29" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/tutorials/bulletproof-your-online-forms-for-mobile-devices-with-php-%e2%80%93-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bulletproof Your Online Forms for Mobile Devices with PHP &#8211; Part 1</title>
		<link>http://www.hesslerdesign.com/blog/tutorials/bulletproof-your-online-forms-for-mobile-devices-with-php-part-1/</link>
		<comments>http://www.hesslerdesign.com/blog/tutorials/bulletproof-your-online-forms-for-mobile-devices-with-php-part-1/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 16:09:28 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[validation]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=541</guid>
		<description><![CDATA[The more popular mobile devices get, the more reason there is to be cautious and deliberate when creating your website. While there are a bevy of issues in dealing with creating mobile-friendly sites, the one I’d like to focus on here is building out an HTML form. More specifically, since some mobile devices don’t have [...]]]></description>
			<content:encoded><![CDATA[<p>The more popular mobile devices get, the more reason there is to be cautious and deliberate when creating your website. While there are a bevy of issues in dealing with creating mobile-friendly sites, the one I’d like to focus on here is building out an HTML form. More specifically, since some mobile devices don’t have JavaScript enabled (either by default or by choosing, either way done to increase speed on your device), it’s not necessarily good to rely on JavaScript validation for your forms. And, since most current mobile devices aren’t Flash-friendly either (thank you Steve Jobs), the best method in creating a form is using HTML, styled with CSS, and using PHP for validation and processing.</p>
<p>With that said, here’s part 1 of how to build a bulletproof form using only HTML, PHP and CSS.</p>
<h4>Step 1: Plan Your Form</h4>
<p>This first step is important when building out a form.  Rather than just jumping in and starting to throw together a form, it&#8217;s helpful (and a big time-saver) to plan out what fields your form will have, and what types of fields they will be.  I find it helpful to either jot this info down on a piece of paper, or write it in pseudo-code inside of a comment block in my working file.  Either way, plan your form fields first.  It will make life much easier as you build out the form, and eventually its validation and processing.</p>
<p>For this tutorial, we&#8217;ll build out a form with three fields: Name, Email, and Message.  The form will also have a Submit and Reset button for form processing and resetting.</p>
<h4>Step 2: Create PHP Variables for Each Form Field Value</h4>
<p>Now that we have the form architecture figured out, we need to assign a PHP variable to each form field.  In our example, this means we’ll need 3 variables.  So at the very top of our file, inside of the PHP wrapper tags (<strong><span style="color: #ff0000;"><code>&lt;?php ?&gt;</code></span></strong>), create a variable for each.  In our example, it will look like this:</p>
<p><code><strong><span style="color: #ff0000;">&lt;?php</span></strong><br />
$user_name <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">""</span>;<br />
$user_email <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">""</span>;<br />
$user_message <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">""</span>;<br />
<strong><span style="color: #ff0000;">?&gt;</span></strong></code></p>
<p><em>Note: This step could be swapped with step #3 below, but for the sake of  brevity in this tutorial, I&#8217;m putting it here so we can plug these  variable values directly in the form fields when we build out the form  in step #3.</em></p>
<p><span id="more-541"></span></p>
<h4>Step 3: Build Out the Form</h4>
<p>This step is simple, as we just need to put together the pure HTML code for our form.  Our form will have two <code>input</code> fields and one <code>textarea</code> (for the message).  While assembling the code, I&#8217;m going to insert some extra <code>&lt;div&gt;</code> and <code>&lt;span&gt;</code> tags that are inserted to break up the form into containers in the absence of CSS.  This is done as a precaution for mobile devices that are not set up to enable CSS.  Many times the default is okay, but I&#8217;ve noticed that here and there, you need to hammer it down a little bit.</p>
<p>Another important thing that we&#8217;ll do here is to set the value of each form field to its accompanying PHP variable.  This is a setup step that will ensure that our form will &#8220;remember&#8221; its values, should any of the form fields fail in the validation process (still to come).  You know what I mean here – we’ve all been there – you fill out a long form, submit, and find out that the form is somehow invalid, and all of the form fields are blank again, forcing you to refill the entire thing all over again.  Frustrating, isn’t it?</p>
<p>This is actually much easier than you might think using PHP.  For the <code>input</code> fields, it’s a simple matter of echoing out the PHP variable inside of the ‘value’ attribute of the tag.  For the <code>textarea</code>, you’ll need to echo out the PHP variable between the opening and closing tags.  And don’t worry – since our PHP variables are set as empty strings by default, the fields will also be empty when the form initially loads.  But as the form and validation logic get built out, our PHP variables are set to match the form fields, and thus the form fields will be populated with the &#8220;remembered&#8221; value of the field (stored in the variables) rather than being blank.</p>
<p>In our example, our form looks a little something like this:</p>
<p><code><span style="color: #ff9900;">&lt;form action=</span><span style="color: #0000ff;">""</span> <span style="color: #ff9900;">method=</span><span style="color: #0000ff;">"post"</span> <span style="color: #ff9900;">name=</span><span style="color: #0000ff;">"contact_form"</span> <span style="color: #ff9900;">id=</span><span style="color: #0000ff;">"contact_form"</span><span style="color: #ff9900;">&gt;</span><br />
&nbsp; &nbsp;<span style="color: #000099;">&lt;div&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #ff9900;">&lt;label for=</span><span style="color: #0000ff;">"user_name"</span><span style="color: #ff9900;">&gt;</span>Your Name:<span style="color: #ff9900;">&lt;/label&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #000099;">&lt;span class=</span><span style="color: #0000ff;">"hidden"</span><span style="color: #000099;">&gt;&lt;br /&gt;&lt;/span&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #ff9900;">&lt;input type=</span><span style="color: #0000ff;">"text"</span> <span style="color: #ff9900;">name=</span><span style="color: #0000ff;">"user_name"</span> <span style="color: #ff9900;">value=</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;">&lt;?php</span> <span style="color: #0000ff;">echo</span> $user_name; <span style="color: #ff0000;">?&gt;</span><span style="color: #0000ff;">"</span> <span style="color: #ff9900;">autocomplete=</span><span style="color: #0000ff;">"off"</span> <span style="color: #ff9900;">tabindex=</span><span style="color: #0000ff;">"1"</span> <span style="color: #ff9900;">/&gt;</span><br />
&nbsp; &nbsp;<span style="color: #000099;">&lt;/div&gt;</span><br />
&nbsp; &nbsp;<span style="color: #000099;">&lt;div&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #ff9900;">&lt;label for=</span><span style="color: #0000ff;">"user_email"</span><span style="color: #ff9900;">&gt;</span>Your Email:<span style="color: #ff9900;">&lt;/label&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #000099;">&lt;span class=</span><span style="color: #0000ff;">"hidden"</span><span style="color: #000099;">&gt;&lt;br /&gt;&lt;/span&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #ff9900;">&lt;input type=</span><span style="color: #0000ff;">"text"</span> <span style="color: #ff9900;">name=</span><span style="color: #0000ff;">"user_email"</span> <span style="color: #ff9900;">value=</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;">&lt;?php</span> <span style="color: #0000ff;">echo</span> $user_email; <span style="color: #ff0000;">?&gt;</span><span style="color: #0000ff;">"</span> <span style="color: #ff9900;">autocomplete=</span><span style="color: #0000ff;">"off"</span> <span style="color: #ff9900;">tabindex=</span><span style="color: #0000ff;">"2"</span> <span style="color: #ff9900;">/&gt;</span><br />
&nbsp; &nbsp;<span style="color: #000099;">&lt;/div&gt;</span><br />
&nbsp; &nbsp;<span style="color: #000099;">&lt;div&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #ff9900;">&lt;label for=</span><span style="color: #0000ff;">"user_message"</span><span style="color: #ff9900;">&gt;</span>Message:<span style="color: #ff9900;">&lt;/label&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #000099;">&lt;span class=</span><span style="color: #0000ff;">"hidden"</span><span style="color: #000099;">&gt;&lt;br /&gt;&lt;/span&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #ff9900;">&lt;textarea name=</span><span style="color: #0000ff;">"user_message"</span> <span style="color: #ff9900;">autocomplete=</span><span style="color: #0000ff;">"off"</span> <span style="color: #ff9900;">wrap=</span><span style="color: #0000ff;">"physical"</span> <span style="color: #ff9900;">tabindex=</span><span style="color: #0000ff;">"3"</span><span style="color: #ff9900;">&gt;</span><span style="color: #ff0000;">&lt;?php</span> <span style="color: #0000ff;">echo</span> $user_message; <span style="color: #ff0000;">?&gt;</span><span style="color: #ff9900;">&lt;/textarea&gt;</span><br />
&nbsp; &nbsp;<span style="color: #000099;">&lt;/div&gt;</span><br />
&nbsp; &nbsp;<span style="color: #000099;">&lt;div class=</span><span style="color: #0000ff;">"centered"</span><span style="color: #000099;">&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #ff9900;">&lt;input type=</span><span style="color: #0000ff;">"submit"</span> <span style="color: #ff9900;">name=</span><span style="color: #0000ff;">"submit"</span> <span style="color: #ff9900;">value=</span><span style="color: #0000ff;">"Submit &amp;raquo;"</span> <span style="color: #ff9900;">/&gt;</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #ff9900;">&lt;input type=</span><span style="color: #0000ff;">"submit"</span> <span style="color: #ff9900;">name=</span><span style="color: #0000ff;">"reset"</span> <span style="color: #ff9900;">value=</span><span style="color: #0000ff;">"Reset Form"</span> <span style="color: #ff9900;">/&gt;</span><br />
&nbsp; &nbsp;<span style="color: #000099;">&lt;/div&gt;</span><br />
<span style="color: #ff9900;">&lt;/form&gt;</span></code></p>
<p>A few important notes about the form setup:</p>
<ul>
<li>We didn&#8217;t include any value in the action attribute for the form tag.  This is because we&#8217;re going to house all of the form logic within the same file to reduce page-to-page navigation, and the amount of external files we need to concern ourselves with.  There are different schools of thought about this, but this is the method we&#8217;ll use for this tutorial.</li>
<li>As discussed above, PHP markup has been inserted into the form fields as their values.</li>
<li>Each form field tag has a unique name.  This will be necessary when we start to set/reset variables and validate the form later on down the road.</li>
<li>Each form field is set up here with the autocomplete attribute set to &#8220;off&#8221;. This is just more of a security precaution that I like on contact forms, that makes it so the browser doesn&#8217;t remember previous values you&#8217;ve typed in other forms, in the case that you&#8217;re using a public computer that doesn&#8217;t delete private browsing history.  <em>(Note: This doesn&#8217;t have anything to do with the method we&#8217;re using to echo out our PHP variables into the form, as our PHP variable method will simply keep our values in the form upon unsuccessful form submission, whereas the autocomplete attribute would have a dropdown of &#8220;remembered&#8221; values of past forms when the user starts typing.)</em></li>
<li>Overall, I&#8217;ve included a number of ids and classes in the form that will be later used to style it with CSS for browsers and mobile devices that have CSS enabled.</li>
</ul>
<h4>What&#8217;s Next</h4>
<p>We now have the framework for our form, and have set up some of the initial PHP logic to help us populate and store form values.  In the next segment, we&#8217;ll work on adding in the variable setting/resetting functionality, as well as the validation functions.  Also, and most importantly, we&#8217;ll tie in the Submit and Reset buttons with the correct functionality to make the form do what it&#8217;s supposed to do.</p>
<p>Until the next part of this tutorial, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/tutorials/bulletproof-your-online-forms-for-mobile-devices-with-php-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Look Mom, No Flash!</title>
		<link>http://www.hesslerdesign.com/blog/web-design/look-mom-no-flash/</link>
		<comments>http://www.hesslerdesign.com/blog/web-design/look-mom-no-flash/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 18:27:02 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=500</guid>
		<description><![CDATA[Whew!  It&#8217;s been far too long since my last ramblings on the blog here.  And c&#8217;mon&#8230;what&#8217;s up with that title?  No Flash?  Don&#8217;t worry, I&#8217;m not turning anti-Flash like Steve Jobs or anything.  Heck, I continue to do a ton of Flash development work, and seriously enjoy doing it.  No, it&#8217;s nothing like that.  It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Whew!  It&#8217;s been far too long since my last ramblings on the blog here.  And c&#8217;mon&#8230;what&#8217;s up with that title?  No Flash?  Don&#8217;t worry, I&#8217;m not turning anti-Flash like Steve Jobs or anything.  Heck, I continue to do a ton of Flash development work, and seriously enjoy doing it.  No, it&#8217;s nothing like that.  It&#8217;s just that I&#8217;ve just launched an updated version of <a title="Hessler Design - Home" href="http://www.hesslerdesign.com/" target="_self">HesslerDesign.com</a> that includes no Flash elements in the main framework of the site (minus the a few entries in the <a title="Hessler Design - Work" href="http://www.hesslerdesign.com/">Work</a> section, and of course excluding the blog section, because I write about Flash quite a bit as you can probably tell).</p>
<p>Why, you ask?</p>
<p>As time goes on, I&#8217;m finding myself drawing closer and closer to sticking close to pure HTML/CSS code, with other standards-compliant languages like PHP/MySQL and JavaScript.  Not to say Flash and it&#8217;s programming language (ActionScript) isn&#8217;t compliant with anything.  I had simply found myself doing things in Flash by default because it&#8217;s what I was most comfortable with, and could do with the least amount of technical issues.</p>
<p>But, now that I&#8217;ve been exploring more uses for JavaScript in place of what would normally be Flash code, it&#8217;s easier and easier to pull myself away from Flash.  Plus, as I&#8217;ve been doing more and more dynamic code content with PHP, I&#8217;m finding myself a lot more excited about using PHP than I am about using Flash.  I still enjoy Flash, and don&#8217;t get me wrong &#8212; there are definitely times and places for Flash.  But for where I&#8217;m at now, I am finding that my own site doesn&#8217;t currently need to rely on Flash so much.</p>
<p>Outside of the programming techniques used for the most recent release of the site, I felt like it was definitely the time for a change regarding the design of the site.  The new design has a much more sophisticated simplicity and clean look than the old version. It&#8217;s focus is more on the projects and artwork, as they take a very prominent position on the <a title="Hessler Design - Work" href="http://www.hesslerdesign.com/" target="_self">Work</a> page with only the project details to accompany them.  No fluff content just to fill in space and give users something else to read.  Only the necessities.</p>
<p>With that all said, I hope you enjoy the newest iteration of HesslerDesign.com.  If you haven&#8217;t already, check out the <a title="Hessler Design - Work" href="http://www.hesslerdesign.com/" target="_self">Work</a> page, which has a few new projects listed that I&#8217;ve completed recently.  I hope you like what you see.</p>
<p>Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/web-design/look-mom-no-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Life on the Edge: Making Your Website Span to the Edge of the Browser Window</title>
		<link>http://www.hesslerdesign.com/blog/web-design/life-on-the-edge-making-your-website-span-to-the-edge-of-the-browser-window/</link>
		<comments>http://www.hesslerdesign.com/blog/web-design/life-on-the-edge-making-your-website-span-to-the-edge-of-the-browser-window/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 15:15:14 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[stylesheet]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=490</guid>
		<description><![CDATA[Here&#8217;s an oldie, but a goodie.  One of the questions I get a lot is, &#8220;Why isn&#8217;t my website reaching all the way to the edge of the browser window, and how do I get it to do that?&#8221;  Well, the answer is very simple, and it&#8217;s easily taken care of with one line of [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an oldie, but a goodie.  One of the questions I get a lot is, &#8220;Why isn&#8217;t my website reaching all the way to the edge of the browser window, and how do I get it to do that?&#8221;  Well, the answer is very simple, and it&#8217;s easily taken care of with one line of CSS code.</p>
<p>In your CSS code, simply assign the following:</p>
<p><span style="margin-left: 24px; margin-right: 24px;"><code>html body {margin:0px; padding:0px}</code></span></p>
<p>That&#8217;s it. Seriously. By default, most (I hesitate to say all) browsers have a built in 10px or so padding around the edge of the window. By setting your html and body to have no margin or padding, it effectively overwrites the browser default values and uses yours.</p>
<p>While you&#8217;re at it, you might also be wondering how you can center your main container in the browser window, instead of having it left-justified.  This too is easy to implement with one snippet of CSS.  Let&#8217;s go ahead and assume that your main div container has the ID &#8220;container&#8221;. Your CSS code to center the div &#8220;container&#8221; will be:</p>
<p><span style="margin-left: 24px; margin-right: 24px;"><code>#container {margin: 0 auto; width:960px;}</code></span></p>
<p>Notice that in this example, you need to fix your width to a certain value so the container knows not to take up 100%. The margin setting &#8220;0 auto&#8221; tells the container to have a margin of 0 (zero) pixels on top and bottom, with auto margins on the left and  right.</p>
<p>So there you have it. Two basic CSS rules to make your page go all the way up to the edge of the browser window, and to center your main container in the window.</p>
<p>Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/web-design/life-on-the-edge-making-your-website-span-to-the-edge-of-the-browser-window/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making Your WordPress Menu Items Smarter</title>
		<link>http://www.hesslerdesign.com/blog/tutorials/making-your-wordpress-menu-items-smarter/</link>
		<comments>http://www.hesslerdesign.com/blog/tutorials/making-your-wordpress-menu-items-smarter/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 19:20:55 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[themes]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=270</guid>
		<description><![CDATA[In my current work with designing my custom WordPress theme for this blog, I came up with a few nifty little tricks to make the theme smarter. One particular thing I found tricky was how to make the top nav (or any nav, for that matter) menu items smart enough to be classified as &#8220;active&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>In my current work with designing my custom WordPress theme for this blog, I came up with a few nifty little tricks to make the theme smarter. One particular thing I found tricky was how to make the top nav (or any nav, for that matter) menu items smart enough to be classified as &#8220;active&#8221; if the user was on a page in a given section. My answer came in a nice little solution called Page Templates, and a built-in function called <a title="WordPress Codex - Conditional Tags" href="http://codex.wordpress.org/Conditional_Tags#Is_a_Page_Template" target="_blank"><code>is_page_template()</code></a>.</p>
<h4>Step 1: Create a New Page Template</h4>
<p>If you&#8217;re familiar with WordPress, you may know that you can create Page Templates that differ from the &#8220;index.php&#8221; page template. All you need to do when creating a new Page Template is save your new file as a unique file name (with a few exceptions) in your Theme directory, and put the following code at the top of the file:</p>
<div style="margin-left:24px; color:#f90;"><code>&lt;?php<br />
/*<br />
Template Name: My Cool Template<br />
*/<br />
?&gt;</code></div>
<p>This little snippet of code defines your file as &#8220;My Cool Template&#8221;, or whatever template name you give it. There&#8217;s plenty more about making Page Templates at the <a title="WordPress Codex - Creating Your Own Page Templates" href="http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates" target="_blank">WordPress Codex, in the Pages section</a>.</p>
<h4>Step 2: Assign a Page Template to a Page</h4>
<p>Once you&#8217;ve got your page templates set up, you can assign a specific page template to one of your pages in the &#8216;Pages&#8217; section of your WordPress Admin. All that you need to do is get into &#8216;Edit&#8217; mode for a page, then in the &#8216;Attributes&#8217; section on the right, select your template under the &#8216;Template&#8217; section. It&#8217;s that easy. (If you want more info on different page attributes that can be set, check out <a title="WordPress Support - Page Attributes" href="http://en.support.wordpress.com/pages/page-attributes/" target="_blank">WordPress Support for Page Attributes</a>.)</p>
<h4>Step 3: Update the Menu List Items</h4>
<p>Once the page templates have been set up, it&#8217;s time to set up the top nav list items to be smart enough to be classified  as &#8220;active&#8221; if the page being viewed is an instance of that page template.</p>
<p>(<em>Note: When I was creating my custom template, I hard-coded my nav links because I knew exactly what links I wanted to have, and because I wasn&#8217;t interested in my theme being shared and used by others. With that said, the logic below may need to be edited if used for a template whose navigation is built dynamically.</em>)</p>
<p>In the code where the navigation items are built, I initially had the following syntax used for each menu item:</p>
<div style="margin-left:24px; margin-bottom:18px;"><code><span style="color: #000099;">&lt;li&gt;</span><span style="color: #006600;">&lt;a href=</span><span style="color: #0000ff;">"</span><span style="color: #ff0000;">&lt;?php</span> bloginfo<span style="color: #000099;">(</span><span style="color: #cc0000;">'url'</span><span style="color: #000099;">)</span>; <span style="color: #ff0000;">?&gt;</span><span style="color: #0000ff;">/mysection/"</span><span style="color: #006600;">&gt;</span>My Section<span style="color: #006600;">&lt;/a&gt;</span><span style="color: #000099;">&lt;/li&gt;</span></code></div>
<p>This is your standard menu list item syntax for a menu item that&#8217;s hard-coded. It&#8217;s smart to use the <a title="WordPress Codex - Blog Info" href="http://codex.wordpress.org/Template_Tags/bloginfo#Parameters" target="_blank"><code>bloginfo('url')</code></a> function inside of the <code>href</code> to get the URL of your blog, and then append any additional directories to the end (if needed). This way, if you switch URLs, or do end up sharing the theme with others, it won&#8217;t be hard-coded to just one URL. But each <code>&lt;li&gt;</code> tag needs to have the ability to be appended with <code>class="active"</code> if the page being viewed is on a page with a given page template. For that, we need to add in another function (is_page_template()), and wrap it inside of a conditional statement:</p>
<div style="margin-left:24px; margin-bottom:18px;"><code><span style="color: #000099;">&lt;li</span> <span style="color: #ff0000;">&lt;?php</span> <span style="color: #006600;">if</span><span style="color: #000099;">(</span>is_page_template<span style="color: #000099;">(</span><span style="color: #cc0000;">'my_cool_template.php'</span><span style="color: #000099;">))</span> <span style="color: #0000ff;">:</span> <span style="color: #ff0000;">?&gt;</span> <span style="color: #000099;">class=</span><span style="color: #0000ff;">"active"</span> <span style="color: #ff0000;">&lt;?php</span> <span style="color: #006600;">endif</span>; <span style="color: #ff0000;">?&gt;</span>&gt;<span style="color: #006600;">&lt;a href=</span>"<span style="color: #ff0000;">&lt;?php</span> bloginfo<span style="color: #000099;">(</span><span style="color: #cc0000;">'url'</span><span style="color: #000099;">)</span>; <span style="color: #ff0000;">?&gt;</span><span style="color: #0000ff;">/mysection/"</span><span style="color: #006600;">&gt;</span>My Section<span style="color: #006600;">&lt;/a&gt;</span><span style="color: #000099;">&lt;/li&gt;</span></code></div>
<div style="margin-bottom:6px;">In the code above, we added the PHP logic:</div>
<div style="margin-left:24px; margin-top:0px; margin-bottom:12px;"><code><span style="color: #ff0000;">&lt;?php</span> <span style="color: #006600;">if</span> <span style="color: #000099;">(</span>is_page_template<span style="color: #000099;">(</span><span style="color: #cc0000;">'my_cool_template.php'</span><span style="color: #000099;">))</span> <span style="color: #0000ff;">:</span> <span style="color: #ff0000;">?&gt;</span> <span style="color: #ff0000;">&lt;?php</span> <span style="color: #006600;">endif</span>; <span style="color: #ff0000;">?&gt;</span></code></div>
<div style="margin-bottom:6px;">And then, between the blocks of PHP code, we add the &#8216;active&#8217; class to assign to the list item:</div>
<div style="margin-left:24px; margin-bottom:18px; margin-top:0px;"><code><span style="color: #000099;">class=</span><span style="color: #0000ff;">"active"</span></code></div>
<p>The <a title="WordPress Codex - Conditional Tags" href="http://codex.wordpress.org/Conditional_Tags#Is_a_Page_Template" target="_blank"><code>is_page_template()</code></a> function checks the page against the file name of the template passed into it. When used inside a conditional statement, it will return a <code>true</code> or <code>false</code> value, depending on whether or not the page being viewed uses that template. And after applying this &#8220;active&#8221; logic to our list items, and as long as the CSS file has a style for linked list items classified as active (i.e. <code>li.active a</code>), any list item whose conditional statement returns a true will have the &#8216;active&#8217; class assigned to it.</p>
<h4>That&#8217;s a Wrap</h4>
<p>So there you have it. A simple bit of conditional logic (assuming you&#8217;re decently familiar with PHP) that you can put into your menu list items so the links can be classified according to the page being viewed. Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/tutorials/making-your-wordpress-menu-items-smarter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making Your Flash Application Communicate with the Outside World</title>
		<link>http://www.hesslerdesign.com/blog/flash/making-your-flash-application-communicate-with-the-outside-world/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/making-your-flash-application-communicate-with-the-outside-world/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 22:14:15 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=181</guid>
		<description><![CDATA[I&#8217;ve recently been working on a number of Flash sites that require communication back and forth between the Flash SWF file and the parent HTML page. This is relatively easy to do, but includes a few &#8220;gotcha&#8217;s&#8221; that should be addressed. Below is a list of items that you will need to make sure you [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been working on a number of Flash sites that require communication back and forth between the Flash SWF file and the parent HTML page.  This is relatively easy to do, but includes a few &#8220;gotcha&#8217;s&#8221; that should be addressed. Below is a list of items that you will need to make sure you follow that will make your Flash be able to communicate with the outside world, and vice-versa.<br /><span id="more-181"></span></p>
<h4>Step 1: Embed your Flash SWF file in your HTML page</h4>
<p>When embedding your SWF file, give your <code>object</code> tags the same <code>id</code> and <code>name</code>.  Your non-Internet Explorer <code>object</code> tag should have the <code>id</code>, and your IE <code>object</code> tag should have the name. And again, both should be set to the same value. (In this example, these attributes are set to &#8220;helloSWF&#8221;.) Additionally, you need to set the <code>allowScriptAccess</code> attribute of your Flash object to either &#8220;sameDomain&#8221; or &#8220;always&#8221;.  Without this attribute set, you won&#8217;t be able to have Flash communicate with the HTML file.  At a basic level, the <code>object</code> tag will need to look something like this:</p>
<p><a href="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/11/flashJS_htmlObjectCode1.gif"><img src="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/11/flashJS_htmlObjectCode1.gif" alt="flashJS_htmlObjectCode" title="flashJS_htmlObjectCode" width="542" height="181" class="aligncenter size-full wp-image-232" /></a></p>
<div style="display:block; height:20px; clear:both;"></div>
<h4>Step 2: Write a JavaScript function that targets and calls to Flash</h4>
<p>There must be a JavaScript function that acts as the mediator between HTML and your Flash SWF file. In this JS function, you need to access the SWF file.  This is done by referencing the <code>id/name</code> (see step 1).  In its simplest form, this JS function should look something like this:</p>
<p>
<code><strong>function</strong> jsSayHello<span style="color: #000099;">() {</span><br />
&nbsp; &nbsp;<span style="color: #000099;">var</span> mySWF;<br />
&nbsp; &nbsp;mySWF = <span style="color: #990099;">document</span>.helloSWF;<br />
&nbsp; &nbsp;<span style="color: #000099;">if (</span><span style="color: #0000FF;">!</span>mySWF<span style="color: #000099;">) {</span><br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #990099;">window</span>.helloSWF;<br />
&nbsp; &nbsp;<span style="color: #000099;">}</span><br />
&nbsp; &nbsp;mySWF.sayHello<span style="color: #000099;">()</span>;<br />
<span style="color: #000099;">}</span></code>
</p>
<p>In this example, you&#8217;ll notice a variable that get set to <code>document.helloSWF</code>.  If you&#8217;re using a browser that doesn&#8217;t recognize the &#8216;<code>document</code>&#8216; syntax, the conditional statement catches it, and uses &#8216;<code>window</code>&#8216; to reference the SWF file. Once the variable is set, you can simply call the function you wish to call in your Flash file by using the syntax &#8220;<code>jsVariable.flashFunctionName()</code>&#8220;.  In our example, this is the line &#8220;<code>mySWF.sayHello<span style="color: #000099;">()</span>;</code>&#8220;.</p>
<div style="display:block; height:20px; clear:both;"></div>
<h4>Step 3: Set functions and ExternalInterface properties in Flash</h4>
<p>In your Flash file, you need to import the <code>ExternalInterface</code> Class, and add a callback that listens for the function being called from outside of the Flash file.  When adding the callback, you also need to specify the function to run in your Flash file when it gets instructed to do so from the outside world.  The code snippet below provides the basic structure of what you&#8217;ll need:</p>
<p>
<code><span style="color: #0000ff;">import flash.external.*</span>;<br />
<span style="color: #0000ff;">ExternalInterface.addCallback</span>(<span style="color: #009900;">'sayHello'</span>, helloWorld);<br />
<span style="color: #0000ff;">function</span> helloWorld():<span style="color: #0000ff;">void</span> {<br />
&nbsp; &nbsp;<span style="color: #bbbbbb;">// Insert actions</span><br />
}</code>
</p>
<p>In this example, you&#8217;ll notice the <code>addCallback</code> accepts two parameters: (1) a String that is the function called from outside of Flash, and (2) a function inside of Flash to run.</p>
<p>If you want to have Flash call out to JavaScript, you can use the <code>ExternalInterface.call</code> method to call a JavaScript function.  For example, if you wanted to call a JS function named &#8220;hiFromFlash&#8221;, the ActionScript code would look something like this:</p>
<p>
<code><span style="color: #0000ff;">ExternalInterface.call</span>(<span style="color: #009900;">'hiFromFlash'</span>);</code>
</p>
<p>If you need to pass parameters, simply add them after the function call, separated by commas.</p>
<div style="display:block; height:20px; clear:both;"></div>
<p>So there you have it. With these three items, you will be all set to have your Flash file be able to receive instructions from its parent file.  Until next time, happy coding!</p>
<p><a href="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/11/AS-JS-Communication.zip">Download source files &raquo;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/making-your-flash-application-communicate-with-the-outside-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using &amp; Formatting HTML Text in Flash</title>
		<link>http://www.hesslerdesign.com/blog/flash/using-formatting-html-text-in-flash/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/using-formatting-html-text-in-flash/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 04:05:41 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[cdata]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[stylesheet]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=74</guid>
		<description><![CDATA[I import XML into my Flash projects a lot. From time to time, the XML will contain special characters that can&#8217;t be rendered by Flash.  Or maybe it will contain text that should act as a hyperlink, or be bold or italic.  Whatever the case may be, there are a few key steps to successfully [...]]]></description>
			<content:encoded><![CDATA[<p>I import XML into my Flash projects a lot. From time to time, the XML will contain special characters that can&#8217;t be rendered by Flash.  Or maybe it will contain text that should act as a hyperlink, or be bold or italic.  Whatever the case may be, there are a few key steps to successfully importing and displaying these special characters and HTML styles.</p>
<p>First, we need to set up the XML file.  In the text editor of your choice, you can begin setting it up by entering the following code:</p>
<p><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;</code><br />
<code>&lt;site&gt;</code><br />
&nbsp; &nbsp;<code>&lt;theItem&gt;&lt;/theItem&gt;</code><br />
<code>&lt;/site&gt;</code></p>
<p>In the code above, we simply set up the main tag, named <code>site</code>, and put another tag named <code>theItem</code> inside of it. (I&#8217;m not going to get into explaining best practices for setting up XML files here. That&#8217;s a topic for another post.)  Inside the <code>theItem</code> tag, we can put our text. I&#8217;ll start by putting one sentence, contained inside of a <code>&lt;p&gt;</code> tag, with <code>&lt;b&gt;</code>, <code>&lt;i&gt;</code>, and <code>&lt;a&gt;</code> HTML tags.</p>
<p><code>&lt;theItem&gt;&lt;p&gt;This is an example of XML text with &lt;b&gt;bold&lt;/b&gt; and &lt;i&gt;italic&lt;/i&gt; words, as well as &lt;a href="#"&gt;hyperlinks&lt;/a&gt;.&lt;/p&gt;&lt;/theItem&gt;</code></p>
<p>Save your XML file as &#8220;text.xml&#8221;.</p>
<p><span id="more-74"></span></p>
<p>Now that we have the XML built, let&#8217;s move over to Adobe Flash and import the XML.  With Adobe Flash open, create a new ActionScript 3.0 file, and make a new dynamic text field and name it &#8220;text_txt&#8221;.  Set the color, font, and size to your own liking.  Then, create a new layer, named Actions, and lock it.  (I always name my ActionScript layer &#8220;Actions&#8221;, lock it, and put it as the top layer.  It&#8217;s a good practice to get into if you don&#8217;t already.)  Save your Flash file in the same directory location as the XML file.</p>
<p>Now, in your Actions panel, type the following code:</p>
<p><code><span style="color: #0000ff;">var</span> theXML:<span style="color: #0000ff;">XML</span>;</code><br />
<code><span style="color: #0000ff;">var</span> xmlData:<span style="color: #0000ff;">Array</span> = <span style="color: #0000ff;">new Array</span>();</code><br />
<code><span style="color: #0000ff;">var</span> loader:<span style="color: #0000ff;">URLLoader</span> = <span style="color: #0000ff;">new URLLoader</span>();</code><br />
<code>loader.<span style="color: #0000ff;">addEventListener</span>(Event.COMPLETE, processXML);</code><br />
<code>loader.<span style="color: #0000ff;">load</span>(<span style="color: #0000ff;">new URLRequest</span>(<span style="color: #009900;">"test.xml"</span>));</code></p>
<p><code><span style="color: #0000ff;">function</span> processXML(e:<span style="color: #0000ff;">Event</span>){</code><br />
&nbsp; &nbsp;<code>theXML = <span style="color: #0000ff;">new XML</span>(e<span style="color: #0000ff;">.target.data</span>);</code><br />
&nbsp; &nbsp;<code><span style="color: #0000ff;">var</span> xmlLength:<span style="color: #0000ff;">Number</span> = theXML.theItem<span style="color: #0000ff;">.length</span>();</code><br />
&nbsp; &nbsp;<code><span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> i=0; i&lt;xmlLength; i++){</code><br />
&nbsp; &nbsp;&nbsp; &nbsp;<code>xmlData[i] = theXML.theItem[i];</code><br />
&nbsp; &nbsp;<code>}</code><br />
&nbsp; &nbsp;<code>text_txt<span style="color: #0000ff;">.text</span> = xmlData[0];</code><br />
&nbsp; &nbsp;<code>text_txt<span style="color: #0000ff;">.multiline</span> = <span style="color: #0000ff;">true</span>;</code><br />
&nbsp; &nbsp;<code>text_txt<span style="color: #0000ff;">.wordWrap</span> = <span style="color: #0000ff;">true</span>;</code><br />
&nbsp; &nbsp;<code>text_txt<span style="color: #0000ff;">.height</span> = text_txt<span style="color: #0000ff;">.textHeight</span> + 6;</code><br />
<code>}</code></p>
<p>Here&#8217;s a quick rundown of what this code does:<br />
- Define a new XML object named <code>theXML</code><br />
- Create a new Array named <code>xmlData</code><br />
- Create a new URLLoader named <code>loader</code>.  This loader then gets an event listener that will fire the function <code>processXML</code> when loading is complete.  To load the XML file, we load a new URLRequest to the path of our XML file (which should be in the same directory as your Flash file.)<br />
- The <code>processXML</code> function then creates our XML object, filling it with the data from the loader.<br />
- Create a number variable containing the length of the XML. This is essential for what&#8217;s coming next.<br />
- Run a <code>for</code> loop starting at 0 and going through the length of the XML object.  This loop populates our Array, <code>xmlData</code>, with each <code>theItem</code> tag from the XML.<br />
- Fill the text field with the text from the first spot in the array (our only tag in this example).<br />
- Set <code>multiline</code> and <code>wordWrap</code> to true so the text won&#8217;t be limited to one line.<br />
- Set the text field height so it includes all of the text, plus a few extra pixels of buffer at the bottom.</p>
<p>Save your Flash file and test your movie.  You&#8217;ll see something very similar to the image below, which isn&#8217;t very appealing yet.</p>
<p><img class="size-full wp-image-77" title="flash_initialImport" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/06/flash_initialImport.gif" alt="Initial Import of XML" width="552" height="152" /></p>
<p>Close the test movie and return to your Actions panel.</p>
<p>In the Actions panel, we&#8217;re going to change the line of code that sets the text in our text field to the array data.  Instead of using <code>text_txt<span style="color:#0000ff;">.text</span></code>, we&#8217;re going to use <code>text_txt<span style="color:#0000ff;>.htmlText</span></code> (see below).  By setting the text field to <code>htmlText</code>, we enable the ability to accept HTML tags and display the results appropriately.</p>
<p><code>text_txt<span style="color: #0000ff;">.htmlText</span> = xmlData[0];</code></p>
<p>Save your Flash file and re-test your movie.  You&#8217;ll notice the results are much nicer, but the lines break up each time there is an HTML tag, as in the image below.  The good news is that the bold and italic tags display the text correctly, and the hyperlink does work.  But there&#8217;s really no way to tell the user that the hyperlink is actually a hyperlink.</p>
<p><img class="size-full wp-image-78" title="flash_textNoStyle" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/06/flash_textNoStyle.gif" alt="Flash Export - Text Unstyled" width="552" height="152" /></p>
<p>Close the test movie and return to your Actions panel once again.</p>
<p>To style our HTML text, we&#8217;re going to need to create a style sheet object and attach it to our text field.  To do this, we can use the following code, placed above our <code>processXML</code> function:</p>
<p><code><span style="color: #0000ff;">var</span> textStyles:<span style="color: #0000ff;">StyleSheet</span> = <span style="color: #0000ff;">new StyleSheet</span>();</code><br />
<code>textStyles<span style="color: #0000ff;">.setStyle</span>(<span style="color: #009900;">"a:link"</span>, {color:<span style="color: #009900;">'#01628b'</span>, textDecoration:<span style="color: #009900;">'underline'</span>});</code><br />
<code>textStyles<span style="color: #0000ff;">.setStyle</span>(<span style="color: #009900;">"a:hover"</span>, {color:<span style="color: #009900;">'#d68402'</span>, textDecoration:<span style="color: #009900;">'underline'</span>});</code><br />
<code>text_txt<span style="color: #0000ff;">.styleSheet</span> = textStyles;</code></p>
<p>Here, we create a new <code>StyleSheet</code> object, and set styles for <code>&lt;a&gt;</code> tags, based on the correct syntax that Flash uses.  In this example, we assigned a color and underline to our link, and to its hover state.  (For more info on <code>StyleSheets</code>, consult the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/text/StyleSheet.html" target="_blank">Flash documentation on StyleSheets</a>.</p>
<p>Lastly, we set the <code>styleSheet</code> attribute on our text field to our <code>StyleSheet</code> object.</p>
<p>Save your Flash file and re-test your movie again.  Our lines are still broke, but our hyperlink now looks like a hyperlink.  We&#8217;re getting closer.</p>
<p><img class="size-full wp-image-79" title="flash_textStyled" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/06/flash_textStyled.gif" alt="Flash Export - Text Styled" width="552" height="152" /></p>
<p>Close the test movie, and return to your XML file.</p>
<p>Here, we will get to the key to successfully displaying the HTML content correctly, and on one line:  The CDATA tag.</p>
<p>In order to display HTML content and special characters successfully, we need to put a CDATA tag into our <code>theItem</code> tag.  The syntax of the CDATA tag starts with <code>&lt;![CDATA[</code> and ends with <code>]]&gt;</code>.  It wraps around the outside of the <code>theItem</code> content, like this:</p>
<p><code>&lt;theItem&gt;&lt;![CDATA[&lt;p&gt;This is an example of XML text with &lt;b&gt;bold&lt;/b&gt; and &lt;i&gt;italic&lt;/i&gt; words, as well as &lt;a href="#"&gt;hyperlinks&lt;/a&gt;.&lt;/p&gt;]]&gt;&lt;/theItem&gt;</code></p>
<p>Save the XML file, and return to Flash.  Once in Flash, re-rest your movie.  You&#8217;ll notice that the text now flows correctly, and is styled according to our HTML tags and style sheet data!</p>
<p><img class="size-full wp-image-75" title="flash_cdata01" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/06/flash_cdata01.gif" alt="Flash Export - CDATA #1" width="552" height="52" /></p>
<p>Ah, sweet success!  We did it!  But the fun doesn&#8217;t stop there.  Inside of the CDATA tag, we not only have the ability to successfully show HTML tags, but also special characters.  Let&#8217;s put some special characters into our XML tag and see what happens.</p>
<p>To use special characters, we will need to know the respective HTML Entity Number, which can be found at the W3 Schools website here: <a href="http://www.w3schools.com/tags/ref_entities.asp" target="_blank">HTML Entity Number Reference</a>.</p>
<p>Now that we have a reference for finding special character entity numbers, we&#8217;ll put in another sentence containing a handful of them to see how they look.  In your XML file, add another sentence to the <code>theItem</code> tag, like the one I&#8217;ve included below:</p>
<p><code>&lt;![CDATA[&lt;p&gt;This is an example of XML text with &lt;b&gt;bold&lt;/b&gt; and &lt;i&gt;italic&lt;/i&gt; words, as well as &lt;a href="#"&gt;hyperlinks&lt;/a&gt;. It also contains special characters, like &amp;#198;, &amp;amp;, &amp;#169;, &amp;#174;, and &amp;#187;.&lt;/p&gt;]]&gt;</code></p>
<p>Save the XML file, return to Flash, and re-test your movie.  Notice that the special characters show up correctly, and in line with everything else without those annoying line breaks!</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="60" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/06/flashXML_specialCharacters.swf" /><embed type="application/x-shockwave-flash" width="550" height="60" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/06/flashXML_specialCharacters.swf"></embed></object></p>
<p>Now, I will say this:  CDATA tags aren&#8217;t needed to merely display HTML tags and special characters within Flash. Flash has done a good job with the <code>htmlText</code> attribute, but we still need to set up the XML file with CDATA tags to make the content flow properly without the line breaks.</p>
<p>Here&#8217;s a look at our final code for this test:</p>
<p><code><span style="color: #999999;">&lt;!-- Begin XML --&gt;</span></code><br />
<code>&lt;?xml version="1.0" encoding="utf-8"?&gt;</code><br />
<code>&lt;site&gt;</code><br />
&nbsp; &nbsp;<code>&lt;theItem&gt;</code><br />
&nbsp; &nbsp;&nbsp; &nbsp;<code>&lt;![CDATA[&lt;p&gt;This is an example of XML text with &lt;b&gt;bold&lt;/b&gt; and &lt;i&gt;italic&lt;/i&gt; words, as well as &lt;a href="#"&gt;hyperlinks&lt;/a&gt;. It also contains special characters, like &amp;#198;, &amp;amp;, &amp;#169;, &amp;#174;, and &amp;#187;.&lt;/p&gt;]]&gt;</code><br />
&nbsp; &nbsp;<code>&lt;/theItem&gt;</code><br />
<code>&lt;/site&gt;</code><br />
<code><span style="color: #999999;">&lt;!-- End XML --&gt;</span></code></p>
<p><code><span style="color: #999999;">/* Begin ActionScript */</span></code><br />
<code><span style="color: #0000ff;">var</span> theXML:<span style="color: #0000ff;">XML</span>;</code><br />
<code><span style="color: #0000ff;">var</span> xmlData:<span style="color: #0000ff;">Array</span> = <span style="color: #0000ff;">new Array</span>();</code><br />
<code><span style="color: #0000ff;">var</span> loader:<span style="color: #0000ff;">URLLoader</span> = <span style="color: #0000ff;">new URLLoader</span>();</code><br />
<code>loader.<span style="color: #0000ff;">addEventListener</span>(<span style="color: #0000ff;">Event.COMPLETE</span>, processXML);</code><br />
<code>loader.<span style="color: #0000ff;">load</span>(<span style="color: #0000ff;">new URLRequest</span>(<span style="color: #009900;">"test.xml"</span>));</code></p>
<p><code><span style="color: #0000ff;">var</span> textStyles:<span style="color: #0000ff;">StyleSheet</span> = new StyleSheet();</code><br />
<code>textStyles.<span style="color: #0000ff;">setStyle</span>(<span style="color: #009900;">"a:link"</span>, {color:<span style="color: #009900;">'#01628b'</span>, textDecoration:<span style="color: #009900;">'underline'</span>});</code><br />
<code>textStyles.<span style="color: #0000ff;">setStyle</span>(<span style="color: #009900;">"a:hover"</span>, {color:<span style="color: #009900;">'#d68402'</span>, textDecoration:<span style="color: #009900;">'underline'</span>});</code><br />
<code>text_txt.<span style="color: #0000ff;">styleSheet</span> = textStyles;</code></p>
<p><code><span style="color: #0000ff;">function</span> processXML(e:<span style="color: #0000ff;">Event</span>){</code><br />
&nbsp; &nbsp;<code>theXML = <span style="color: #0000ff;">new XML</span>(e<span style="color: #0000ff;">.target.data</span>);</code><br />
&nbsp; &nbsp;<code><span style="color: #0000ff;">var</span> xmlLength:<span style="color: #0000ff;">Number</span> = theXML.theItem.<span style="color: #0000ff;">length</span>();</code><br />
&nbsp; &nbsp;<code><span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> i=0; i&lt;xmlLength; i++){</code><br />
&nbsp; &nbsp;&nbsp; &nbsp;<code>xmlData[i] = theXML.theItem[i];</code><br />
&nbsp; &nbsp;<code>}</code><br />
&nbsp; &nbsp;<code>text_txt<span style="color: #0000ff;">.htmlText</span> = xmlData[0];</code><br />
&nbsp; &nbsp;<code>text_txt<span style="color: #0000ff;">.multiline</span> = <span style="color: #0000ff;">true</span>;</code><br />
&nbsp; &nbsp;<code>text_txt<span style="color: #0000ff;">.wordWrap</span> = <span style="color: #0000ff;">true</span>;</code><br />
&nbsp; &nbsp;<code>text_txt<span style="color: #0000ff;">.height</span> = text_txt<span style="color: #0000ff;">.textHeight</span> + 6;</code><br />
<code>}</code><br />
<code><span style="color: #999999;">/* End ActionScript */</span></code></p>
<p>If you want the source files, you can download them here.  <a href="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/09/flashXML_specialCharacters.zip">Download Source Files »</a></p>
<p>I hope that this sheds some light on the topic of getting HTML text to correctly display and flow inside of your Flash application.  Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/using-formatting-html-text-in-flash/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

