Aise
Aise

Reputation: 173

Customize fieldset output from form collection in ZF2

I have correctly set up a form in ZF2, which includes several elements and a collection containing a fieldset that can be duplicated by the user. All works fine, but I need more control on how the fieldset renders, ie. I need to add other things between some elements in the fieldset, rather than just output them one after another.

I'm not expert in ZF2, but from research I seem to understand that you can declare a custom fieldsetHelper in the formCollection, however:

  1. I can't manage to do so; I tried to extend the FormCollection class, and adding protected $fieldsetHelper = 'myFieldsetHelper';, which is also declared in the module config, but I get:

Fatal error: Call to undefined function myFieldsetHelper()

  1. I'm familiar with extending FormRow helper, but I don't know how the fieldset helper should be written (I only need to add my extra stuff between some elements), and can't find any example on the web.

Any help, please?

Upvotes: 1

Views: 441

Answers (1)

Garry
Garry

Reputation: 1485

You can use other view helpers to customize the forms layout in your view script such as FormLabel, FormText, etc.

Please see my answer here

EDIT

You can also loop through all the collection elements in your view script and render separately.

<?php
foreach ($this->form->get('collection') as $fieldset) {
    echo $this->formText($fieldset->get('elementName'));
}
?>

Upvotes: 1

Related Questions