title: Passing variables to a Custom Zend Form Element
body: <p>I'm trying to create a custom form element which extends Zend_Form_Element_Text with a validator (so I don't have to keep setting up the validator when I use certain elements). Anyway, I'm having trouble passing $maxChars variable to it when I instantiate it in my Main form. I've provided my shortened code below</p>
  
  <p><strong>This is my custom element below</strong></p>
  
  <pre><code>class My_Form_Custom_Element extends Zend_Form_Element_Text
  {
  
  public $maxChars
  
  public function init()
  {
      $this-&gt;addValidator('StringLength', true, array(0, $this-&gt;maxChars))
  }
  
  public function setProperties($maxChars)
  {
      $this-&gt;maxChars= $maxChars;
  }
  }
  </code></pre>
  
  <p><strong>This is where I instantiate my custom form element.</strong></p>
  
  <pre><code>class My_Form_Abc extends Zend_Form
  {
  public function __construct($options = null)
  {
      parent::__construct($options);
      $this-&gt;setName('abc');
  
      $customElement = new My_Form_Custom_Element('myCustomElement');
      $customElement-&gt;setProperties(100); //**&lt;----This is where i set the $maxChars**
  
      $submit = new Zend_Form_Element_Submit('submit');
      $submit -&gt;  setAttrib('id', 'submitbutton');
  
      $this-&gt;addElements(array($customElement ,$submit));
  }
  }
  </code></pre>
  
  <p>When I try to pass '100' using $customElement->setProperties(100) in my Form, it doesnt get passed properly to my StringLength validator. I assume it's because the validator is getting called in Init? How can I fix this?</p>