Adding HTML markup to elements in a ZendFramework 2 fieldset

I'm sure I'm missing something obvious, but I've been banging my head for a while now.

What I want to do is pretty simple. Say, I want a shopping cart that can hold many items, represented in a ZF2 Form. I create a Form for the shopping cart, and then a fieldset class for the items, then put that item fieldset in a Form Element Collection.

This all works fine, BUT I want to wrap the individual elements of the item fieldset with HTML markup. Put divs around them, put them in a table, whatever.

For the life of me I can't figure out how to do that. In my viewscript, I could iterate through the collection to get the item fieldsets one at a time, then iterate through the fieldsets to explicitly echo the individual item fieldset elements, wrapped by whatever HTML markup I want.

BUT that doesn't deal with the template, and I'm using the template to create additional items, and the template doesn't have the HTML markup that comes from the view template.

I would have thought there would be some way to tell the item fieldset itself how to render itself -- sort of like using a "partial" view template that works in the same way as the page view template, echoing each item fieldset element explicitly and putting whatever else markup -- but this partial view should be attached to the item fieldset itself and rendered for each fieldset in the collection (and the template).

Is there an obvious way to do this I'm just missing?

Thanks.

Answers


Your forms and fieldsets are used by the form view helpers to render the correct HTML markup.

You would need to create a custom (just extend) Zend\Form\View\Helper\FormCollection and depending on what your needs may be, also a custom Zend\Form\View\Helper\FormRow that you then attach to it.

If you look at the code for the form collection you will see that they generate the HTML using the same method you describe doing yourself, however its already done for you; you just need to modify the bits you need, such as the render() method or properties like $wrapper or $templateWrapper etc.


Need Your Help

Mapping sums of defaultdict(list) to one list

python list python-3.x mapping defaultdict

I have a large collection of data formatted somewhat like the d.items() of a defaultdict(list). See below:

Get a single phone number from contacts Android

android android-contacts phone-number

Hi I am trying to get a single phone number from the contact list . I have found code which gets me the whole contact list telephone numbers, all I want is the telephone number for the item clicked...