title: Using ViewScript Decorator on Nested Subforms (Zend Form)
body: <p>I want to use a view script to render my zend form as it seems to be the best way to 
  control the layout/design of the form while still using the Zend_Elements classes.</p>
  
  <p>From the view script, I render the element with <code>$this-&gt;element-&gt;getElement('elementName')</code> .</p>
  
  <p>I'm having problems with the names of the elements. This is actually a sub-form inside a sub-form inside a form.</p>
  
  <p>When I used the FormElements decorators , the fully qualified name of the elements was form[subForm][subForm][element] , which was good.
  Wehn I moved to the viewScript decorators, it changed to subForm[subForm][element].</p>
  
  <p>I understood that I need to use the PrepareElements decorator to fix this, but this caused the name to change form[subForm][form][subForm][subForm][elements] (it doubled the first two names in the start).</p>
  
  <p>Any ideas how I should handle this?</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE:</strong> I tried to debug PrepareElements and I really don't understand what is doing.
  It seems like it works ok in the first iteration, but then it adds again the form[subform] prefix when running on one of the middle subforms.</p>
  
  <p>When I'm not using the PrepareElements decorator, I'm just missing the "form" prefix in the names (i.e., instead of form[subForm][element], I get only subForm[element]).</p>
  
  <p>May be I can just fix this somehow? </p>
  
  <p>I tried to change the belongsTo but that only replaced the "subForm" prefix .</p>
  
  <p>It actually seems like what is missing is a belongsTo method on the subForm.</p>
  
  <p>Again, this is all because of the ViewScript decorator. It works fine with the FormElements decorators.</p>
  
  <p><strong>UPDATE 2:</strong> Just to clarify, I wouldn't mind this name change, but it causes my fields to not populate when I call form->populate .</p>
  
  <p><strong>Edit:</strong> I think that I've narrowed the problem to this: when I get my values back in setDefaults, they are ordered like this: </p>
  
  <pre><code>array(
  \"formElements1-name\" =&gt; value1... \"subFormName\" =&gt; array(
  \"parentFormName\" =&gt; array(
  \"subFormName\" =&gt; subForm-values-array
  )
  )
  </code></pre>
  
  <p>...
  The main problem here is the <code>"parentFormName" =&gt; "subFormNAme"..</code> what does it repeat itself? I'm already in the main form. I'm guessing this is caused because I've set the <code>setElementsBelongTo(formName[subFormName])</code> , but if I wouldn't do that, then I would get my subform values completely separate from the form, </p>
  
  <p>i.e. 
      values array = array(
      \"formName\" => array(
      formValues
      ), \"subFormNAme\" => array(
      subFormValues
      )</p>
  
  <p>, while I exepct it to be </p>
  
  <pre><code>array(
  formName =&gt; array(
  subFormNAme =&gt; values-array
  )
  )...
  </code></pre>
  
  <p>Is it even possible to make this work?</p>