<?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"
	>

<channel>
	<title>plasticBrain</title>
	<atom:link href="http://www.plasticbrain.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.plasticbrain.net</link>
	<description>The workings of a young, sleep deprived geek.</description>
	<pubDate>Mon, 22 Sep 2008 07:47:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>GUI Magnets Help Layout Your Website</title>
		<link>http://www.plasticbrain.net/design/gui-magnets-help-layout-your-website/</link>
		<comments>http://www.plasticbrain.net/design/gui-magnets-help-layout-your-website/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 07:39:18 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://www.plasticbrain.net/?p=177</guid>
		<description><![CDATA[


The first and most crucial part of designing a website is actually laying out it. There are several ways to do it &#8212; mind maps, sketch on a whiteboard, pencil and paper, etc &#8212; but those are no fun! While stumbling around the interweb the other night I came across something that was geeky, fun, [...]]]></description>
			<content:encoded><![CDATA[<p>
<a class="image" href="http://www.plasticbrain.net/design/gui-magnets-help-layout-your-website/"><img class="header-image" src="http://www.plasticbrain.net/wp-content/uploads/2008/09/header_gui_magnets.png" alt="Gui Magnets" title="header_gui_magnets" width="620" height="75" /></a>
</p>
<p>
The first and most crucial part of designing a website is actually laying out it. There are several ways to do it &#8212; <a href="http://en.wikipedia.org/wiki/Mind_map">mind maps</a>, sketch on a whiteboard, pencil and paper, etc &#8212; but those are no fun! While <a href="http://www.stumbleupon.com/">stumbling</a> around the interweb the other night I came across something that was geeky, fun, and most importantly useful&#8230; Check out <a href="http://www.guimagnets.com/order/">Gui Magnets</a> (or these <a href="http://www.guimags.com/guimags_magnets.php">Gui Magnets</a>) these things rock! Basically, they are little magnets thats contain all sorts of UI elements. There are scroll bars, text boxes, radio buttons, check boxes, drop down lists, and much more! They are coated with a &#8220;special&#8221; material that let&#8217;s you write on them with dry erase markers and then erase them when the fun is over. Did I mention that they stick to metal shit? Order. Now.
</p>
<p><span id="more-177"></span><br />
</p>
<p>
<img class="picleft" src="http://www.plasticbrain.net/wp-content/uploads/2008/09/gui_magnets.gif" alt="Gui Magnets" title="gui_magnets" width="618" height="120" /></p>
<div class="push"></div>
<div class="source">
<h2>Resources</h2>
<p>
<a href="http://www.guimagnets.com/order/">Gui Magnets</a> and <a href="http://www.guimags.com/guimags_magnets.php">More Gui Magnets</a>
</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.plasticbrain.net/design/gui-magnets-help-layout-your-website/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Design and Inspiration: Freak Show Art Work</title>
		<link>http://www.plasticbrain.net/design/freak-show-art-work/</link>
		<comments>http://www.plasticbrain.net/design/freak-show-art-work/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 04:41:11 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[design]]></category>

		<category><![CDATA[inspiration]]></category>

		<category><![CDATA[art]]></category>

		<guid isPermaLink="false">http://www.plasticbrain.net/?p=133</guid>
		<description><![CDATA[


Here is a nice collection of &#8220;Freak Show&#8221; art work, signs, and advertisements. These are all painted, wooden signs that I saw at a local fair and decided to get a few shots of. I have more, but these are the only ones that I have had the time to crop and resize. There&#8217;s some [...]]]></description>
			<content:encoded><![CDATA[<p>
<a class="image" href="http://www.plasticbrain.net/design/inspiration-freak-show-art-work/"><img src="http://www.plasticbrain.net/wp-content/uploads/2008/09/header_freak_show_art.png" alt="Freak Show Art" title="Freak Show Art" width="620" height="75" class="header-image" /></a>
</p>
<p>
Here is a nice collection of &#8220;Freak Show&#8221; art work, signs, and advertisements. These are all painted, wooden signs that I saw at a local fair and decided to get a few shots of. I have more, but these are the only ones that I have had the time to crop and resize. There&#8217;s some pretty cool stuff here.  I love the colors and the style &#8212; great inspiration!
</p>
<p><span id="more-133"></span><br />
</p>
<h2>Miss Olga Hess&#8230;The Headless Girl</h2>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/2877979502/in/set-72157607423369235/"><img class="picleft" alt="Olga Hess -- The Headless Girl 1" src="http://farm4.static.flickr.com/3233/2877979502_0d232fa18e.jpg?v=0" title="Olga Hess -- The Headless Girl 1" width="260" height="500" /></a></p>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/2877980612/in/set-72157607423369235/"><img class="picright" alt="Olga Hess -- The Headless Girl 2" src="http://farm4.static.flickr.com/3006/2877980612_68c87bbdf8.jpg?v=0" title="Olga Hess -- The Headless Girl 2" width="263" height="500" /></a></p>
<div class="push"></div>
<h2>Wild Woman</h2>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/2877979844/in/set-72157607423369235/"><img class="picleft" alt="Wild Woman" src="http://farm4.static.flickr.com/3163/2877979844_dd8c860a82.jpg?v=0" title="Wild Woman" width="330" height="500" /></a></p>
<div class="push"></div>
<h2>[Really Small] Bearded Woman</h2>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/2877148431/in/set-72157607423369235/"><img class="picleft" alt="Worlds Smallest Bearded Woman" src="http://farm4.static.flickr.com/3063/2877148431_b3f9ce9068.jpg?v=0" title="Worlds Smallest Bearded Woman" width="334" height="500" /></a></p>
<div class="push"></div>
<h2>Kid With Two Heads</h2>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/2877980194/in/set-72157607423369235/"><img class="picleft" alt="Kid With Two Heads" src="http://farm4.static.flickr.com/3121/2877980194_57fef5f2c8.jpg?v=0" title="Kid With Two Heads" width="340" height="500" /></a></p>
<div class="push"></div>
<h2>Multi-Headed, Multi-Legged, and Really Small Animals</h2>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/2877147551/in/set-72157607423369235/"><img class="picleft" alt="Two Headed Turtle" src="http://farm4.static.flickr.com/3264/2877147551_b0c2a5054a.jpg?v=0" title="Two Headed Turtle" width="322" height="500" /></a></p>
<div class="push"></div>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/2877147665/in/set-72157607423369235/"><img class="picleft" alt="Two Headed Snake" src="http://farm4.static.flickr.com/3138/2877147665_a29e289d86.jpg?v=0" title="Two Headed Snake" width="328" height="500" /></a></p>
<div class="push"></div>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/2877147765/in/set-72157607423369235/"><img class="picleft" alt="Worlds Smallest Horse" src="http://farm4.static.flickr.com/3080/2877147765_8f3965962b.jpg?v=0" title="Worlds Smallest Horse" width="317" height="500" /></a></p>
<div class="push"></div>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/2877981292/in/set-72157607423369235/"><img class="picleft" alt="Worlds Smallest Horse 2" src="http://farm4.static.flickr.com/3129/2877981292_5f504b0045.jpg?v=0" title="Worlds Smallest Horse 2" width="500" height="353" /></a></p>
<div class="push"></div>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/2877148049/in/set-72157607423369235/"><img class="picleft" alt="Six Legged Sheep" src="http://farm4.static.flickr.com/3291/2877148049_9e90418dd0.jpg?v=0" title="Six Legged Sheep" width="295" height="500" /></a></p>
<div class="push"></div>
<p>That&#8217;s all for today! Whenever I find the time I will crop, resize, and upload the rest of the images that I have.
</p>
<div class="source">
<h2>Resources</h2>
<p><a href="http://www.flickr.com/photos/plasticbrainmedia/sets/72157607423369235/">View these pictures on Flickr</a>!
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.plasticbrain.net/design/freak-show-art-work/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP - Validating Email Address and Phone Number</title>
		<link>http://www.plasticbrain.net/code/php-validating-email-address-and-phone-number/</link>
		<comments>http://www.plasticbrain.net/code/php-validating-email-address-and-phone-number/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 09:20:58 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.plasticbrain.net/?p=11</guid>
		<description><![CDATA[Do you have a form and need to validate an email address or phone number? Here we have an example of how to do just that&#8230;validate an email address and validate a phone number &#8212; for Both standard phone numbers and 800/866/900/etc numbers!


Getting Started
Our final product will contain three different parts: An HTML form, the [...]]]></description>
			<content:encoded><![CDATA[<p><a class="image" href="http://www.plasticbrain.net/code/php-validating-email-address-and-phone-number/" ><img src="http://www.plasticbrain.net/wp-content/uploads/2008/09/header_validate_form.png" alt="PHP - Validating Email address and Phone Number" title="PHP - Validating Email address and Phone Number" width="620" height="75" class="header-image" /></a></p>
<p>Do you have a form and need to validate an email address or phone number? Here we have an example of how to do just that&#8230;validate an email address and validate a phone number &#8212; for Both standard phone numbers and 800/866/900/etc numbers!</p>
<p><span id="more-11"></span><br />
</p>
<h2>Getting Started</h2>
<p>Our final product will contain three different parts: An HTML form, the php that validates the form, and the css that styles everything. The PHP and the HTML form are setup to go in the same file but you can (and should!) copy the CSS to your existing stylesheet.</p>
<h3>The Form</h3>
<p>
<img src="http://www.plasticbrain.net/wp-content/uploads/2008/09/form.gif" alt="What our form looks like" title="form" width="273" height="199" class="picright" /></p>
<p>Our form is a typical one. One like you have seen on websites everywhere. It includes fields for <strong>name</strong>, <strong>phone number</strong>, <strong>email address</strong>, and a <strong>message</strong>.</p>
<p>As you can see in the picture, we are making some of the fields <em><span class="req">required</span></em>. Aside from that, we will also be validating the name, phone number, and email address (and making sure the message is not left blank.)</p>
<h3>The Code</h3>
<p>
The code is pretty straightforward &#8212; and heavily commented &#8212; so take a look. After you are finished looking at it we will go over what it does and exactly how it does it.
</p>
<h4>style.css</h4>
<pre>
/* "holds" everything... in this case it just determines the overall width*/
 #holder {
      width: 600px;
    }

/* styles the text boxes and text area */
    input.text, textarea {
      width: 300px;
      border: 1px solid #ccc;
      margin: 0 0 10px 0;
      padding: 0 0 0 3px;
      height: 24px;
      font-size: 16px;
    }

/* Set the height for the text area */
    textarea {
      height: 150px;
    }

/* Make the submit button push to the right side of the form */
    input#submit {
      margin: 0 0 0 320px;
    }

/* style the labels that are in front of the text boxes */
    label {
      width: 90px;
      text-align: right;
      display: block;
      float: left;
      font-size: 14px;
      margin: 0 5px 0 0;
      padding: 4px 0 0 0;
    }

/* Make our "required" labels red */
    span.req {
      color: #ff0000;
    }

/* The "status bar" at the top -- blue for messages */
    span.message {
      display: block;
      background-color: #DFF1FF;
      border: 2px solid #8FD7FF ;
      color: #333;
      margin: 0 0 20px 0;
      padding: 7px;
      text-align: left;
      font-size: 14px;
    }

/* The "status bar" at the top -- red for errors */
    span.error { /* red */
      display: block;
      background-color: #FFBFC2;
      border: 2px solid #FF6F75 ;
      color: #444;
      margin: 0 0 20px 0;
      padding: 7px;
      text-align: left;
      font-size: 14px;
      font-weight: bold;
    }

/* set the margin and padding for the ul's in the status bar */
    span ul {
      margin: 0;
      padding: 0 0 0 20px;
    }

/* set the margin and padding for the li's in the status bar */
    span ul li {
      margin: 0;
      padding: 0;
    }
  </style>
</pre>
<h4>validate_form.php</h4>
<pre>
&lt;?php

// Updated 2008-09-21
// Validate Email Address and Phone -- ©2008 PlasticBrain
// www.plasticbrain.net
// ---------------------------------------------------------

// see if the "submit" button was pushed

if (isset($_POST['submit'])) {

  // gather the POST data
  $name = $_POST['name'];
  $phone = $_POST['phone'];
  $email = $_POST['email'];
  $message = $_POST['message'];

  // make sure our variables are empty
  $error = array();
  $msg = "";
  $error_msg = "";

// validate name 

  if (strlen(trim($name)) > 0) {
    if(!ereg('^[a-z A-Z]+$', $name)){
      $error['name'] = "Your name contains invalid characters. Only letters are allowed! "; // invalid characters
    }

  } else {
    $error['name'] = "Please enter your name!"; // the name field was left blank
  }  

//validate phone number

if (strlen(trim($phone)) > 0) {
    if(!ereg('^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$', $phone)){  //
      $error['phone'] = "Your phone number is not valid!";
    }
  } 

//validate email

  if (strlen(trim($email)) > 0) {
    if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
      $error['email'] = "Your email address is not valid!";
    }

  } else {
    $error['email'] = "Please enter your email address!";
  }

// Check the message

if (!strlen(trim($message)) > 0) {
  $error['message'] = "Please enter your message!";
}

//
// We are finished validating the form. Now, let's see if there were any errors.
// If there are no errors, we proceed. If there are errors, we will print
// them to the screen and highlight the fields in the form
//

if (empty($error)) {

// There were no errors!
  $msg = "Congrats, $name! There were no errors in the form!";

} else {  

// There were errors, let's set the styles for the fields
  $error_msg = "&lt;ul&gt;\n";

  foreach($error as $field =&gt; $message) {
    $style[$field] = "border: 1px solid #ff0000 !important;;
                      background-color: #FFEFEF !important;";
    $error_msg .= "&lt;li&gt;$message&lt;/li&gt;\n";
  }

  $error_msg .= "&lt;/ul&gt;\n";
}

} // end check for submit button...

//
// Now we print the form...
//

?&gt;

  &lt;div id="holder"&gt;
    &lt;?php
      if (isset($error_msg) &#038;&#038; strlen(trim($error_msg)) > 0) {
        echo "&lt;span class=\"error\"&gt; $error_msg &lt;/span&gt;\n";
      }

      if (isset($msg) &#038;&#038; strlen(trim($msg)) > 0) {
        echo "&lt;span class=\"message\"&gt; $msg &lt;/span&gt;\n";
      }
    ?&gt;

	  &lt;form action="&lt;?php $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
	    &lt;label&gt;Name&lt;span class="req"&gt;*&lt;/span&gt; &lt;/label&gt;
	    &lt;input type="text" class="text" name="name" style="&lt;?php echo $style['name']; ?&gt;" value="&lt;?php if (isset($_POST['name'])) { echo $_POST['name']; } ?&gt;" /&gt;&lt;br /&gt;

	    &lt;label&gt;Phone Number&lt;/label&gt;
	    &lt;input type="text" class="text" name="phone" style="&lt;?php echo $style['phone']; ?&gt;" value="&lt;?php if (isset($_POST['phone'])) { echo $_POST['phone']; } ?&gt;" /&gt;&lt;br /&gt;

	    &lt;label&gt;Email&lt;span class="req"&gt;*&lt;/span&gt; &lt;/label&gt;
      &lt;input type="text" class="text" name="email" style="&lt;?php echo $style['email']; ?&gt;" value="&lt;?php if (isset($_POST['email'])) { echo $_POST['email']; } ?&gt;" /&gt;&lt;br /&gt;

	    &lt;label&gt;Message&lt;span class="req"&gt;*&lt;/span&gt; &lt;/label&gt;
	    &lt;textarea name="message" style="&lt;?php echo $style['message']; ?&gt;" cols="" rows=""&gt;&lt;?php if (isset($_POST['message'])) { echo $_POST['message']; } ?&gt;&lt;/textarea&gt;&lt;br /&gt;

	    &lt;input type="submit" name="submit" id="submit" value="submit &rarr;" /&gt;
    &lt;/form&gt;
  &lt;/div&gt;
</pre>
<h2>Was the Form Submitted?</h2>
<p>
Let&#8217;s take a look at the code. Starting at the top:</p>
<blockquote class="code"><p>if (isset($_POST['submit'])) </p></blockquote>
<p>When the page is loaded, this line of code checks the POST data &#8212; if there is any &#8212; to see if the &#8220;submit&#8221; button was pushed. If you were wondering how our PHP code knew the name of our button then take look at the HTML code for the form. You will notice that we gave our button the <strong>name</strong> &#8220;submit&#8221;. If the button was pressed, we continue on to the next lines of code: </p>
<blockquote class="code"><p>
// gather the POST data<br />
$name = $_POST['name'];<br />
&#8230;</p>
<p>// make sure our variables are empty<br />
$error = array();<br />
&#8230;
</p></blockquote>
<p>As the comments suggest, these lines get the POST data and makes sure that our variables that we will be using are empty.</p>
<h2>Validate the Data</h2>
<p>
Now we need to take all of the data that was submitted and make sure it meets our guidelines. If it doesn&#8217;t we need to let the user know!
</p>
<h3>Name</h3>
<blockquote class="code">
<pre>
 if (strlen(trim($name)) > 0) {
</pre>
</blockquote>
<p> First, we remove any whitespace from the name. Then we make sure that it was not left blank by verifying that it&#8217;s length (minus any spaces) is at least 1 character. You can increase this number for a more accurate judgement.
</pre>
</blockquote>
<blockquote class="code">
<pre>
if(!ereg('^[a-z A-Z]+$', $name)){
</pre>
</blockquote>
<p>If the user did enter a name, we then use ereg to make sure that it matches a certain pattern. In this case the pattern is: <strong>^[a-z A-Z]+$</strong> <br />The ^ signals the beginning of the string. The [a-zA-Z] tells us that we can only have upper or lowercase letters from A to Z. The $ signals the end of the string.</p>
<blockquote class="code">
<pre>
$error['name'] = "Your name contains invalid characters. Only letters are allowed! "; // invalid characters
}
</pre>
</blockquote>
<p>If the name does not match the pattern we add an error message to our &#8220;error&#8221; array as <strong>error['name']</strong></p>
<blockquote class="code">
<pre>
} else {
  $error['name'] = "Please enter your name!"; // the name field was left blank
}
</pre>
</blockquote>
<p>Remember, the name was required! If it was left blank, we add a (slightly different) error message to the array.
</p>
<h3>Phone Number </h3>
<p>
To check the phone number, we use ereg again, but with a different pattern: <strong>^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$</strong><br />
This pattern will check both &#8220;standard&#8221; numbers (555-555-1234) and 1-800 style numbers. Let&#8217;s take a look.</p>
<blockquote class="code"><pre>
if(!ereg('^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$', $phone)){  //
    $error['phone'] = "Your phone number is not valid!";
  }
</pre>
</blockquote>
<p>Again, the ^ signals the start, and the $ signals the end.  <strong>([1]-)?</strong> says that there <em>might be</em> one number and a hyphen at the beginning (for 1-800 numbers) <em>but there might not be</em>. <strong>[0-9]{3}-</strong> verifies that there are numbers <strong>[0-9]</strong> and that there are three of them <strong>{3}</strong> followed by a hyphen <strong>-</strong>. If the number does not match our pattern, we set an error for it in our array.
</p>
<h3>Email Address</h3>
<p>
Since email addresses are a bit more complicated than phone numbers, we will use a similar, yet slightly different function. We use <strong>ereg<em>i</em></strong> instead of <strong>ereg</strong>. They are the exact same function, except eregi ignores case when matching. This prevents us from having to type [a-zA-Z] each time.</p>
<blockquote class="code"><pre>
if (strlen(trim($email)) > 0) {
  if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
   $error['email'] = "Your email address is not valid!";
  }
} else {
 $error['email'] = "Please enter your email address!";
}
</pre>
</blockquote>
<p>The pattern here is a bit more complicated. Think you can figure it out on your own? I <a href="http://www.webcheatsheet.com/php/regular_expressions.php">Think</a> <a href="http://www.roscripts.com/PHP_regular_expressions_examples-136.html">you</a> <a href="http://www.sitepoint.com/article/regular-expressions-php/">can</a> <img src='http://www.plasticbrain.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />
</p>
<h3>Message</h3>
<blockquote class="code"><pre>
if (!strlen(trim($message)) > 0) {
  $error['message'] = "Please enter your message!";
}
</pre>
</blockquote>
<p>This one is simple enough. We remove the whitespace and make sure that it has as least one character. If not, we add an error.
</p>
<h2>Checking for Errors</h2>
<p>Now that we have validated all of the submitted data it&#8217;s time to either let the user know of any errors, or continue with our script if there were none.</p>
<blockquote class="code"><pre>
if (empty($error)) {
</pre>
</blockquote>
<p>This checks to see if our array <strong>$error</strong> contains any data. If it is empty, we know that there were no errors:
</p>
<blockquote class="code"><pre>
// There were no errors!
  $msg = "Congrats, $name! There were no errors in the form!";
</pre>
</blockquote>
<p>Here, we simply display a nice message saying that there were no errors. In real life, this is where you would put the code to do whatever it is that you are actually wanting to do with this form &#8212; send an email, add data to a database, submit comments to a blog post, whatever.
</p>
<blockquote class="code"><pre>
} else {  

// There were errors, let's set the styles for the fields
</pre>
</blockquote>
<p>If we get to this point, it means that our <strong>$error</strong> array is not empty &#8212; it&#8217;s holding data about the errors on the form.
</p>
<blockquote class="code"><pre>
  $error_msg = "&lt;ul&gt;\n";

  foreach($error as $field => $message) {
    $style[$field] = "border: 1px solid #ff0000 !important;;
                          background-color: #FFEFEF !important;";
    $error_msg .= "&lt;li&gt;$message&lt;/li&gt;\n";
  }

  $error_msg .= "&lt;/ul&gt;\n";
}
</pre>
</blockquote>
<p>Here, we use a new variable &#8212; <strong>$error_message</strong> &#8212; to create an unordered list that displays each of the messages. Then, we use <strong>foreach</strong> to loop through our <strong>$error</strong> array. For each error it takes the <strong>key</strong> of the array (which is the field name) and the <strong>value</strong> of the array (which is the error that we set) and adds it to our list. At the same time that this happens, you will notice that we create yet another array &#8212; actually, we create several arrays &#8212; called <strong>$style[$field]</strong>. Do you see what we did there? We created an array called <strong>style</strong> for each of the fields with an error. Why did we do that? Well, that&#8217;s how we determine which fields to highlight on the form to let the user know about their errors. We could further extend this and display the error messages under each text box, create individual styles for each text box, and so on. But, we have dragged this one out long enough so that will have to wait for another time!
</p>
<h4>Printing the Form</h4>
<p>
I know some of you are thinking &#8220;Wait a minute&#8230; we need the form to be shown FIRST, so why is it LAST?!!1!!one!&#8221; Well, we have a good answer for that. Our code comes first because the <strong>action</strong> for our form is set to post back to the same page in which it originated from. This means that when you submit the form, essentially the page is just reloaded. That&#8217;s why the PHP needs to be at the top. To catch all of the POSTed data. Also, with it setup this way you are able to use a header redirect if the form is submitted without errors (say, for a login script).</p>
<p>
Another thing you will notice before we even get to the form is that we have some more code:</p>
<blockquote class="code"><pre>
&lt;div id="holder"&gt;
    &lt;?php
      if (isset($error_msg) &#038;&#038; strlen(trim($error_msg)) > 0) {
        echo "&lt;span class=\"error\"&gt; $error_msg &lt;/span&gt;\n";
      }

      if (isset($msg) &#038;&#038; strlen(trim($msg)) &gt; 0) {
        echo "&lt;span class=\"message\"&gt; $msg &lt;span&gt;\n";
      }
    ?&gt;
</pre>
</blockquote>
<p>This is the code that we use to check for, and display, our error messages (and in this case our message for success.) Notice that we check for the string that we created &#8212; <strong>$error_msg</strong> &#8212; and not the $errors array. If it is set then we drop it between some span tags that we define in the CSS. Also notice our beginning <strong>&lt;div id=&#8221;holder&#8221;&gt;</strong>
</p>
<blockquote class="code"><pre>
&lt;form action="&lt;?php $_SERVER['PHP_SELF']; ?>" method="post">
	    &lt;label>Name&lt;span class="req"&gt;*&lt;/span>&lt;/label>
	    &lt;input type="text" class="text" name="name" style="&lt;?php echo $style['name']; ?>" value="&lt;?php if (isset($_POST['name'])) { echo $_POST['name']; } ?>" />&lt;br />

	    &lt;label>Phone Number&lt;/label>
	    &lt;input type="text" class="text" name="phone" style="&lt;?php echo $style['phone']; ?>" value="&lt;?php if (isset($_POST['phone'])) { echo $_POST['phone']; } ?>" />&lt;br />

           <strong>...</strong>

	    &lt;input type="submit" name="submit" id="submit" value="submit →" />
    &lt;/form>
 &lt;/div>
</pre>
</blockquote>
<p></p>
<p>
Here we have your basic HTML form, with a bit of added flavor&#8230; First, we have the form action that we mentioned earlier: <strong>&lt;?php $_SERVER['PHP_SELF']; ?&gt;</strong> tells the form to submit back to the same page.</p>
<p>
After that, we have a standard label and an input (text) box. Notice that for required fields, we add &lt;span class=&#8221;req&#8221;&gt;*&lt;/span&gt; to the labels for our red asterisk <span class="req">*</span>.
</p>
<p>The main thing to pay attention to here is the <strong>style</strong> for each of the inputs. Notice that it&#8217;s set as <strong>style=&#8221;&lt;?php echo $style['name']; ?&gt;</strong> (or whatever the input&#8217;s <strong>name</strong> is) We use this in conjunction with the <strong>$style</strong> array that was created earlier to highlight the incorrect fields. With me so far? Good! </p>
<p>
Last is our submit button. The important thing here is the <strong>name</strong> that we give it. It must match whatever it is that you are checking for at the beginning of the script &#8211;<strong>if (isset($_POST['<span class="req">submit</span>']))</strong>! </p>
<h2>So, What Does This Thing Look Like?</h2>
<p>Glad you asked! Let&#8217;s take a look:</p>
<p><img src="http://www.plasticbrain.net/wp-content/uploads/2008/09/form_error1.gif" alt="Form with errors" title="form_error1" width="273" height="199" class="picleft" />If you just copy and past the code you will get results similar to what you see here. Nothing too fancy. We just display each error message, and change the borders to a bold red and the backgrounds to a light red on those fields with errors. </p>
<div class="push20"></div>
<h2>Get Creative!</h2>
<p>With a little tweaking, you can do other, fancier stuff like:<br />
<img src="http://www.plasticbrain.net/wp-content/uploads/2008/09/form_fancy.gif" alt="Fancy Form" title="Fancy Form" width="572" height="145" class="piccenter" />
</p>
<h2>Download the Script</h2>
<div class="source">
<p>
validate_form.txt - <a href="http://plasticbrain.net/scripts/validate-form/validate_form.php">View Demo</a> - <a href="http://plasticbrain.net/scripts/validate-form/validate_form.txt">Download</a> <small>(5KB)</small></p>
<p>validate_form (fancy version) - <a href="http://plasticbrain.net/scripts/validate-form/validate_form_fancy.php">View Demo</a>
</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.plasticbrain.net/code/php-validating-email-address-and-phone-number/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Photoshop CS4 Demo (video)</title>
		<link>http://www.plasticbrain.net/photoshop/photoshop-cs4-demo-video/</link>
		<comments>http://www.plasticbrain.net/photoshop/photoshop-cs4-demo-video/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 09:15:43 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[photoshop]]></category>

		<guid isPermaLink="false">http://www.plasticbrain.net/?p=23</guid>
		<description><![CDATA[Adobe&#8217;s Terry White posted an awesome video demo of some of the new stuff available in Photoshop CS4. This is the first full development cycle of the Creative Suite since Adode acquired Macromedia a while back. Needless to say, everyone had extremely high expectations. We all figured that since the two companies joined that there [...]]]></description>
			<content:encoded><![CDATA[<p><a class="image" href="http://www.plasticbrain.net/photoshop/photoshop-cs4-demo-video/" ><img src="http://www.plasticbrain.net/wp-content/uploads/2008/09/header_cs4_video_demo.png" alt="Photoshop CS4 Demo (video)" title="Photoshop CS4 Demo (video)" width="620" height="75" class="header-image" /></a></p>
<p>Adobe&#8217;s <a href="http://creativesuitepodcast.com/index.php?post_id=375336">Terry White posted an awesome video demo</a> of some of the new stuff available in Photoshop CS4. This is the first full development cycle of the Creative Suite since Adode acquired Macromedia a while back. Needless to say, everyone had extremely high expectations. We all figured that since the two companies joined that there would be tighter integration with Flash. However, Adobe has gone above and beyond with this version. Not only is there tighter Flash integration now the entire Creative Suite works together seamlessly. And that is just the beginning&#8230; Wait until you see some of the new features that will be available in Photoshop CS4!</p>
<p>[Video After The Jump]<br />
<span id="more-23"></span></p>
<p>The video is good, but it is long. Not to mention the first 15 minutes are pretty much fluff. Fast Forward to the 16 minute mark to get to the good stuff!<br />
<embed src="http://blip.tv/play/gaVazOV+jeID" type="application/x-shockwave-flash" width="640" height="382" allowscriptaccess="always" allowfullscreen="true"></embed></p>
<p></p>
<p>Some of the things that are highlighted in the video include:</p>
<ul>
<li><em><strong>Much</strong> better performance.</em><br />
<blockquote><p>
They demonstrate by working with a <strong>442 megapixel</strong> image that is 2gb big and suffer almost no system lag!</p></blockquote>
</li>
<li><em>Improved 3D capabilities.</em><br />
<blockquote><p>The 3D capability in CS4 is amazing! You basically have the ability to work with 3d files directly in Photoshop now. You can mess with the light sources, draw directly on the 3d textures, create <a href="http://en.wikipedia.org/wiki/Anaglyph_image">anaglyph images</a> (the ones you look at while wearing the goofy red and blue 3d glasses) and much more. Plus you have the ability to transform panoramic images into three dimensional &#8220;environments&#8221; and then export them into a flash video &#8212; think  real estate sites. You know those fancy, 3d sort of &#8220;walk through&#8221; views of a room? Yea&#8230; Photoshop can now do that in a matter of minutes!</p></blockquote>
</li>
<li><em>Resize brush by dragging mouse</em><br />
<blockquote><p>It&#8217;s not really talked about, but if you forward to 25:00 in the video you will see them resizing the brush by dragging the mouse. The guy merely mentions it. Kind of like a throw away comment. This feature is excellent and definitely deserved more attention!</p></blockquote>
</li>
<li><em>Content Aware Image Resizing (also know as seam carving, or &#8220;totally kick ass&#8221;) </em><br />
<blockquote><p>You may have seen the hype around the interwebs a while back about a couple of guys that created some kick ass image resizing technology (see the video below.) Everyone that saw it was absolutely amazed&#8230;including the guys over at Adobe! About a week after the video hit the web Adobe, not wanting to miss out, <a href="http://blogs.adobe.com/jnack/2007/08/imaging_heavy_h.html">hired one of the developers</a> to help them integrate the feature into Photoshop. This is, by far, the coolest feature that we have seen come to the Photoshop franchise in a while. Watch the video below and be amazed:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/vIFCV2spKtg&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/vIFCV2spKtg&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>
</p></blockquote>
</li>
</ul>
<p>This version of Creative Suite seems to really drive home three points:</p>
<ul>
<li>Cutting edge technology</li>
<li>Better integration</li>
<li>Increased productivity</li>
</ul>
<p>And by the looks of the demo they really nailed it!
</p>
<p>
You may also <a href="http://adobe.com/go/somethingbrilliant">register to view an online presentation</a> on September 23, 2008 that showcases even more features that will be in CS4. Register at <a href="http://adobe.com/go/somethingbrilliant">http://adobe.com/go/somethingbrilliant</a>. If you just can&#8217;t get enough Adobe information for one day, <a href="https://admin.connectpro.acrobat.com/_a791863308/p40652716/">checkout this presentation by John Nack</a>. It&#8217;s long winded, but there are a couple more Photshop CS4 features hidden away inside plus loads of other Adobe-centric info.
</p>
<p>I really think that Creative Suite 4 is going to completely revolutionize the media industry as a whole. Even if it doesn&#8217;t&#8230; it will make my life easier and that counts for something!</p>
<div class="source">
<h2>Sources</h2>
<p><a href="http://www.creativetechs.com/iq/sneak_peeks_at_adobe_photoshop_cs4.html">CreativeTechs.com</a>, <a href="http://creativesuitepodcast.com/index.php?post_id=375336">CreativeSuitePodcast.com</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.plasticbrain.net/photoshop/photoshop-cs4-demo-video/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flying to LA for Harrison&#8217;s Bday!</title>
		<link>http://www.plasticbrain.net/upcoming-events/flying-to-la-for-harrisons-bday/</link>
		<comments>http://www.plasticbrain.net/upcoming-events/flying-to-la-for-harrisons-bday/#comments</comments>
		<pubDate>Sat, 31 May 2008 06:32:51 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[upcoming events]]></category>

		<guid isPermaLink="false">http://www.plasticbrain.net/?p=17</guid>
		<description><![CDATA[[ June 18, 2008 10:40 am to June 23, 2008 6:45 pm. ] Lane and I are going to California for Harrison's birthday -- it's gonna be the shit!]]></description>
			<content:encoded><![CDATA[<table class="ec3_schedule"><tr><td class="ec3_start">June 18, 2008 10:40 am</td><td class="ec3_to">to</td><td class="ec3_end">June 23, 2008 6:45 pm</td></tr></table><p>Lane and I are going to California for Harrison&#8217;s birthday &#8212; it&#8217;s gonna be the shit!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.plasticbrain.net/upcoming-events/flying-to-la-for-harrisons-bday/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP - Link Cloaking Script</title>
		<link>http://www.plasticbrain.net/code/php-link-cloaking-script/</link>
		<comments>http://www.plasticbrain.net/code/php-link-cloaking-script/#comments</comments>
		<pubDate>Tue, 27 May 2008 09:00:55 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.plasticbrain.net/?p=10</guid>
		<description><![CDATA[This script will mask the links on your website. This is important if you do any affiliate marketing. The major search engines will compare your links with their database of &#8220;known affiliates&#8221; and they will penalize you in the form of high minimum bids. Don&#8217;t worry though, this simple little script will &#8220;mask&#8221; (cloak) your [...]]]></description>
			<content:encoded><![CDATA[<p><a class="image" href="http://www.plasticbrain.net/code/php-link-cloaking-script/"><img src="http://www.plasticbrain.net/wp-content/uploads/2008/09/header_link_cloak.png" alt="PHP - Link Cloaking Script" title="PHP - Link Cloaking Script" width="620" height="75" class="header-image" /></a></p>
<p>This script will mask the links on your website. This is important if you do any affiliate marketing. The major search engines will compare your links with their database of &#8220;known affiliates&#8221; and they will penalize you in the form of high minimum bids. Don&#8217;t worry though, this simple little script will &#8220;mask&#8221; (cloak) your links so that all the search engines (and users) see is something like www.yoursite.com/out.php?id=google</p>
<p><span id="more-10"></span></p>
<p>If you have problems copying and pasting the code below, you can <a href="http://plasticbrain.net/scripts/link-cloak.php.txt">download a copy here</a></p>
<h3>Instructions</h3>
<ol>
<li> Copy and paste the script below into an empty php file (our example was called out.php)</li>
<li> Edit the section that says &#8220;edit your links here!&#8221;
<p>The format is as follows:<br />
      &#8220;link_id&#8221; => &#8220;http//www.your_link_goes_here.com&#8221;</p>
<p>where &#8220;link_id&#8221; is the id you pass in the URL like: www.yoursite.com/out.php?id=link_id</p>
<p>Notice that there is a comma at the end of each line EXCEPT the last one!</p>
</li>
</ol>
<pre>

&lt;?php

// Link Cloaking Script -- ©2008 PlasticBrain
// www.plasticbrain.net
// ---------------------------------------------------------
// Edit the "links" section below. Format them like:
// "link_id" => "http//www.your_link_goes_here.com"
//
// where "link_id" is the id you pass in the URL
// www.yoursite.com/out.php?id=link_id
//
// if you need help visit us at www.plasticbrain.net
// ---------------------------------------------------------

$links = array(

// -- edit your links here! -- Notice that there is a comma after each entry EXCEPT the last one!!!

"1" => "http://www.your_link_here.com",
"2" => "http://www.another_link_here.com"

// -- Stop editing here! --
);

$id = $_GET['id'];

header("Location:".$links[$id]);
exit;

?&gt;
</pre>
<div class="source">
<h2>download the script</h2>
<p><a href="http://plasticbrain.net/scripts/link-cloak.txt">link-cloak.txt</a> <small>(1KB)</small></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.plasticbrain.net/code/php-link-cloaking-script/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flying to Boulder Colorado</title>
		<link>http://www.plasticbrain.net/upcoming-events/flying-to-boulder-colorado/</link>
		<comments>http://www.plasticbrain.net/upcoming-events/flying-to-boulder-colorado/#comments</comments>
		<pubDate>Sun, 25 May 2008 13:10:07 +0000</pubDate>
		<dc:creator>mike</dc:creator>
		
		<category><![CDATA[upcoming events]]></category>

		<guid isPermaLink="false">http://www.plasticbrain.net/?p=16</guid>
		<description><![CDATA[[ July 10, 2008 4:05 pm to July 14, 2008 2:25 pm. ] Going to meet up with the rest of the team!]]></description>
			<content:encoded><![CDATA[<table class="ec3_schedule"><tr><td class="ec3_start">July 10, 2008 4:05 pm</td><td class="ec3_to">to</td><td class="ec3_end">July 14, 2008 2:25 pm</td></tr></table><p>Going to meet up with the rest of the team!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.plasticbrain.net/upcoming-events/flying-to-boulder-colorado/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
