Archive for January 8th, 2011

Zend_Form_Element_Hidden not really hidden

The point of having a hidden field is that it is truly hidden, and doesn’t require labels / etc. Unfortunately, Zend_Form_Element_Hidden doesn’t really recognise this. Here’s how to subclass it and get rid of that stuff so you can create an input that is hidden for real:

class M_Form_Element_Hidden extends Zend_Form_Element_Hidden {
   public function init() {
      $this->setDisableLoadDefaultDecorators(true);
      $this->addDecorator('ViewHelper');
      $this->removeDecorator('DtDdWrapper');
      $this->removeDecorator('HtmlTag');
      $this->removeDecorator('Label');
      return parent::init();
   }
}