I have a zend form in which I need each element to be wrapped by a display group. Then I need a group of elements to be wrapped in another display group. Since zend form does not support nested display groups I use subform instead.
So, my structure now is:
Form
--- SubForm (1)
--- --- DisplayGroup (1-1)
--- --- --- Element (1)
--- --- DisplayGroup (1-2)
--- --- --- Element (2)
--- SubForm (2)
--- --- DisplayGroup (2-1)
--- --- --- Element (3)
--- --- DisplayGroup (2-2)
--- --- --- Element (4)
etc.
From this, however, comes the problem that each subform is set as a parent to each element that belongs to it. This changes the name of the element, f.e. name="username" becomes name="subformname[username]".
Since I am using the subform as a substitute of the display group, I don’t need it’s extra functionality.
How can I disable this changing of the names?
P.S.: I am using a custom function to “bulk process” each element (trivial stuff – remove decorators, set labels etc.), so I was able to force setAttrib('name', $element -> getName()), but it turns out that this only works for regular form elements. It does not work on ZendX form elements like datepickers, colorpickers etc.
From the comments you said you’re only using display groups to give the element a twitter bootstrap grid class. You don’t need to use display groups for this, just add an additional HtmlTag decorator to each form element, or add a class to one of the existing ones. Then you can use display groups for their intended purpose, giving you:
if you have any trouble, edit your question to include the your ‘bulk process’ code that is modifying the existing decorators we can suggest how it could be modified.
Edit: Getting a decorator to wrap the label and the form element is just down to the order in which your decorators are specified. Here’s an example:
The viewHelper decorator renders the form element itself. Each subsequent decorator is wrapped ‘around’ the existing content. Exactly how that is rendered depends a bit on the decorator itself, but in the example above you’ll see a div tag with the class ‘span4’ as the last decorator, which means the div will wrap everything else.