title: Zend Framework Custom form element gets repeated
body: <p>I've got a strange problem.</p>
  
  <p>I created a custom form element. I created it with two select-form-elements to select a time (00:00). </p>
  
  <p>The strange things is that when i use it once in a form its ok, but when i use it a second time (because an appointment has a beginning and an end time) the first one is shown again. So i end up with three times the form-element. When i use it again it shows the first two also and i end up with 6 times the form element.</p>
  
  <p>Does anybody know how to prevent his from happening?</p>
  
  <p>The Code:</p>
  
  <p>Form Element</p>
  
  <pre><code>&lt;?php
  
  class App_Form_Element_TimeSelect extends Zend_Form_Element_Xhtml
  {
  
      public $helper = 'FormTimeSelect';
      protected $hour = null;
      protected $minutes = null;
  
      public function setHour($hour)
      {
          $this-&gt;hour = $hour;
          return $this;
      }
  
      public function setMinutes($minutes)
      {
          $this-&gt;minutes = $minutes;
          return $this;
      }
  
      public function setValue($value)
      {
          if (is_array($value)
                  &amp;&amp; isset($value['hour'])
                  &amp;&amp; isset($value['minutes']))
          {
              $this-&gt;setHour($value['hour'])
                      -&gt;setMinutes($value['minutes']);
          }
      }
  
      public function getValue()
      {
          if (!$this-&gt;hour || !$this-&gt;minutes)
              return false;
          return $this-&gt;hour . ':' . $this-&gt;minutes;
      }
  
  }
  </code></pre>
  
  <p>The view Helper</p>
  
  <pre><code>&lt;?php
  
  class App_View_Helper_FormTimeSelect extends Zend_View_Helper_FormElement {
  
      protected $html = '';
  
      public function FormTimeSelect($name, $value = null, $attribs = null)
      {
          $hour = '00';
          $minute = '00';
          if ($value)
              list($hour, $minute) = split(':', $value);
  
          $helper = new Zend_View_Helper_FormSelect();
          $helper-&gt;setView($this-&gt;view);
  
          $hourarray = array('00' =&gt; '00', '01' =&gt; '01', '02' =&gt; '02', '03' =&gt; '03',
              '04' =&gt; '04', '05' =&gt; '05', '06' =&gt; '06', '07' =&gt; '07', '08' =&gt; '08',
              '09' =&gt; '09', '10' =&gt; '10', '11' =&gt; '11', '12' =&gt; '12', '13' =&gt; '13',
              '14' =&gt; '14', '15' =&gt; '15', '16' =&gt; '16', '17' =&gt; '17', '18' =&gt; '18',
              '19' =&gt; '19', '20' =&gt; '20', '21' =&gt; '21', '22' =&gt; '22', '23' =&gt; '23');
          $minutearray = array('00' =&gt; '00', '15' =&gt; '15', '30' =&gt; '30', '45' =&gt; '45');
  
          $this-&gt;html .= $helper-&gt;formSelect($name . '[hour]', $hour, null, $hourarray);
          $this-&gt;html .= ' : ';
          $this-&gt;html .= $helper-&gt;formSelect($name . '[minutes]', $minute, null, $minutearray);
  
          return $this-&gt;html;
      }
  
  }
  </code></pre>
  
  <p>Thanks! </p>
  
  <p>Peter</p>