<?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; Tutorials</title>
	<atom:link href="http://www.hesslerdesign.com/blog/category/tutorials/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>Formatting Raw Numbers with Commas</title>
		<link>http://www.hesslerdesign.com/blog/tutorials/formatting-raw-numbers-with-commas/</link>
		<comments>http://www.hesslerdesign.com/blog/tutorials/formatting-raw-numbers-with-commas/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 14:48:44 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=637</guid>
		<description><![CDATA[I&#8217;ve worked on a number of Flash projects where I&#8217;ve needed to convert a raw number into a correctly comma-formatted string for display.  Doing this is a relatively simple process, but since I found myself repeating the same chunk of code in multiple projects, I ended up creating a function that I could reuse over [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve worked on a number of Flash projects where I&#8217;ve needed to convert a raw number into a correctly comma-formatted string for display.  Doing this is a relatively simple process, but since I found myself repeating the same chunk of code in multiple projects, I ended up creating a function that I could reuse over and over again. And the nice thing about this chunk of code is that, with a few language-specific modifications, you can use it as JavaScript, PHP, etc.</p>
<p><code><span style="color: #999999;">// This variable gets set as 1,234,567,890</span><br />
<span style="color: #0000ff;">var</span> commaFormattedNumber:<span style="color: #0000ff;">String</span> = formatWithCommas(<span style="color: #009900;">"1234567890"</span>); </code></p>
<p><code><span style="color: #0000ff;">function</span> formatWithCommas(pNum_str:<span style="color: #0000ff;">String</span>):<span style="color: #0000ff;">String</span> {<br />
&nbsp; &nbsp;<span style="color: #0000ff;">var</span> lReturn_str:String = <span style="color: #009900;">""</span>;<br />
&nbsp; &nbsp;<span style="color: #0000ff;">var</span> lStringAsArray_arr:Array = pNum_str.split(<span style="color: #009900;">""</span>);<br />
&nbsp; &nbsp;<span style="color: #0000ff;">var</span> commaCounter_num:Number = 1;<br />
&nbsp; &nbsp;for (<span style="color: #0000ff;">var</span> i=lStringAsArray_arr.<span style="color: #0000ff;">length</span>-1; i&gt;=0; i--) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;lReturn_str = lStringAsArray_arr[i] + lReturn_str;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">if</span> ((commaCounter_num == 3) &amp;&amp; (i != 0)) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;lReturn_str = "," + lReturn_str;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;commaCounter_num = 1;<br />
&nbsp; &nbsp;&nbsp; &nbsp;} <span style="color: #0000ff;">else</span> {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;commaCounter_num++;<br />
&nbsp; &nbsp;&nbsp; &nbsp;}<br />
&nbsp; &nbsp;}<br />
&nbsp; &nbsp;<span style="color: #0000ff;">return</span> lReturn_str;<br />
}</code></p>
<h4>Notes:</h4>
<ul>
<li>In our example, we pass in 1 String value into the function, and it returns a String.</li>
<li>Inside of the function, we split the passed-in string into an Array, then we loop through the array backwards, adding the number in each array slot each time through the loop.</li>
<li>While looping through the array, notice that we have the variable <code>commaCounter_num</code>, which keeps track of which slots to also add in a comma. The conditional logic checks if the <code>commaCounter_num</code> is up to 3 and if the value of <code>i</code> is NOT zero. If both of these are true, we add in a comma and continue on. We must add the check of ensuring that <code>i</code> is not zero, so we don&#8217;t get a 6-digit number, for example, that ends up being returned with a comma at the very beginning of the string.</li>
</ul>
<p>So there you have it.  A nice little chunk of code you can use to format a number into a correctly comma-formatted string. Not a whole lot to it, but still a nice reference function to have for future use.</p>
<p>Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/tutorials/formatting-raw-numbers-with-commas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making Your Web Page Elements More Dynamic with PHP Variables</title>
		<link>http://www.hesslerdesign.com/blog/tutorials/making-your-web-page-elements-more-dynamic-with-php-variables/</link>
		<comments>http://www.hesslerdesign.com/blog/tutorials/making-your-web-page-elements-more-dynamic-with-php-variables/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 18:08:00 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=629</guid>
		<description><![CDATA[One of my little PHP tricks I have become a big fan of is having a set of variables at the top of each file that I use to populate values later on in the file. For instance, I often bulk all of my &#60;head&#62; tag content into one file, and then have a &#8220;include_once("headTag.php");&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>One of my little PHP tricks I have become a big fan of is having a set of variables at the top of each file that I use to populate values later on in the file. For instance, I often bulk all of my <code>&lt;head&gt;</code> tag content into one file, and then have a &#8220;<code>include_once("headTag.php");</code>&#8221; to write it into each file in which it needs to be. If I do this though, I&#8217;m stuck with the same page title, description, etc. Or am I?</p>
<p>If I include a standard set of variables at the very top of each of my PHP files for my site, I can then utilize those variables in any file that is written into that file. So if I want a custom page title on each page, I can make a variable named <code>$pageTitle_str</code>, and set it equal to whatever I want to be the page title for that particular page.  Then, in the file that includes all of the <code>&lt;head&gt;</code> tag content, I would have a little PHP logic to echo that into the <code>&lt;title&gt;</code> tag.  And if I use conditional logic to echo it in, I can set the title to a default value in case the variable isn&#8217;t found.</p>
<p>Here&#8217;s how it&#8217;s done. In the example below, I have the PHP code for a fictitious page in my site that will be placed on the top of that file. I also have the <code>&lt;title&gt;</code> tag for the file that is written into this fictitious page, which includes the conditional logic to echo in the variable for page title.</p>
<p><strong>File &#8211; <em>fictitious.php</em></strong><br />
Code Snippet:<br />
<code>&nbsp; &nbsp;<span style="color: #ff0000;">&lt;?php</span><br />
&nbsp; &nbsp;<span style="color: #0066ff;">$pageTitle_str</span> <span style="color: #0000ff;">=</span> <span style="color: #cc0000;">"Custom Page Title"</span>;<br />
&nbsp; &nbsp;<span style="color: #ff0000;">?&gt;</span></code></p>
<p><strong>File &#8211; <em>headTag.php</em></strong><br />
Code Snippet:<br />
<code>&nbsp; &nbsp;<span style="color: #000099;">&lt;title&gt;</span><span style="color: #ff0000;">&lt;?php</span> <span style="color: #006600;">if</span> <span style="color: #000099;">(</span><span style="color: #0066ff;">$pageTitle_str</span><span style="color: #000099;">)</span> <span style="color: #000099;">{</span> <span style="color: #0000ff;">echo</span> <span style="color: #0066ff;">$pageTitle_str;</span> <span style="color: #000099;">}</span> <span style="color: #006600;">else</span> <span style="color: #000099;">{</span> <span style="color: #0000ff;">echo</span> <span style="color: #cc0000;">"Default Page Title"</span>; <span style="color: #000099;">}</span> <span style="color: #ff0000;">?&gt;</span><span style="color: #000099;">&lt;/title&gt;</span></code></p>
<p>And that&#8217;s all there is to it. The <code>&lt;title&gt;</code> will be written out whether the variable exists or not. And if you include the variables on each page, you can do <em>WAY</em> more than just setting page title. You can set sections and subsections for use in styling in a top navigation file, or have custom descriptions or keywords for the <code>&lt;head&gt;</code> tag on each individual page. The possibilities are endless.</p>
<p>Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/tutorials/making-your-web-page-elements-more-dynamic-with-php-variables/feed/</wfw:commentRss>
		<slash:comments>0</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>Streaming RSS Feeds into Your Flash Application</title>
		<link>http://www.hesslerdesign.com/blog/flash/streaming-rss-feeds-into-your-flash-application/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/streaming-rss-feeds-into-your-flash-application/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 21:30:35 +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[arrays]]></category>
		<category><![CDATA[rss]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=300</guid>
		<description><![CDATA[One of the great things about RSS feeds is that RSS formats are specified using XML.  Because of this, you can parse the RSS feed in your Flash applications just as you would an XML file.  So if, for instance, you have a Flash-based website that you would like to add a &#8220;Recent Blog Posts&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great things about RSS feeds is that RSS formats are specified using XML.  Because of this, you can parse the RSS feed in your Flash applications just as you would an XML file.  So if, for instance, you have a Flash-based website that you would like to add a &#8220;Recent Blog Posts&#8221; section to, you can just import the RSS into Flash and *BAM*, you&#8217;re all set.  Here&#8217;s a quick rundown of how to do it:</p>
<h4>Step 1: Locate the RSS Feed</h4>
<p>If you&#8217;re the owner of a blog that you want to get the RSS feed to, all you should need to do is go to the blog&#8217;s home page, and add &#8220;/feed/&#8221; to the end of the URL.  (For example: <a title="Hessler Design Blog Feed" href="http://www.hesslerdesign.com/blog/feed/" target="_blank">http://www.hesslerdesign.com/blog/feed/</a>)  This is an XML-based page that gives you a list of the blog&#8217;s posts, titles, contents/extracts, etc.</p>
<p>If you need an RSS feed through a service like FeedBurner, you first need to go to the FeedBurner page of the site you want an RSS feed from. (For example: <a title="Hessler Design Blog Feed" href="http://feeds.feedburner.com/hesslerdesign" target="_blank">http://feeds.feedburner.com/hesslerdesign</a>)  This page is NOT the one you need to link to, however.  At this page you&#8217;ll notice a link to &#8220;View Feed XML&#8221; in the Subscribe Now! box.  Click on that link, and you&#8217;ll be presented with a page exactly like that of the &#8220;/feed/&#8221; URL mentioned in the previous paragraph.</p>
<p>Once you get to the XML-based page, copy the URL, because you&#8217;ll need it in Flash.  (If you want to confirm that the page is the correct one, view the page&#8217;s source. It will be set up as an XML file, with a line like <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code> at the very top.)</p>
<h4>Step 2: Importing the RSS Feed into Flash</h4>
<p>To import the feed into Flash, just follow the normal steps you would to import an XML file.  Create an <code>XML</code> object and a <code>URLLoader</code> object, then load your RSS feed URL using the <code>URLLoader</code>.  Since I&#8217;m the type of developer who likes to code as dynamically and flexibly as possible, I like to also set up an empty array for each of the items I want to hold from the RSS feed, such as titles and permalinks.  Then, when I parse the XML, I assign a slot in the appropriate array for each title and accompanying permalink, and then have them to use when I display the Recent Posts section.  Here&#8217;s how to do this:</p>
<div style="margin-left: 24px;"><code><span style="color: #808080;">/* Begin ActionScript 3.0 Code */</span><br />
<span style="color: #0000ff;">var</span> rssXML:<span style="color: #0000ff;">XML</span>;<br />
<span style="color: #0000ff;">var</span> rssLoader:<span style="color: #0000ff;">URLLoader</span>;<br />
<span style="color: #0000ff;">var</span> rssTitles_arr:<span style="color: #0000ff;">Array</span> = <span style="color: #0000ff;">new Array</span>();<br />
<span style="color: #0000ff;">var</span> rssLinks_arr:<span style="color: #0000ff;">Array</span> = <span style="color: #0000ff;">new Array</span>();<br />
<span style="color: #0000ff;">function</span> importFeed():<span style="color: #0000ff;">void</span> {<br />
rssLoader = <span style="color: #0000ff;">new URLLoader</span>();<br />
rssLoader.<span style="color: #0000ff;">addEventListener</span>(<span style="color: #0000ff;">Event.COMPLETE</span>, loadRSS);<br />
rssLoader.<span style="color: #0000ff;">load</span>(<span style="color: #0000ff;">new URLRequest</span>(<span style="color: #009900;">"http://www.hesslerdesign.com/blog/feed/"</span>));<br />
}<br />
<span style="color: #0000ff;">function</span> loadRSS(e:<span style="color: #0000ff;">Event</span>):void {<br />
rssXML = <span style="color: #0000ff;">new XML</span>(e.<span style="color: #0000ff;">target.data</span>);<br />
<span style="color: #0000ff;">trace</span>(rssXML);<br />
<span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> i=0; i&lt;4; i++) {<br />
rssTitles_arr[i] = rssXML.channel.item[i].title;<br />
rssLinks_arr[i] = rssXML.channel.item[i].link;<br />
}<br />
<span style="color: #808080;">// Garbage Collection</span><br />
rssLoader.<span style="color: #0000ff;">removeEventListener</span>(<span style="color: #0000ff;">Event.COMPLETE</span>, loadRSS);<br />
}<br />
importFeed();<br />
<span style="color: #808080;">/* End ActionScript 3.0 Code */</span></code></div>
<h4>An important note:</h4>
<p>To dig down into the XML and get things like Post titles and permalinks, you need to be familiar with the structure of the RSS file.  You can see from the code above that the title for each post is inside an item tag, which sits inside of the channel tag.  If you want to get more info than just these two items, just go to the RSS URL (see Step 1) and view the page source.  Or, you can do as I&#8217;ve done in the code above and trace out the XML in Flash once the XML loads.  This is a helpful first step to see what the structure of the XML file is before you get into parsing the XML into appropriate arrays.</p>
<p>Another quick thing to note is in the <code>for</code> loop, inside of the <code>loadRSS()</code> function.  I used the number 4 as a benchmark to populate my arrays (seen in the snippet <code>i&lt;4</code>).  You can use a different number if you want.  It&#8217;s a matter of (a) the number of posts available in the RSS feed, and (b) personal preference.</p>
<p>Once you incorporate the code above, you can then use the arrays populated with RSS info and populate text fields, buttons, etc.  Since it&#8217;s stored in an array, the possibilities are virtually limitless.</p>
<p>So there you have it.  The flexibility of RSS feeds makes it just that easy to import into Flash.  Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/streaming-rss-feeds-into-your-flash-application/feed/</wfw:commentRss>
		<slash:comments>2</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>Embedding Fonts Using ActionScript 3.0</title>
		<link>http://www.hesslerdesign.com/blog/flash/embedding-fonts-using-actionscript-3-0/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/embedding-fonts-using-actionscript-3-0/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 17:05:31 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[text format]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=137</guid>
		<description><![CDATA[If you read my previous post on Embedding Fonts Using ActionScript 2.0, you&#8217;ll remember that I didn&#8217;t cover embedding fonts in ActionScript 3.0 in that post. So now, I&#8217;ll take you through the steps necessary to embed fonts in your ActionScript 3.0 files. As we did when embedding in ActionScript 2.0, you&#8217;ll need to make [...]]]></description>
			<content:encoded><![CDATA[<p>If you read my previous post on Embedding Fonts Using ActionScript 2.0, you&#8217;ll remember that I didn&#8217;t cover embedding fonts in ActionScript 3.0 in that post. So now, I&#8217;ll take you through the steps necessary to embed fonts in your ActionScript 3.0 files.</p>
<p>As we did when embedding in ActionScript 2.0, you&#8217;ll need to make a new Font item in your Library.  Click on the Library menu, and select &#8220;New Font&#8230;&#8221;.  Find your Font and Style from the dropdown menus in the dialog box, and give it a unique name.  I generally give it a name that includes reference to both the Font and Style (in this example, I am using RockwellBold).  Then, make sure the &#8220;Export for ActionScript&#8221; checkbox is checked under the Linkage section of the dialog box, which will auto-check the &#8220;Export in frame 1&#8243; checkbox.  Lastly, give your new Font a unique identifier in the &#8220;Class&#8221; field beneath the checkboxes.  I like to make this Class the same as the Name I gave it above.  Once all that is done, click OK.  </p>
<p><i>(Note: You may get a dialog box that tells you, &#8220;A definition for this class could not be found in the classpath, so one will be automatically generated in the SWF file upon export.&#8221;  This is fine.  It&#8217;s just telling you that the Class you identified isn&#8217;t a built-in Flash Class.  As long as you don&#8217;t need to access additional functionality beyond that of the Font class, you don&#8217;t have to worry.)</i></p>
<p><a href="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/09/embed_font_dialog_as3.jpg"><img class="size-full wp-image-138" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/09/embed_font_dialog_as3.jpg" alt="" width="566" height="495" /></a></p>
<p>Next comes the ActionScript:</p>
<p><code><span style="color: #0000ff;">var</span> rockwellBold:<span style="color: #0000ff;">Font</span> = <span style="color: #0000ff;">new</span> RockwellBold <span style="color: #0000ff;">as Font</span></code>;<br />
<code><span style="color: #0000ff;">var</span> rockwellBoldTF:<span style="color: #0000ff;">TextFormat</span> = <span style="color: #0000ff;">new TextFormat</span>();</code><br />
<code>rockwellBoldTF<span style="color: #0000ff;">.font</span> = rockwellBold.<span style="color: #0000ff;">fontName</span>;</code></code></p>
<p><code>myText_txt<span style="color: #0000ff;">.text</span> = <span style="color: #009900;">"Hello World!"</span>;</code><br />
<code>myText_txt<span style="color: #0000ff;">.setTextFormat</span>(rockwellBoldTF);</code><br />
<code>myText_txt<span style="color: #0000ff;">.embedFonts</span> = <span style="color: #0000ff;">true</span>;</code><br />
<code>myText_txt<span style="color: #0000ff;">.antiAliasType</span> = <span style="color: #0000ff;">AntiAliasType.ADVANCED</span>;</code></p>
<p>First, we create a new Font object, and assign it to our Font Class we created above (RockwellBold).  Then, we create a new <code>TextFormat</code>, and give it the <code>font</code> attribute with the name of the Font object you just created, appended with <code>fontName</code> property.  Then, set the text of your text field ("Hello World!").  After setting the text, use the <code>setTextFormat</code> attribute, and pass in the <code>TextFormat</code> variable you created in the first line.  Next, set the <code>embedFonts</code> attribute to "<code>true</code>".  Lastly, you can optionally set the <code>antiAliasType</code> attribute of your text to either <code>ADVANCED</code> or <code>NORMAL</code>.  By anti-aliasing your text, you effectively smooth the edges of your font to avoid any distortion artifacts that may be introduced through screen display.  According to Adobe's documentation, the <code>ADVANCED</code> setting is most useful for applications that have a lot of small text, and isn't recommended for font sizes above 48 pts.  The <code>NORMAL</code> setting is most useful for applications that don't have a lot of text, and sets the anti-aliasing to the setting that was used in Flash Player 7.  Once these steps are done, you're all set.</p>
<p>As with embedding fonts in AS 2.0, it's nothing too complicated.  Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/embedding-fonts-using-actionscript-3-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding Line Breaks to Flash Checkboxes &amp; Radio Buttons</title>
		<link>http://www.hesslerdesign.com/blog/flash/adding-line-breaks-to-flash-checkboxes-radio-buttons/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/adding-line-breaks-to-flash-checkboxes-radio-buttons/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 23:01:06 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[components]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=134</guid>
		<description><![CDATA[I was recently working on a Flash website where the space in the registration form was really tight.  I needed to squeeze a full sentence into a checkbox label, but only had enough room for about half of the sentence to fit.  I needed a line break in the checkbox label, but found that trying [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently working on a Flash website where the space in the registration form was really tight.  I needed to squeeze a full sentence into a checkbox label, but only had enough room for about half of the sentence to fit.  I needed a line break in the checkbox label, but found that trying to add one in using the Component Inspector did nothing.  So I went to ActionScript.</p>
<p>Using ActionScript 3.0, you can add labels to your CheckBox and RadioButton components, as long as they have a unique instance name.  The simple syntax for doing this is:</p>
<p><code>myCheckBox<span style="color: #0000ff;">.label</span> = <span style="color: #009900;">"Hello, World!"</span>;</code></p>
<p>If you need to add in a line break, all you need to do is include &#8220;\n&#8221; where you want the line break.  Using the previous line of code as an example, we could break the two words into two lines by putting:</p>
<p><code>myCheckBox<span style="color: #0000ff;">.label</span> = <span style="color: #009900;">"Hello, \nWorld!"</span>;</code></p>
<p>If you find it hard to read the string with the &#8220;\n&#8221; scrunched right up against a word, you can always concatenate strings together for greater code legibility.  An example would be:</p>
<p><code>myCheckBox<span style="color: #0000ff;">.label</span> = <span style="color: #009900;">"Hello,"</span> + <span style="color: #339966;">"\n"</span> + <span style="color: #339966;">"World!"</span>;</code></p>
<p>The line of code above does the exact same thing, but shows you more cleanly where your line break is, should you need or want to see it better.</p>
<p>So there you have it.  Line breaks in your Flash components using ActionScript 3.0.  Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/adding-line-breaks-to-flash-checkboxes-radio-buttons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

