How can I process an unlimited amount of elements using Zend Form

62 views Asked by At

Consider the following html...

<form method="post">
  <input type="colour[]">
  <input type="colour[]">
  <input type="colour[]">
  ...

In PHP it is trivial to handle the incoming results using $_POST['colour'] because it's an array. Buy how can this be achieved using Zend Forms?

I tried whacking [] on the end of the element name, but ZF rejects it.

I have tried using setElementsBelongTo() with subforms but this means I have to set the amount of elements to a nominal amount. ie. if I want four elements I must add four elements. When really I want to be able to stipulate that an element can multiple instances.

Ideally I've like the be able to add extra elements on the frontend using JavaScript and they would then be added in.

1

There are 1 answers

1
Weltschmerz On

Try calling setIsArray(true) on your element object. That should allow you to use array notation for name.