<?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; optimization</title>
	<atom:link href="http://www.hesslerdesign.com/blog/tag/optimization/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>Dropping the Ball on Mobile Application Development</title>
		<link>http://www.hesslerdesign.com/blog/flash/dropping-the-ball-on-mobile-application-development/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/dropping-the-ball-on-mobile-application-development/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 18:30:23 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[applications]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=786</guid>
		<description><![CDATA[OK. I need to get this off my chest. I&#8217;m not a fan of Adobe&#8217;s attempt to get into the mobile application game. There. I said it. That feels better. But why am I not a fan of what they&#8217;ve done? Quite frankly, in the process of trying to build a mobile application with Flash [...]]]></description>
			<content:encoded><![CDATA[<p>OK. I need to get this off my chest. I&#8217;m not a fan of Adobe&#8217;s attempt to get into the mobile application game.</p>
<p>There. I said it. That feels better.</p>
<p>But why am I not a fan of what they&#8217;ve done? Quite frankly, in the process of trying to build a mobile application with Flash Builder 4.5, I&#8217;m finding myself either engineering components from scratch, or reengineering the default &#8220;mobile-optimized&#8221; components to get them to do what I want/need. Plus, I&#8217;m finding that in an application of even a decent size (more than just a &#8220;hello world&#8221; app with a couple simple views like Adobe likes to show off to get Flash developers excited about mobile apps), the optimization and performance are still lacking.</p>
<p>Maybe I&#8217;m just being pessimistic. And maybe I&#8217;m not doing everything correctly to get things optimized for the mobile app. Honestly, I hope that I am missing something that I&#8217;ll catch soon and have a light bulb-over-the-head moment. But my experience thus far has taught me that Steve Jobs was right in bashing Adobe&#8217;s ability to create mobile-optimized content.</p>
<p>Here&#8217;s a snippet from a blog post from Steve Jobs, dated April 2010:</p>
<div style="padding: 16px 24px 16px 24px; background: #ededed; border: 1px solid #dedede;">
<p><em>“We know from painful experience that letting a third party layer of software come between the platform and the developer ultimately results in sub-standard apps and hinders the enhancement and progress of the platform. If developers grow dependent on third party development libraries and tools, they can only take advantage of platform enhancements if and when the third party chooses to adopt the new features. We cannot be at the mercy of a third party deciding if and when they will make our enhancements available to our developers.</em></p>
<p><em>“This becomes even worse if the third party is supplying a cross platform development tool. The third party may not adopt enhancements from one platform unless they are available on all of their supported platforms. Hence developers only have access to the lowest common denominator set of features. Again, we cannot accept an outcome where developers are blocked from using our innovations and enhancements because they are not available on our competitor’s platforms.”</em></p>
<p><small>Jobs, Steve. &#8220;<a title="Thoughts on Flash" href="http://www.apple.com/hotnews/thoughts-on-flash">Thoughts on Flash.</a>&#8221; Apple. Apple Inc., Apr. 2010. Web. 22 Nov. 2011.</small></p>
</div>
<p>&nbsp;</p>
<p>As you probably noticed, this post was from April of 2010. Yeah, that&#8217;s over a year and a half ago. And guess what? Adobe <b><i>still</i></b> doesn&#8217;t have it right. They&#8217;re close. But not there. And with the news of Adobe dropping mobile support for Flash Player a couple weeks ago, I&#8217;m guessing they never will be there. They may try to really hone in on the mobile application side, rather than just the Flash Player plugin for mobile, and they may get close. But like Jobs eluded to, Adobe holds all of its developers at the mercy of when they choose to adopt new features, whereas developing a mobile application natively gives immediate access to the full spectrum of features. </p>
<p>Don&#8217;t get me wrong. I&#8217;m not completely agreeing with the Flash haters out there who think that all Flash needs to go away&mdash;there is definitely still a time and place for Flash on the web. I&#8217;m just agreeing that Adobe needs to realize what their strengths are, and really concentrate on them rather than trying to get a foot into every single realm and telling developers that the Adobe solution will change their lives and work seamlessly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/dropping-the-ball-on-mobile-application-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clean Up Your Flash Applications with the Help of Math</title>
		<link>http://www.hesslerdesign.com/blog/flash/clean-up-your-flash-applications-with-the-help-of-math/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/clean-up-your-flash-applications-with-the-help-of-math/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 23:21:25 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[user experience]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=648</guid>
		<description><![CDATA[We&#8217;ve all seen it before. Someone builds a well-intentioned Flash website that will wow the masses, but that ends up looking sub-par because of mis-placed, mis-sized, or otherwise unfortunate visual assets. It&#8217;s easy to do — you put together a design, draw out your shapes, do some resizing with a Transform tool to get things [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve all seen it before. Someone builds a well-intentioned Flash website that will wow the masses, but that ends up looking sub-par because of mis-placed, mis-sized, or otherwise unfortunate visual assets.  It&#8217;s easy to do — you put together a design, draw out your shapes, do some resizing with a Transform tool to get things &#8220;perfect&#8221;, and in the process, you inevitably create fuzzy lines.  It&#8217;s not all your fault.  Blame it on Photoshop or Flash for allowing smaller-than-pixel increments — doesn&#8217;t matter to me where you place the blame.  But at the end of the day, one of the MUST DO items when putting together any website is to ensure that your vertical and horizontal lines are crisp and exact — unless there&#8217;s good reason why to do otherwise.</p>
<p>Lucky for you, Flash comes well-equipped with providing tools for developers to use when coding their Flash applications.  My three most-used Flash methods for clean lines and exact placement are listed below, and are all part of Flash&#8217;s Math class.  If you use them, you&#8217;ll be sure clean up the lines and sizes of your site in no time.  (It may not help poorly-drawn shapes that you draw by hand, but for dynamically-drawn, code-generated items, or code-based asset placement, it&#8217;s golden.)</p>
<h4>A Few of My Favorites</h4>
<p><strong><code>Math.ceil()</code></strong><br />
This function returns the ceiling of the specified number or expression, which equates to the closest integer that is greater than or equal to the number.</p>
<div style="margin-left: 20px; margin-bottom: 32px;"><em>Example:</em><br />
<code><span style="color: #0000ff;">var</span> myValue:<span style="color: #0000ff;">Number</span> = <span style="color: #0000ff;">Math.ceil</span>(4.385); <span style="color: #999999;">// Returns 5</span></code></div>
<p><strong><code>Math.floor()</code></strong><br />
This function returns the floor of the specified number or expression, which equates to the closest integer that is less than or equal to the number.</p>
<div style="margin-left: 20px; margin-bottom: 32px;"><em>Example:</em><br />
<code><span style="color: #0000ff;">var</span> myValue:<span style="color: #0000ff;">Number</span> = <span style="color: #0000ff;">Math.floor</span>(4.385); <span style="color: #999999;">// Returns 4</span></code></div>
<p><strong><code>Math.round()</code></strong><br />
This function rounds the value of the passed-in parameter to the nearest closest integer. If the passed-in value is exactly in the middle, it rounds up.</p>
<div style="margin-left: 20px; margin-bottom: 32px;"><em>Examples:</em><br />
<code><span style="color: #0000ff;">var</span> myValue:<span style="color: #0000ff;">Number</span> = <span style="color: #0000ff;">Math.round</span>(4.385); <span style="color: #999999;">// Returns 4</span></code><br />
<code><span style="color: #0000ff;">var</span> myMiddleValue:<span style="color: #0000ff;">Number</span> = <span style="color: #0000ff;">Math.round</span>(4.5); <span style="color: #999999;">// Returns 5</span></code></div>
<p><span id="more-648"></span></p>
<h4><span style="color: #999999;"><span style="color: #000000;">How and When to Use the Math Functions</span></span></h4>
<p>Let&#8217;s say you have a square MovieClip that&#8217;s sitting on your stage with an <code>x</code> coordinates of 133.  You want to tween it with ActionScript to a point 50% of the way to the left edge of your application from it&#8217;s original point of 133.  You&#8217;ll need to have the <code>x</code> coordinate change for the move, obviously.  But if you simply figure out what point to tween to without somehow finding the nearest integer value, you&#8217;ll be left with a non-integer value (66.5), and your horizontal and vertical lines will get fuzzy.  However, if you use the <code>Math.round()</code> method, for instance, you&#8217;ll get an integer value (67), which will keep your horizontal and vertical lines crisp and clean.</p>
<p>In the example SWF below, there are two square MovieClips, both placed at an <code>x</code> coordinate of 133, as in the example above.  The top one does <em>not</em> use the Math class to get the integer-based pixel value it will end on.  The bottom one, on the other hand, <strong><em>does</em></strong> use the Math class, and rounds the target value to the nearest integer, thus resulting in a final <code>x</code> coordinate that is an integer.  Click on each box to tween it, and notice the end result of the boxes side by side.  You&#8217;ll quite obviously notice the top box having fuzzy edges when compared the the clean lines of the bottom box.</p>
<p style="text-align:center;">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="260" height="200" 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/2010/11/integerTweens.swf" /><embed type="application/x-shockwave-flash" width="260" height="200" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2010/11/integerTweens.swf"></embed></object>
</p>
<h4>Know, Love, and Understand Integers</h4>
<p>The important part to note about all three of these methods is that they all calculate the closest &#8220;integer&#8221; — or whole number.  This is immensely helpful, because if you base your <code>width</code>, <code>height</code>, <code>x</code>, or <code>y</code> values on any of these methods, you&#8217;ll always get back a whole-pixel value, which will give you the crisp edges that we all know and love.  With that said, there is one important exception….</p>
<p>Even though these methods return integers, there is still one more &#8220;gotcha&#8221; that you&#8217;ll need to keep in mind when developing your Flash application.  If you have a MovieClip of a square shape, for instance, and you have it centered to the registration point of the MovieClip, you may still get fuzzy pixels.  How, you ask?  If your square has a width and/or height whose value is an odd number (57, for example), its <code>x</code> and <code>y</code> coordinates will be half-pixels within the MovieClip (-28.5, -28.5 for a width of 57).  And if you place this MovieClip on the stage and put it at coordinates whose values are integers, the edges will be fuzzy, because of the coordinates of the object within the MovieClip.</p>
<p>To combat this, there are a couple of options:</p>
<ul>
<li>If you center your object(s) in your MovieClips (or other display objects), make sure they have dimensions that are even numbers.  If this isn&#8217;t doable, at least make the <code>x</code> and <code>y</code> coordinates integer values, even if it means your assets won&#8217;t be &#8220;exactly&#8221; centered in the MovieClip.</li>
<li>Instead of centering your object(s) in your MovieClips, use corner-based orientation, so, for example, your object(s) will have an <code>x</code> and <code>y</code> value of 0.  This way, you&#8217;ll be guaranteed to have crisp lines when the MovieClip is placed at coordinates whose values are integers.</li>
</ul>
<h4>Other Best Practices for Clean Lines</h4>
<ul>
<li>When drawing shapes with horizontal and/or vertical lines in Flash, make sure that the <code>x</code> and <code>y</code> coordinates are integer values in your Properties panel.  Also, make sure the <code>width</code> and <code>height</code> are also integer values.  Every so often, Flash will want to add/subtract a random 0.05 from your typed-in values, so you may need to re-type in a value now and again.</li>
<li>If you&#8217;re nudging objects around on your stage, turn on &#8220;Snap to Pixels&#8221;.  To do this, select the &#8220;View&#8221; menu, and select &#8220;Snapping &gt; Snap to Pixels&#8221;.  Doing this will always snap your objects to integer (pixel) values.</li>
</ul>
<h4>Wrapping Up</h4>
<p>So there you have it.  With a little careful planning and knowhow, and with a little help from the Math class, you can ensure your Flash applications have vertical and horizontal lines that are crisp and exact, creating a much stronger, cleaner design.</p>
<p>Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/clean-up-your-flash-applications-with-the-help-of-math/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>Optimize Your Website&#8217;s SEO with the Help of SEOmoz</title>
		<link>http://www.hesslerdesign.com/blog/web-design/optimize-your-websites-seo-with-the-help-of-seomoz/</link>
		<comments>http://www.hesslerdesign.com/blog/web-design/optimize-your-websites-seo-with-the-help-of-seomoz/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 17:50:05 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=486</guid>
		<description><![CDATA[One question I get repeatedly is, &#8220;How can I improve my search rankings?&#8221;  While there&#8217;s a vast array of variables that go into search rankings, most of which are beyond the comprehension of non-Google developers, there is a site that is devoted to providing information on Search Engine Optimization (SEO).  That site is: seomoz.org. SEOmoz [...]]]></description>
			<content:encoded><![CDATA[<p>One question I get repeatedly is, &#8220;How can I improve my search rankings?&#8221;  While there&#8217;s a vast array of variables that go into search rankings, most of which are beyond the comprehension of non-Google developers, there is a site that is devoted to providing information on Search Engine Optimization (SEO).  That site is: <a title="SEOmoz" href="http://www.seomoz.org" target="_blank">seomoz.org</a>.</p>
<p>SEOmoz is a popular provider of SEO software.  It&#8217;s website is dedicated to all things SEO, including a blog, helpful articles and user guides, and best of all, a set of tools that webmasters can use to help their site&#8217;s SEO.  Some of the tools are only available to &#8220;Pro&#8221; members, which costs money.  But a little over half of them (at the writing of this entry) are completely free to use (some with daily restrictions on use).</p>
<p>One of the coolest free tools available to anyone is the <a title="SEO Toolbar for Firefox" href="http://www.seomoz.org/seo-toolbar" target="_blank">SEO Toolbar for Firefox</a>.  With the toolbar, you can access any of the SEOmoz tools right from the toolbar, without having to go to the actual site first.  It&#8217;s incredibly handy, and also includes stats like Page Authority and Domain Authority, which give real-time stats on the site you&#8217;re currently on.</p>
<p>So next time you get the question, &#8220;How can I improve my search rankings?&#8221;, look to <a title="SEOmoz" href="http://www.seomoz.org" target="_blank">SEOmoz.org</a> as your first (and likely, only) stop for resources and tools to help guide you on your road to SEO success.</p>
<p>Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/web-design/optimize-your-websites-seo-with-the-help-of-seomoz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top Ten Ways to Optimize Your Flash Website</title>
		<link>http://www.hesslerdesign.com/blog/flash/top-ten-ways-to-optimize-your-flash-website/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/top-ten-ways-to-optimize-your-flash-website/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 17:45:12 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=324</guid>
		<description><![CDATA[Let&#8217;s face it.  When it comes to Flash websites, people either love them or hate them.  For those who hate them, I firmly believe it&#8217;s because of two main reasons: crappy SEO (search engine optimization), and long load times (a direct result of heavy file weights).  While the issue of SEO is its own beast, [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s face it.  When it comes to Flash websites, people either love them or hate them.  For those who hate them, I firmly believe it&#8217;s because of two main reasons: crappy SEO (search engine optimization), and long load times (a direct result of heavy file weights).  While the issue of SEO is its own beast, I won&#8217;t get into that now.  For now, I&#8217;m going to focus on 10 easy ways to optimize your Flash website to make it meaner, leaner, and more user-friendly.  Believe me, if you start using some of these ideas, your sites will transform in ways you never though imaginable.  And you&#8217;ll notice that you&#8217;ll get a much smoother and quicker site.  With that said, let&#8217;s get started.</p>
<h4>1. Use XML files to set content framework</h4>
<p>On nearly every Flash site I work on, I use at least some XML. The great thing about XML files is they are a great way to structure blocks of your site.  For instance, if you want a slideshow on your site, you could have an XML file that contains the title, url, and other image-specific information you want to include for each image. Then, just import the XML into Flash and store the XML data in arrays to organize the information to use later.  (More on arrays below.)</p>
<p>Another great thing about using XML in Flash is that if you want to stream an RSS feed into a Flash site, you can, because RSS feeds are set up as XML.  (For more info on RSS feeds, see the post on <a href="http://www.hesslerdesign.com/blog/flash-actionscript/streaming-rss-feeds-into-your-flash-application/" target="_self">Streaming RSS feeds into Your Flash Applications</a>.)</p>
<p>Additionally, XML is easy to change without having to republish your site.  Say you have that slideshow I mentioned above, but want to swap out an image.  With XML, you just point to the new url, update the title, and save. Your Flash site will automatically update with the new info, and you won&#8217;t have to republish every time. Trust me, you&#8217;ll thank yourself for using XML when you build your Flash site.</p>
<h4>2. Use arrays to organize assets used in your code</h4>
<p>For me, using arrays is quite possibly one of the smartest and most powerful things you can do to optimize your code.  Not necessarily from a file weight perspective, but because with arrays, you can reference an object stored in an array by name, number, id, etc. For instance, say you have 20 thumbnail images you want to make clickable to open a larger image. You could attach individual event listeners to each image.  Or, you could set up a couple of arrays &#8212; one for the instance names of each image, and one for the reference to the larger image to load when clicked &#8212; and run &#8220;for&#8221; loops to set the event listeners all at once. While you&#8217;re in the &#8220;for&#8221; loop, set an ID number for each image that you can then reference in your &#8220;click&#8221; function that will fire on mouse click, and call up that ID number slot in the large image array.  With only a few lines of code, you&#8217;ll have a powerful way to batch chunks of your code with minimal effort. (For more info on arrays, see my post on <a href="http://www.hesslerdesign.com/blog/flash-actionscript/utilizing-the-power-of-arrays-in-adobe-flash/" target="_self">Utilizing the Power of Arrays in Adobe Flash</a>.)</p>
<h4>3. Only import and embed absolutely necessary image files into your file.</h4>
<p>If you&#8217;ve been on the Web at all&#8230;and judging by you reading this, I&#8217;m guessing you have&#8230;you know doubt know that a lot of people don&#8217;t like Flash sites.  The main reason seems to be they take way too long to load.  To get around this, I highly suggest importing and embedding ONLY the images you absolutely need.  If you have a lot of image assets, I suggest loading them dynamically via code, and placing them in the appropriate places.  This not only makes the file size considerably smaller, but it also opens the door to be able to update an image, replace it, and have Flash automatically read in the updated file without the need to republish the entire site.  (Sorta sounds like one of the key perks of using XML, doesn&#8217;t it?)  And trust me, users will thank you for having a site that loads (or at least shows up with a short preloader) in 5 seconds, rather than a beefy site that doesn&#8217;t show up until the entire thing loads.</p>
<h4>4. Load assets in an orderly fashion, not all at once</h4>
<p>Along with #3 above, when you load assets into your Flash site dynamically, it&#8217;s best to set up a structure and order in which to load them. For instance, load all of the home/landing page assets first. Once those are loaded, proceed with the next set of assets that you think will be needed/viewed by your users.  Not using a certain set of images until later in the site?  Don&#8217;t load them up front. Wait until the rest of the assets before it have been loaded first. Think about it.  Would you rather try to have 20 images load all at once?  Or load them in the order of which they&#8217;ll be seen? Loading them one at a time will speed up the individual image load time because there is only one image needing attention while it is being loaded, not all 20?</p>
<h4>5. Cool it with the videos</h4>
<p>Okay, this sounds harsh, but hear me out. Video is great. It&#8217;s everywhere, and it&#8217;s getting more popular by the day.  (YouTube, anyone?)  But when you&#8217;re making a Flash site, video can also be a beast to work with, specifically video that needs to stream without a playback bar.  The worst thing about video is file size. I&#8217;ll admit, video has come a long way in optimizing file weights and all, but at the end of the day, even a small video is still going to be around 1-2MB.  When you are using video, make sure you utilize the &#8220;loading assets in an orderly fashion&#8221; advice from above.  If you try to start streaming a video when 20 images are loading while it&#8217;s trying to play, you&#8217;ll no doubt get choppy playback.</p>
<h4>6. Use TweenMax or TweenLite for code-based tweening and animating</h4>
<p>I&#8217;m a big fan of keeping my Flash sites on one frame of the timeline, and doing as much as I possibly can with code, rather than with the timeline.  The reason for this is simply less time making changes later on down the road.  Want to make every tween of an image fading out half as long across the entire site?  Pretty laborious if you&#8217;re using the timeline.  But if you&#8217;re using code, it&#8217;s a matter of updating a couple of numbers.</p>
<p>This is where <a href="http://blog.greensock.com/tweenmax/" target="_blank">TweenMax</a> and <a href="http://blog.greensock.com/tweenlite/" target="_blank">TweenLite</a> come in.  In a nutshell, they&#8217;re the best tweening engine out there.  Using it, you can call one function that can alter many facets of an object at once (x and y position, alpha, tint, etc.).  You can also attach event listeners like onComplete, onStart, etc., that call functions to run at specific times during the tween.  In short, these tweening engines will make you wonder why you ever used timeline-based animations.  And best of all, they&#8217;re extremely light in file weight, unlike a lot of timeline-based animations.  And it&#8217;s a one-time file weight addition, not a per-tween sort of thing.</p>
<h4>7. Simulate downloading on slower connections</h4>
<p>Not everyone has a cable-speed connection. Believe it or not, there are still a lot of people out there using DSL or slower connections.  And as unfortunate as it may be, those are the people you need to build the site for.  Don&#8217;t ever assume that your audience is going to have the latest and greatest computers.</p>
<p>To simulate downloads in Flash, export your movie and select &#8220;View &gt; Simulate Download&#8221;.  To set different connection speed settings, select &#8220;View &gt; Download Settings&#8221;, and select your desired speed (or create your own custom speed).  Flash can be deceiving. When you test out a movie, it always runs lightning fast. But by testing it using the &#8220;Simulate Download&#8221; method, you&#8217;ll get a much better idea of how your site will behave on the Web.</p>
<h4>8. Build buttons and other UI components as vector artwork in Flash</h4>
<p>One of my biggest pet peeves is using raster images for buttons that could easily be made as vector art in Flash.  Not only does this make having to update the button a multi-step process, but it also beefs up the size of the file.  It may not be much, but if you get a dozen different image buttons, you could easily have just added 100+ kb to your file weight.  Might not seem by much, but as people&#8217;s attention spans are getting shorter and shorter, that added 2 seconds of load time you just added might be costly, and you may see an increase in the number of dropped users.</p>
<p>My motto is this: &#8220;<em>If it can be made in Flash, make it in Flash&#8221;</em>.  Vector art is not only easily editable, but also a huge file weight saver.  Plus, you don&#8217;t get any degradation of quality that you&#8217;d get if you used images.  All of your lines, colors, gradients, etc. are crystal clear.  Pair that with the almost non-existent file weight they carry, and what&#8217;s not to love?</p>
<h4>9. Write custom Classes for reusable code</h4>
<p>If you write Actionscript code, you use Classes.  You might not know it, but you do.  Every time you use a property of a MovieClip instance (i.e. myClip_mc.y to get the &#8220;y&#8221; position), you&#8217;re calling the MovieClip class.  Same with Sprites, Buttons, UI Components, etc.  Classes are a staple in object-oriented programming, and allow you to read or set properties, call functions (methods), and respond to events.  It&#8217;s a great way to reuse the same code over and over again, by simply importing the classes into your site file.</p>
<p>One of my personal favorite classes that I have written is for an Email Validator, which contains the logic to check whether a string is a valid email address or not.  You can check it out in my previous post on <a href="http://www.hesslerdesign.com/blog/flash-actionscript/building-a-better-email-validator-in-flash/" target="_self">Building a Better Email Validator in Flash</a>.  Each time I need to use this, I simply import it into my file (which is 1 line of code), make an instance of the validator (1 line of code), then call the validate function and pass in the string to validate (1 line of code).  In all, for me to validate an email address, it takes 3 lines of code.  Much better than rewriting all of the validation logic in a dozen different files, eh?</p>
<h4>10. Use FlashVars to set important global variables</h4>
<p>Every so often, you&#8217;ll run into an issue where you&#8217;ll want to change a variable from outside of your Flash file. An easy way to do this is to use the FlashVars parameter when embedding your Flash file in HTML.  I find that I mostly use FlashVars for variables that will change from a &#8220;staging&#8221; site to the final &#8220;production&#8221; site.  The most often used variable that I personally encounter is the account name for Omniture tracking. The bulk of sites I develop have different staging and production Omniture account names, so the metrics don&#8217;t get skewed while testing.  But if I embed that account name into the Flash file, I suddenly need 2 different versions of the Flash file &#8212; one for staging, one for production.  But if I have a FlashVar set up for this account name, I can just change the variable in the HTML code, and have Flash read it in.  Trust me, it&#8217;s a handy way to avoid having multiple versions of the same file for different environments.</p>
<h4>In Conclusion&#8230;</h4>
<p>So there you have it.  10 easy ways to optimize your Flash sites.  There are many more ways to optimize Flash sites, and I&#8217;m sure I&#8217;ll get into them in later posts.  But these are some of the main culprits.  And trust me, individual posts could be written about each one of these (and some already have).  If you want to see posts that dive deeper into any of these, just let me know and I&#8217;ll write it up.  Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/top-ten-ways-to-optimize-your-flash-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

