I have form with fieldsets:
$formConfig = array(
'fieldsets' => array(
...
);
);
$factory = new Zend\Form\Factory();
$form = $factory->createForm($formConfig);
echo $this->form($form);
It renders something like this:
<form>
<fieldset>
<legend>Fieldset label</legend>
<label><span>Elem 1</span><input type="text" name="f1[el1]" /></label>
<label><span>Elem 2</span><input type="text" name="f1[el2]" /></label>
<label><span>Elem 3</span><input type="text" name="f1[el3]" /></label>
</fielset>
</form>
The problem is that I need to wrap content after legend:
<form>
<fieldset>
<legend>Fieldset label</legend>
<div class="wrapper">
<label><span>Elem 1</span><input type="text" name="f1[el1]" /></label>
<label><span>Elem 2</span><input type="text" name="f1[el2]" /></label>
<label><span>Elem 3</span><input type="text" name="f1[el3]" /></label>
<div>
</fielset>
</form>
How can I do that?
Once more you need to understand that a
Zend\Form\Fieldset
does not equal a HTML<fieldset>
! AZend\Form\Fieldset
merely is a collection ofZend\Form\Element
that usually represent one entity and you could provide several entities with data from one Form.Now when it comes to rendering the form, the first thing you should learn about are the several
Zend\Form\View\Helper
-Classes. You are using theform()
view-helper, which automatically translates allZend\Form\Element
usingformRow()
and allZend\Form\Fieldset
usingformCollection()
. But you don't want to do that!When wanting your preferred output, you will be needed to render the form yourself. Something like this could be your view-template:
Now, this already has a little comfort within it, as you'd be using
formRow()
. You could also split up each form-row and go the very detailled way like:Even there,
formInput()
still is a magic that derives into things likeformText()
,formSelect()
,formTextarea()
, etc.., etc...