<?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; PHP</title>
	<atom:link href="http://www.hesslerdesign.com/blog/tag/php/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>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>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>Sending Flash Data to ASPX or PHP files</title>
		<link>http://www.hesslerdesign.com/blog/flash/sending-flash-data-to-aspx-or-php-files/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/sending-flash-data-to-aspx-or-php-files/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 15:54:25 +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[aspx]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=1</guid>
		<description><![CDATA[If you are working on any Flash website projects that need to pass data out to an ASPX or PHP file (or any other type of file requiring to send data via POST or GET), you can use the code below.  Note that this code is written in ActionScript 3. /* --- Begin Code --- [...]]]></description>
			<content:encoded><![CDATA[<p>If you are working on any Flash website projects that need to pass data out to an ASPX or PHP file (or any other type of file requiring to send data via POST or GET), you can use the code below.  Note that this code is written in ActionScript 3.</p>
<p><code><span style="color:#999999;">/* --- Begin Code --- */</span></code><br />
<code><span style="color: #0000ff;">var</span> firstName:<span style="color: #0000ff;">String</span> = <span style="color: #009900;">"Anthony"</span>;</code></p>
<p><code><span style="color: #0000ff;">function</span> submitForm(e:<span style="color: #0000ff;">MouseEvent</span>):<span style="color: #0000ff;">void</span> {</code><br />
<code>&nbsp; &nbsp;<span style="color: #0000ff;">var</span> varsToSend:<span style="color: #0000ff;">URLVariables</span> = <span style="color: #0000ff;">new URLVariables</span>();</code><br />
<code>&nbsp; &nbsp;varsToSend.firstName = firstName;</code><br />
<code>&nbsp; &nbsp;<span style="color: #999999;">// Insert additional values to send</span></code></p>
<p><code>&nbsp; &nbsp;<span style="color: #999999;">// Create URL Request, set to POST, and attach data</span></code><br />
<code>&nbsp; &nbsp;<span style="color: #0000ff;">var</span> formRequest:<span style="color: #0000ff;">URLRequest</span> = <span style="color: #0000ff;">new URLRequest</span>(<span style="color: #009900;">"flash.php"</span>);</code><br />
<code>&nbsp; &nbsp;formRequest.<span style="color: #0000ff;">method</span> = <span style="color: #0000ff;">URLRequestMethod.POST</span>;</code><br />
<code>&nbsp; &nbsp;formRequest.<span style="color: #0000ff;">data</span> = varsToSend;</code></p>
<p><code>&nbsp; &nbsp;<span style="color: #999999;">// Create URL Loader, attach listeners, and load URL Request</span></code><br />
<code>&nbsp; &nbsp;<span style="color: #0000ff;">var</span> varLoader:<span style="color: #0000ff;">URLLoader</span> = <span style="color: #0000ff;">new URLLoader</span>;</code><br />
<code>&nbsp; &nbsp;varLoader.<span style="color: #0000ff;">addEventListener</span>(<span style="color: #0000ff;">Event.COMPLETE</span>, onLoaded);</code><br />
<code>&nbsp; &nbsp;varLoader.<span style="color: #0000ff;">addEventListener</span>(<span style="color: #0000ff;">IOErrorEvent.IO_ERROR</span>, ioErrorHandler);</code><br />
<code>&nbsp; &nbsp;varLoader.<span style="color: #0000ff;">load</span>(formRequest);</code><br />
<code>}</code></p>
<p><code><span style="color: #0000ff;">function</span> onLoaded(e:<span style="color: #0000ff;">Event</span>):<span style="color: #0000ff;">void</span> {</code><br />
<code>&nbsp; &nbsp;<span style="color: #999999;">// Insert success actions here</span></code><br />
<code>}</code></p>
<p><code><span style="color: #0000ff;">function</span> ioErrorHandler(e:<span style="color: #0000ff;">IOErrorEvent</span>):<span style="color: #0000ff;">void</span> {</code><br />
<code>&nbsp; &nbsp;<span style="color: #999999;">// Insert error actions here</span></code><br />
<code>}</code><br />
<code><span style="color:#999999;">/* --- End Code --- */</span></code></p>
<p>A few notes on the code:</p>
<ul>
<li>The <code>submitForm</code> function in this example is called on a <code>MouseEvent.CLICK</code> event (noted with the <code>e:MouseEvent</code> passed into the function).</li>
</ul>
<ul>
<li>If you need to send via GET, change the <code>URLRequestMethod</code> to <code>URLRequestMethod.GET</code>.</li>
</ul>
<ul>
<li>One thing I noticed about the <code>URLRequest</code> was that on the particular domain I was working on, using an absolute URL gave me some bugs.  If I used http://www.myfakedomain.com/flash.aspx, my tests failed on PCs but worked on Macs.  If I removed the “www”, resulting in http://myfakedomain.com/flash.aspx, my tests failed on Macs, but worked on PCs. I don’t know if this was an issue with how the domain was set up (since I only worked on the Flash portion, not setting up the domain) or if it is a Flash <code>URLRequest</code> bug.  Either way, I found that using a relative URL (“flash.aspx”) worked on Macs and PCs, and didn’t throw me any errors.</li>
</ul>
<p>Hope this sheds some insight on how to send data out of Flash.  Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/sending-flash-data-to-aspx-or-php-files/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

