<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[UnDefined]]></title>
  <link href="http://jonahlyn.heroku.com/atom.xml" rel="self"/>
  <link href="http://jonahlyn.heroku.com/"/>
  <updated>2011-12-22T21:37:00-07:00</updated>
  <id>http://jonahlyn.heroku.com/</id>
  <author>
    <name><![CDATA[Jonahlyn Gilstrap]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Dabbling With CSS3 Backgrounds and Gradients]]></title>
    <link href="http://jonahlyn.heroku.com/blog/2011/12/17/dabbling-with-css3-backgrounds-gradients/"/>
    <updated>2011-12-17T20:38:00-07:00</updated>
    <id>http://jonahlyn.heroku.com/blog/2011/12/17/dabbling-with-css3-backgrounds-gradients</id>
    <content type="html"><![CDATA[<div class="demo">
<a target="_blank" class="button" href="http://dabblet.com/gist/1486751">Demo</a>
</div>


<p>A few weeks ago I was trying to figure out how to create a thin, vertical line using CSS the purpose of which was to separate two sections of a web page, for instance a side bar from main content, that would be offset a number of pixels from the top of the element. I couldn&#8217;t use a border because of the offset needed (I don&#8217;t think) and modifying the underlying HTML was out.</p>

<p>Reading <a href="http://24ways.org/2011/css3-patterns-explained">this 24ways article on CSS3 patterns</a> helped me to understand css3 gradients and multiple backgrounds a little better and gave me some ideas on how I might accomplish this using CSS3.</p>

<!--more-->


<p>Multiple backgrounds are applied in layers so the top-most background will cover the backgrounds underneath it. I found it helpful to create the backgrounds separately and then combine them together in the end.</p>

<p>I started with creating a 4 pixel wide, solid grey, vertical line at the 240 pixel mark. This would be my bottom-most background layer.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="nt">background-color</span><span class="o">:</span> <span class="nf">#fff</span><span class="o">;</span>
</span><span class='line'><span class="nt">background-image</span><span class="o">:</span>
</span><span class='line'>  <span class="nt">linear-gradient</span><span class="o">(</span><span class="nt">0deg</span><span class="o">,</span> <span class="nt">transparent</span> <span class="nt">240px</span><span class="o">,</span> <span class="nf">#5e5d60</span> <span class="nt">240px</span><span class="o">,</span> <span class="nf">#5e5d60</span> <span class="nt">244px</span><span class="o">,</span> <span class="nt">transparent</span> <span class="nt">244px</span><span class="o">,</span> <span class="nt">transparent</span><span class="o">);</span>
</span><span class='line'><span class="nt">background-size</span><span class="o">:</span> <span class="nt">100</span><span class="o">%;</span>
</span><span class='line'><span class="nt">min-height</span><span class="o">:</span> <span class="nt">100</span><span class="o">%;</span>
</span></code></pre></td></tr></table></div></figure>


<p>Next, I created a series of 1 pixel high horizontal lines alternating white and transparent. The 2 pixel height specified in &#8220;background-size&#8221; accommodates 2 lines and all of this repeats vertically to create multiple lines. Note the background color was changed so the transparent lines could be seen.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="nt">background-color</span><span class="o">:</span> <span class="nf">#5e5d60</span><span class="o">;</span>
</span><span class='line'><span class="nt">background-image</span><span class="o">:</span>
</span><span class='line'>  <span class="nt">linear-gradient</span><span class="o">(</span><span class="nt">top</span><span class="o">,</span> <span class="nf">#fff</span> <span class="nt">1px</span><span class="o">,</span> <span class="nt">transparent</span> <span class="nt">1px</span><span class="o">);</span>
</span><span class='line'><span class="nt">background-size</span><span class="o">:</span> <span class="nt">100</span><span class="o">%</span> <span class="nt">2px</span><span class="o">;</span>
</span><span class='line'><span class="nt">min-height</span><span class="o">:</span> <span class="nt">100</span><span class="o">%;</span>
</span></code></pre></td></tr></table></div></figure>


<p>For the offset I created a solid white block covering the top 70 pixels with the remainder being transparent. The background color here was also changed so the white block could be seen.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="nt">background-color</span><span class="o">:</span> <span class="nf">#5e5d60</span><span class="o">;</span>
</span><span class='line'><span class="nt">background-image</span><span class="o">:</span>
</span><span class='line'>  <span class="nt">linear-gradient</span><span class="o">(</span><span class="nt">top</span><span class="o">,</span> <span class="nf">#fff</span> <span class="nt">70px</span><span class="o">,</span> <span class="nt">transparent</span> <span class="nt">70px</span><span class="o">);</span>
</span><span class='line'><span class="nt">background-size</span><span class="o">:</span> <span class="nt">100</span><span class="o">%;</span>
</span><span class='line'><span class="nt">min-height</span><span class="o">:</span> <span class="nt">100</span><span class="o">%;</span>
</span></code></pre></td></tr></table></div></figure>


<p>And finally combining all the backgrounds together produces the separator line:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="nt">background-color</span><span class="o">:</span> <span class="nf">#fff</span><span class="o">;</span>
</span><span class='line'><span class="nt">background-image</span><span class="o">:</span>
</span><span class='line'>  <span class="nt">linear-gradient</span><span class="o">(</span><span class="nt">top</span><span class="o">,</span> <span class="nf">#fff</span> <span class="nt">70px</span><span class="o">,</span> <span class="nt">transparent</span> <span class="nt">70px</span><span class="o">),</span>
</span><span class='line'>  <span class="nt">linear-gradient</span><span class="o">(</span><span class="nt">top</span><span class="o">,</span> <span class="nf">#fff</span> <span class="nt">1px</span><span class="o">,</span> <span class="nt">transparent</span> <span class="nt">1px</span><span class="o">),</span>
</span><span class='line'>  <span class="nt">linear-gradient</span><span class="o">(</span><span class="nt">0deg</span><span class="o">,</span> <span class="nt">transparent</span> <span class="nt">240px</span><span class="o">,</span> <span class="nf">#5e5d60</span> <span class="nt">240px</span><span class="o">,</span> <span class="nf">#5e5d60</span> <span class="nt">244px</span><span class="o">,</span> <span class="nt">transparent</span> <span class="nt">244px</span><span class="o">,</span> <span class="nt">transparent</span><span class="o">);</span>
</span><span class='line'><span class="nt">background-size</span><span class="o">:</span> <span class="nt">100</span><span class="o">%,</span> <span class="nt">100</span><span class="o">%</span> <span class="nt">2px</span><span class="o">,</span> <span class="nt">100</span><span class="o">%;</span>
</span><span class='line'><span class="nt">min-height</span><span class="o">:</span> <span class="nt">100</span><span class="o">%;</span>
</span></code></pre></td></tr></table></div></figure>


<p>Not very exciting compared to the <a href="http://lea.verou.me/css3patterns/">other CSS3 backround patterns</a> that have been coming out lately but cool enough considering a few weeks ago I didn&#8217;t think it was possible to do without creating an image.</p>

<p>There is (of course) a problem that makes this unusable for me. The line refuses to appear in certain versions of Chrome unless the thickness of the line is 4 pixels or wider. I needed the line to be thinner. Oh well. Back to the drawing board.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Mindfulness]]></title>
    <link href="http://jonahlyn.heroku.com/blog/2011/12/14/mindfullness/"/>
    <updated>2011-12-14T20:19:00-07:00</updated>
    <id>http://jonahlyn.heroku.com/blog/2011/12/14/mindfullness</id>
    <content type="html"><![CDATA[<p>After reading a couple of books on Buddhism I&#8217;ve become interested in the practice of mindfulness. Being attentively aware of something, like breathing, that we do every day without thinking about it and therefore take for granted, seems like such a simple concept but I&#8217;m closer to admitting that it will probably be the hardest thing that I attempt to learn.</p>

<p>That&#8217;s why I was really excited to find <a href="http://vimeo.com/pvom">Plum Village Online Monastery videos on Vimeo</a>. Last night I watched the video &#8220;Basic Mindfulness practice&#8221; right before bed and I think I was able to sleep more deeply than normal.</p>

<iframe src="http://player.vimeo.com/video/31569404" width="400" height="300" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>


<p><a href="http://vimeo.com/31569404">Basic Mindfulness practice</a> from <a href="http://vimeo.com/pvom">Plum Village Online Monastery</a> on <a href="http://vimeo.com">Vimeo</a>.</p>


<p>I highly recommend watching it. The instructor, Phap Luu, seems like a very friendly and likeable person. I especially liked the idea of using the sounds that cell phones and other electronic devices make as a reminder to stop and breathe and be mindful.</p>

<p>If you know of any other similar videos or resources on mindfulness practice for beginners please leave a comment.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[jQuery UI Drag and Drop in a Backbone JS Application]]></title>
    <link href="http://jonahlyn.heroku.com/blog/2011/12/02/backbone-drag-and-drop/"/>
    <updated>2011-12-02T12:55:00-07:00</updated>
    <id>http://jonahlyn.heroku.com/blog/2011/12/02/backbone-drag-and-drop</id>
    <content type="html"><![CDATA[<div class="demo">
<a class="button" target="_blank" href="http://jsfiddle.net/jonahlyn/xYP4F/"><span class="a">Demo</span> <span class="b">Code</span></a>
</div>


<p>Recently I&#8217;ve fallen in love with <a target="_blank" href="http://documentcloud.github.com/backbone/">Backbone.js</a>. If you haven&#8217;t had a chance to check it out yet, I highly recommend it. It&#8217;s a framework for structuring javascript applications into models, views and collections. Yes collections. Just check it out.</p>

<p>Apparently, the way to learn any new javascript MVC framework is to study the todo list application built with it. (<a target="_blank" href="https://github.com/addyosmani/todomvc">Check out this github repository</a> to find the todo list app for your prefered framework.) The backbone todo list application is well documented in this <a target="_blank" href="http://documentcloud.github.com/backbone/docs/todos.html">split screen annotated source file</a> that really helped me a lot. There is also a <a target="_blank" href="http://documentcloud.github.com/backbone/examples/todos/index.html">working example</a> that I referenced quite a bit.</p>

<p>One thing that was obviously missing to me was the ability to drag and drop the todo items into a specific order. I did eventually find <a target="_blank" href="http://localtodos.com/">another version of the app</a> that did have drag and drop but it looked to be implemented with mootools. Now I haven&#8217;t quite gotten around to learning mootools yet. Bad I know. I&#8217;m highly dependent on jQuery at this time so I wanted to figure out how to do it with jQuery and more specifically jQuery UI.</p>

<p>Googling didn&#8217;t lead me to any ready-made solutions so I decided to try to figure it out on my own. So here&#8217;s the solution I came up with.</p>

<!--more-->


<p>First things first, jQuery and jQuery UI need to be included for this to work:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;</span><span class="nt">&gt;&lt;/script&gt;</span>
</span><span class='line'><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">&quot;https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js&quot;</span><span class="nt">&gt;&lt;/script&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>Then I added a custom html5 data attribute to the todo div element in the javascript template and set the value to the model id. I did this so I would be able to associate the div back to its model later.</p>

<figure class='code'><figcaption><span>Add an data-id attribute to the todo div element</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="o">&lt;%=</span> <span class="nx">id</span> <span class="o">?</span> <span class="s1">&#39;data-id=&quot;&#39;</span><span class="o">+</span><span class="nx">id</span><span class="o">+</span><span class="s1">&#39;&quot;&#39;</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span> <span class="o">%&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>Here&#8217;s what the entire template would look like:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="o">&lt;</span><span class="nx">script</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;text/template&quot;</span> <span class="nx">id</span><span class="o">=</span><span class="s2">&quot;item-template&quot;</span><span class="o">&gt;</span>
</span><span class='line'>  <span class="o">&lt;</span><span class="nx">div</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;todo &lt;%= done ? &#39;done&#39; : &#39;&#39; %&gt; &quot;</span> <span class="o">&lt;%=</span> <span class="nx">id</span> <span class="o">?</span> <span class="s1">&#39;data-id=&quot;&#39;</span><span class="o">+</span><span class="nx">id</span><span class="o">+</span><span class="s1">&#39;&quot;&#39;</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span> <span class="o">%&gt;&gt;</span>
</span><span class='line'>    <span class="o">&lt;</span><span class="nx">div</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;display&quot;</span><span class="o">&gt;</span>
</span><span class='line'>      <span class="o">&lt;</span><span class="nx">input</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;check&quot;</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;checkbox&quot;</span> <span class="o">&lt;%=</span> <span class="nx">done</span> <span class="o">?</span> <span class="s1">&#39;checked=&quot;checked&quot;&#39;</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span> <span class="o">%&gt;</span> <span class="err">/&gt;</span>
</span><span class='line'>      <span class="o">&lt;</span><span class="nx">div</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;todo-text&quot;</span><span class="o">&gt;&lt;</span><span class="err">/div&gt;</span>
</span><span class='line'>      <span class="o">&lt;</span><span class="nx">span</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;todo-destroy&quot;</span><span class="o">&gt;&lt;</span><span class="err">/span&gt;</span>
</span><span class='line'>    <span class="o">&lt;</span><span class="err">/div&gt;</span>
</span><span class='line'>    <span class="o">&lt;</span><span class="nx">div</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;edit&quot;</span><span class="o">&gt;</span>
</span><span class='line'>      <span class="o">&lt;</span><span class="nx">input</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;todo-input&quot;</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;text&quot;</span> <span class="nx">value</span><span class="o">=</span><span class="s2">&quot;&quot;</span> <span class="o">/&gt;</span>
</span><span class='line'>    <span class="o">&lt;</span><span class="err">/div&gt;</span>
</span><span class='line'>  <span class="o">&lt;</span><span class="err">/div&gt;</span>
</span><span class='line'><span class="o">&lt;</span><span class="err">/script&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>The todo list itself is simply a unordered list element with an id of &#8220;todo-list&#8221;. Inside the top level view &#8216;Appview&#8217; inside the initialize function, I called the jquery UI sortable function on that unordered list. The update function passed to sortable will run after the drag and drop ordering has occurred. In this function, I loop through all of the divs in the list, get a reference to the todo model using the value of the data-id attribute and update the order property. Backbone seemed to take care of the rest.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="k">this</span><span class="p">.</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#todo-list&quot;</span><span class="p">).</span><span class="nx">sortable</span><span class="p">({</span>
</span><span class='line'>    <span class="nx">update</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">,</span> <span class="nx">ui</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>        <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;div.todo&#39;</span><span class="p">,</span><span class="k">this</span><span class="p">).</span><span class="nx">each</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">i</span><span class="p">){</span>
</span><span class='line'>            <span class="kd">var</span> <span class="nx">id</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;data-id&#39;</span><span class="p">),</span>
</span><span class='line'>                <span class="nx">todo</span> <span class="o">=</span> <span class="nx">Todos</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">id</span><span class="p">);</span>
</span><span class='line'>            <span class="nx">todo</span><span class="p">.</span><span class="nx">save</span><span class="p">({</span><span class="nx">order</span><span class="o">:</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">});</span>
</span><span class='line'>        <span class="p">});</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p><a target="_blank" href="http://jsfiddle.net/jonahlyn/xYP4F/">Check out this jsfiddle</a> if you want to play around with it.</p>

<p>This seems to work just fine but at this point I haven&#8217;t used it in any production applications so use at your own risk. That and I am still a backbone newbie so if you have any better ideas, please let me know.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Creating Elements for Zend Form]]></title>
    <link href="http://jonahlyn.heroku.com/blog/2011/05/05/creating-elements-for-zend-form/"/>
    <updated>2011-05-05T20:52:00-06:00</updated>
    <id>http://jonahlyn.heroku.com/blog/2011/05/05/creating-elements-for-zend-form</id>
    <content type="html"><![CDATA[<div class="demo">
<a target="_blank" class="button" href="https://gist.github.com/918655">Basic Elements</a>

<a target="_blank" class="button" href="https://gist.github.com/920446">Advanced Elements</a>

<a target="_blank" class="button" href="https://gist.github.com/937720">MultiCheckbox Element</a>

</div>


<p>I&#8217;m nearly finished with the form I set out to create using Zend_Form and I&#8217;ve only written one blog post about what I&#8217;ve learned so far. I want to try to get as much knowlege in writing as I can before it&#8217;s gone. I&#8217;m starting to find that I am only an &#8220;expert&#8221; at what I&#8217;m presently doing at the time. Everything else I have to re-learn at some point and that&#8217;s what I&#8217;m hoping blog posts like this will help me do when the time comes. That and it might actually help someone else. Who knows.</p>

<p>When I first got started learning Zend_Form, I really wanted to stop and try to understand more about the different ways to create elements. The more I looked at different resources online and in books, I was seeing different ways of creating and configuring elements. At first this was confusing but I came to see how this made form creation incredibly flexible.</p>

<!--more-->


<h2>Creating an Element</h2>

<p>You can create elements by either instanciating objects or by using the factory method &#8216;createElement&#8217;. When instanciating objects, it&#8217;s necessary to know the class name of the type of element you are trying to create. Alternatively, the factory method accepts a string as the first argument that determines what type of element it will create.</p>

<p>The following snippet shows both ways of creating the same text field with an id of &#8216;fullname&#8217;.</p>

<div><script src='https://gist.github.com/932806.js?file=element_creation.php'></script>
<noscript><pre><code>// Instantiate an Element Object
$fullname = new Zend_Form_Element_Text('fullname');


// Element Creation by Factory
$fullname = $this-&gt;createElement('text', 'fullname');</code></pre></noscript></div>


<p>The table below lists the class names of some of the more basic types of form controls with the matching string that can be passed to createElement to create the same type of element. These and more are described in some detail in the <a href="http://framework.zend.com/manual/en/zend.form.standardElements.html">Zend Programmer&#8217;s Reference</a>.</p>

<table>
<tbody><tr>
<th>Class Name</th><th>Element String</th>
</tr>
<tr>
<td>Zend_Form_Element_Text</td>
<td>text</td>
</tr>
<tr>
<td>Zend_Form_Element_Textarea</td>
<td>textarea</td>
</tr>
<tr>
<td>Zend_Form_Element_Select</td>
<td>select</td>
</tr>
<tr>
<td>Zend_Form_Element_Radio</td>
<td>radio</td>
</tr>
<tr>
<td>Zend_Form_Element_Checkbox</td>
<td>checkbox</td>
</tr>
<tr>
<td>Zend_Form_Element_Hidden</td>
<td>hidden</td>
</tr>
<tr>
<td>Zend_Form_Element_Reset</td>
<td>reset</td>
</tr>
<tr>
<td>Zend_Form_Element_Submit</td>
<td>submit</td>
</tr>
</tbody></table>


<h2>Configuring the Element</h2>

<p>You can configure an element by setting various properties for it including the label, description, whether or not it is a required field, filters and validators for the input, and decorators that determine how the element will look. I&#8217;m not going to describe these in detail because that would make this post too long. What I want to show is that these options can be set either by passing an array of options, by calling methods on the element object, or any combination of the two.</p>

<p>The code snippets below create and configure the exact same element. I think I prefer passing an array of options (the 1st snippet) over calling the individual methods. It just seems cleaner to me.</p>

<div><script src='https://gist.github.com/932806.js?file=factory_full_example.php'></script>
<noscript><pre><code>// Configure an element by passing an array of options.
$fullname = $this-&gt;createElement('text', 'fullname', array(
    'label' =&gt; 'Full Name',
    'required' =&gt; true,
    'filters' =&gt; array('StringTrim','StripTags'),
    'validators' =&gt; array(
        array('NotEmpty', true, array(
            'messages' =&gt; array(
                'isEmpty' =&gt; 'Please enter your name.'
            )
        )),
        array('StringLength', false, array(
            'min' =&gt; 4,
            'max' =&gt; 255,
            'messages' =&gt; array(
                'stringLengthTooShort' =&gt; 'Full Name must be between 4 and 255 characters in length.',
                'stringLengthTooLong' =&gt; 'Full Name must be between 4 and 255 characters in length.'
            )
        ))
    )
));</code></pre></noscript></div>




<div><script src='https://gist.github.com/932806.js?file=object_full_example.php'></script>
<noscript><pre><code>// Create Text Field
$fullname = new Zend_Form_Element_Text('fullname');

// Set metadata
$fullname-&gt;setLabel('Full Name');
$fullname-&gt;setRequired(true);

// Add filters
$fullname-&gt;addFilter('StringTrim');
$fullname-&gt;addFilter('StripTags');

// Add validators
// Arguments: Validator Name, breakChainOnFailure, options
$fullname-&gt;addValidator('NotEmpty', true);         
$fullname-&gt;addValidator('StringLength', true, array(4,10));

// Set validation errors
$fullname-&gt;getValidator('NotEmpty')-&gt;setMessage(&quot;Please enter your name.&quot;);
$fullname-&gt;getValidator('StringLength')-&gt;setMessage('Your name must be between 4 and 10 characters in length.');
</code></pre></noscript></div>




<div><script src='https://gist.github.com/932806.js?file=combination_example.php'></script>
<noscript><pre><code>// Only some options are passed in the array.
$fullname = $this-&gt;createElement('text', 'fullname', array(
    'label' =&gt; 'Full Name',
    'required' =&gt; true
));

// Add multiple filters at once by calling the addFilters method.
$fullname-&gt;addFilters(array('StringTrim','StripTags'));

// Add multiple validators at once by calling the addValidators method.
$fullname-&gt;addValidators(array(
    array('NotEmpty', true),
    array('StringLength', true, array(4,10))
)); 

// Set validation errors by chaining method calls together.
$fullname-&gt;getValidator('NotEmpty')-&gt;setMessage(&quot;Please enter your name.&quot;);
$fullname-&gt;getValidator('StringLength')-&gt;setMessage('Your name must be between 4 and 10 characters in length.');
</code></pre></noscript></div>


<p>Thanks for reading!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using Zend Form Without the Framework]]></title>
    <link href="http://jonahlyn.heroku.com/blog/2011/04/06/using-zend-form-without-the-framework/"/>
    <updated>2011-04-06T19:31:00-06:00</updated>
    <id>http://jonahlyn.heroku.com/blog/2011/04/06/using-zend-form-without-the-framework</id>
    <content type="html"><![CDATA[<p>I&#8217;ve been having a love/hate relationship with the Zend Framework as I attempt to learn how to use it. No doubt it is incredibly powerful but it may be overly complicated for my tastes. Maybe I was having a bad day or following bad instructions, but setting up an initial site using Zend for the first time took me HOURS! This is not the first PHP framework I&#8217;ve ever used either. I used to manage my personal site in Codeigniter and many years ago tried and loved Cake PHP. Anyway I&#8217;m not sure what the problem was, but by the time I got to the blue welcome screen I was exhausted and went no further.</p>

<p>More recently however, I had a need to develop an application on a server I knew had Zend installed on it. The thought of repeating the frustrations from several months earlier did not sound appealing so I have set out to experiment with using the Zend Framework without the Framework, or, in other words, the Zend classes without the MVC. Most of what I have learned so far has come from other posts on the Internet, so I now know I&#8217;m not the only one who&#8217;s ever attempted to do this.</p>

<p>Actually this turned out to be pretty easy. The rest of this post covers the creation of a very basic, standalone zend form.</p>

<!--more-->


<h2>The &#8220;Controller&#8221;</h2>

<p>Even though MVC is not being used, a controller of sorts is still needed to get things started. Loading Zend classes can be done by requiring the Zend Loader and then calling the loadClass static method with the name of the class needed. In this basic controller, I load my custom form class RequestForm and also Zend_View which is necessary in order to create a view object to render the form.</p>

<p>Forms in Zend are objects so it is necessary to instanciate an instance of a form in order to display and use it. The form is displayed on a webpage by calling the form&#8217;s render method and passing it the view object. The rest of the controller code checks whether or not the form has been posted, and if it has attempts to validate it using a very cool isValid method on the form object. Once the form is posted with valid input, that information can be accessed by calling the getValues method. This makes for a nice, lean controller.</p>

<div><script src='https://gist.github.com/904998.js?file=index.php'></script>
<noscript><pre><code>&lt;?php

    // Load needed Zend classes
    require_once(&quot;Zend/Loader.php&quot;);
    Zend_Loader::loadClass('Zend_View');
    Zend_Loader::loadClass('RequestForm');

    // Create a view to render the form
    $view = new Zend_View();

    // Create an instance of the form
    $form = new RequestForm();

    if (!$_POST) {
        // Render the blank form
        echo $form-&gt;render($view);
    } else if(!$form-&gt;isValid($_POST)) {
        // Renders form with error messages
        echo $form-&gt;render($view);
    } else {
        // Passed validation. Do someting with the values entered.
        $values = $form-&gt;getValues();
        extract($values);
        include &quot;thank-you.php&quot;;
    }</code></pre></noscript></div>


<h2>The Form</h2>

<p>I mentioned that forms in Zend are objects. I now love the idea of using form objects for creating forms, but this took some time to get used to. The bulk of the work here takes place in the init method. To begin, use a series of setter methods to set the various form attributes such as name, action URL and method. It&#8217;s also possible to use the setAttrib method to set custom attributes, such as &#8220;id&#8221;. There is also a setDescription method although I haven&#8217;t quite figured out what this is good for.</p>

<p>Creating form fields is possible by calling the createElement method with 2 arguments: 1st the type of field (ie. text, submit, etc) you need to create and 2nd the name of the field. Calling setOptions on the element it&#8217;s possible to do things such as assign a label, make the field required and filter and validate the incoming data. The ability to use Zend&#8217;s built-in form handling to filter and validate input is exactly why I wanted to use it for this project in the first place and this seems to be one of its strengths.</p>

<p>Last but not least, calling the addElement method actually adds the created fields to the form.</p>

<div><script src='https://gist.github.com/904998.js?file=requestform.php'></script>
<noscript><pre><code>&lt;?php

Zend_Loader::loadClass('Zend_Form');

class RequestForm extends Zend_Form{

    public function init(){

        // Set properties of the form
        $this-&gt;setName('myform')
            -&gt;setAction('index.php')
            -&gt;setMethod('post')
            -&gt;setAttrib('id','myform')
            -&gt;setDescription('Please fill out the following form.');

        // Name Field
        $yourname = $this-&gt;createElement('text','yourname')
            -&gt;setOptions(
                array(
                    'label'=&gt;'What is your name?',
                    'required'=&gt; true,
                    'filters' =&gt; array('StringTrim','StripTags'),
                )
            );

        // Submit Button
        $submit = $this-&gt;createElement('submit','submit');

        // Add controls to the form
        $this-&gt;addElement($yourname)
             -&gt;addElement($submit);

    }

}</code></pre></noscript></div>


<h2>The Output</h2>

<p>The above gets the job done, but what I&#8217;m not too happy with is the output. The result is a form structured with a definition list. Lately wrapping fields in &lt;p&gt; tags has been my preference but I know others like to use lists. An unordered list of errors is displayed if the field did not pass validation and the default messages are not the most user-friendly.</p>

<p><img class="none" src="http://jonahlyn.heroku.com/images/posts/zend-form.png.scaled500.png" width="245" height="147" title="'Very simple zend generated form with a single text box.'" >
<img class="none" src="http://jonahlyn.heroku.com/images/posts/zend-form-errors.png.scaled500.png" width="329" height="173" title="'Zend generated form with validation errors displayed as a list underneath the text box.'" ></p>

<div><script src='https://gist.github.com/904998.js?file=result.html'></script>
<noscript><pre><code>&lt;form id=&quot;myform&quot; enctype=&quot;application/x-www-form-urlencoded&quot; action=&quot;index.php&quot; method=&quot;post&quot;&gt;

&lt;dl class=&quot;zend_form&quot;&gt;
    &lt;dt id=&quot;yourname-label&quot;&gt;
        &lt;label for=&quot;yourname&quot; class=&quot;required&quot;&gt;What is your name?&lt;/label&gt;
    &lt;/dt&gt;
    &lt;dd id=&quot;yourname-element&quot;&gt;
        &lt;input type=&quot;text&quot; name=&quot;yourname&quot; id=&quot;yourname&quot; value=&quot;&quot;&gt;
    &lt;/dd&gt;
    &lt;dt id=&quot;submit-label&quot;&gt;&amp;nbsp;&lt;/dt&gt;
    &lt;dd id=&quot;submit-element&quot;&gt;
        &lt;input type=&quot;submit&quot; name=&quot;submit&quot; id=&quot;submit&quot; value=&quot;submit&quot;&gt;
    &lt;/dd&gt;
&lt;/dl&gt;

&lt;/form&gt;</code></pre></noscript></div>


<p>I hope to spend more time learning about the various ways of creating different types of elements, filtering and validating input and customizing the appearance of the generated form.</p>

<p>Thanks for reading.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using jQuery to Extract the Contents of a Web Page]]></title>
    <link href="http://jonahlyn.heroku.com/blog/2011/02/09/using-jquery-to-extract-the-contents-of-a-web-page/"/>
    <updated>2011-02-09T09:39:00-07:00</updated>
    <id>http://jonahlyn.heroku.com/blog/2011/02/09/using-jquery-to-extract-the-contents-of-a-web-page</id>
    <content type="html"><![CDATA[<p>I wanted to get the text contents of this web page into excel. Sure it&#8217;s backed by a database (if you can call Access a database :-p) but I thought it would be fun to play with jQuery instead. This is probably something that could also be done with python or perl, but like I said I wanted to play with jQuery.</p>

<p>The page itself does not use jQuery but it&#8217;s possible to add jQuery to any page with the awesome <a target="_blank" href="http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet">jQuerify bookmarklet</a> so that&#8217;s what I did. Then I fired up the console in Chrome and started hacking.</p>

<!--more-->


<p>First, I added the link URL as text after each link.</p>

<div><script src='https://gist.github.com/819489.js?file=console1.js'></script>
<noscript><pre><code>$('a').each(function(index){$(this).append('|' + $(this).attr('href'));});</code></pre></noscript></div>


<p>Next, I executed a series of commands to get rid of things like headings, paragraphs, breaks, images, spaces etc.</p>

<div><script src='https://gist.github.com/819489.js?file=console2.js'></script>
<noscript><pre><code>// First get a handle on the main element (a blockquote no less!)
var blockqt = $('blockquote');

// Remove headings, paragraphs, links, images and break tags
blockqt.children('h3').remove();
blockqt.children('p').remove();
blockqt.children('br').remove();
$('a &gt; img',blockqt).parent('a').remove();
$('a',blockqt).contents().unwrap();

// Remove non-breaking spaces
blockqt.html().replace(/&amp;nbsp;/gi,'');

// Remove superfluous line breaks
blockqt.html().replace(/\n{2,}/g,'\n')

// Show actual ampersands
blockqt.html().replace(/&amp;amp;/g,'&amp;');

// The result is nice, clean text printed to the console</code></pre></noscript></div>


<p>Finally, I re-attempted the whole thing as a single command using jquery&#8217;s end() method and its ability to chain method calls together.</p>

<div><script src='https://gist.github.com/819489.js?file=console3.js'></script>
<noscript><pre><code>// All of the above done in 1 step
$('blockquote').children('h3').remove().end().children('p').remove().end().children('br').remove().end().add('a &gt; img').parent('a').remove().end().children('a').contents().unwrap().end().end().end().html().replace(/&amp;nbsp;/g,'').replace(/\n{2,}/g,'\n').replace(/&amp;amp;/g,'&amp;');</code></pre></noscript></div>


<p>The less than optimal markup made this a really good test of my knowledge and I learned a lot. Thanks for reading!</p>
]]></content>
  </entry>
  
</feed>

