<?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>Beth Granter &#187; custom decorators</title>
	<atom:link href="http://bethgranter.com/blog/tag/custom-decorators/feed/" rel="self" type="application/rss+xml" />
	<link>http://bethgranter.com/blog</link>
	<description>Social media, online communities, interface design, ethics and feminism</description>
	<lastBuildDate>Tue, 31 Jan 2012 17:31:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Zend Form &#8211; custom decorators</title>
		<link>http://bethgranter.com/blog/2008/04/zend-form-custom-decorators/</link>
		<comments>http://bethgranter.com/blog/2008/04/zend-form-custom-decorators/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 12:02:14 +0000</pubDate>
		<dc:creator>Beth Granter</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[custom decorators]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zend form]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[zend_form]]></category>

		<guid isPermaLink="false">http://bethgranter.wordpress.com/?p=102</guid>
		<description><![CDATA[So I&#8217;m learning PHP and Zend Framework and MVC stuff.  And I just figured out how to do a custom decorator on Zend_Form to change the way the form is written to HTML.  The default puts each element label and input box into dd and dl tags.  ...]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m learning PHP and Zend Framework and MVC stuff.  And I just figured out how to do a custom decorator on Zend_Form to change the way the form is written to HTML.  The default puts each element label and input box into dd and dl tags.  I just wanted to put each element in a div, with the input box on the same line as the label.  There may be better ways to do this, but this is what I put in the IndexController.php file:</p>
<pre><span style="color:#333399;">$form = new Zend_Form(array(
    'elementDecorators'=&gt;array(
       'ViewHelper',
       array(
          'Description',
          array(
             'tag'=&gt;'div',
             'class'=&gt;'help'
          )
       ),
       'Errors',
       array('Label'),
       array(
          'HtmlTag',
           array(
              'tag'=&gt;'div',
              'class'=&gt;'field'
           )
        )
    ),
    'decorators'=&gt;array(
        'FormElements',
        array(
          'HtmlTag',
          array('tag' =&gt; '&lt;div&gt;')
        ),
        'Form',
     ),
    'method' =&gt; 'post',
    'action' =&gt;'/url/to/form',
    'elements' =&gt; array(
        'name' =&gt; array('text', array(
            'label' =&gt; 'Name:'
        )),
        'subject' =&gt; array('text', array(
            'label' =&gt; 'Subject:'
         )),
        'submit' =&gt; array('submit', array(
            'label' =&gt; 'Add',
        ))
    ),
 ));
 $form-&gt;submit-&gt;removeDecorator('Label');
 return $form;
}</span>
<span style="color:#333399;"> public function formAction()
 {
      $this-&gt;view-&gt;form = $form;
 }</span></pre>
<p>The  $form-&gt;submit-&gt;removeDecorator(&#8216;Label&#8217;) bit removes the extra &#8216;Add&#8217; from the submit button.</p>
<p>Then you just put<br />
<span style="color:#333399;">echo $this-&gt;form;</span><br />
in your form.phtml</p>
<p>(This form does nothing)</p>
<p>This results in HTML like:</p>
<pre><span style="color:#333399;">&lt;<span class="start-tag">form</span><span class="attribute-value"> </span><span class="attribute-name">method</span>=<span class="attribute-value">"post" </span><span class="attribute-name">action</span>=<span class="attribute-value">"/route/to/form"</span>&gt;
   &lt;<span class="start-tag">div</span>&gt;
      &lt;<span class="start-tag">div</span><span class="attribute-name"> class</span>=<span class="attribute-value">"field"</span>&gt;
         &lt;<span class="start-tag">label</span><span class="attribute-name"> for</span>=<span class="attribute-value">"name" </span><span class="attribute-name">class</span>=<span class="attribute-value">"optional"</span>&gt;Name:&lt;/<span class="end-tag">label</span>&gt;
<span class="start-tag">         &lt;input</span><span class="attribute-name"> type</span>=<span class="attribute-value">"text" </span><span class="attribute-name">name</span>=<span class="attribute-value">"subject" </span><span class="attribute-name">id</span>=<span class="attribute-value">"subject" </span><span class="attribute-name">value</span>=<span class="attribute-value">""</span>&gt;
      &lt;/<span class="end-tag">div</span>&gt;
      &lt;<span class="start-tag">div</span><span class="attribute-name"> class</span>=<span class="attribute-value">"field"</span>&gt;
          &lt;<span class="start-tag">label</span><span class="attribute-name"> for</span>=<span class="attribute-value">"subject" </span><span class="attribute-name">class</span>=<span class="attribute-value">"optional"</span>&gt;Subject:&lt;/<span class="end-tag">label</span>&gt;
          &lt;<span class="start-tag">input</span><span class="attribute-name"> type</span>=<span class="attribute-value">"text" </span><span class="attribute-name">name</span>=<span class="attribute-value">"subject" </span><span class="attribute-name">id</span>=<span class="attribute-value">"subject" </span><span class="attribute-name">value</span>=<span class="attribute-value">""</span>&gt;
      &lt;/<span class="end-tag">div</span>&gt;
      &lt;<span class="start-tag">div</span><span class="attribute-name"> class</span>=<span class="attribute-value">"field"</span>&gt;
           &lt;<span class="start-tag">input</span><span class="attribute-name"> name</span>=<span class="attribute-value">"submit" </span><span class="attribute-name">id</span>=<span class="attribute-value">"submit" </span><span class="attribute-name">value</span>=<span class="attribute-value">"Add" </span><span class="attribute-name">type</span>=<span class="attribute-value">"submit"</span>&gt;
      &lt;/<span class="end-tag">div</span>&gt;
   &lt;/<span class="end-tag">div</span>&gt;
&lt;/<span class="end-tag">form</span>&gt;</span>

Instead of the default dd and dl layed out form.</pre>
]]></content:encoded>
			<wfw:commentRss>http://bethgranter.com/blog/2008/04/zend-form-custom-decorators/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

