Search code examples
phpformsannotationszend-framework2zend-view

Zend Framework 2 - Annotation forms - Multiple forms in one view


I'm using ZF2 and AnnotationForms. This worked great for me until now.

I have this exception that I want to display three forms in one view.

Basically I do the following:

<form>
  <?php for field in form1: echo field ?>
  <?php for field in form2: echo field ?>
  <?php for field in form3: echo field ?>
  <input type="submit" />
</form>

My problem is that some of these forms have fields with the same name (eg. "city"). So some of the input data gets lost.

I thought about renaming the fields (name-attribute in HTML) but then the mapping in the action with $entity->setData() won't work...

Does anyone has an idea how I can solve this without the need to build my whole form staticly in plain html?


Solution

  • You can use ComposedObject annotation, this will actualy create fieldset from some other model/entity file. It's very good explainded here: http://devblog.x2k.co.uk/using-the-composedobject-zend-framework-2-form-annotation/