I've got a table of messages/emails and want to have a checkbox to select multiple messages and delete them using the button at the bottom of the table:
Dead simple with standard PHP/HTML without the use of a framework you can:
<input type="checkbox" name="ids[]" value="510">
<input type="checkbox" name="ids[]" value="1231">
Then in PHP loop through the array of IDs that have been selected. I'm trying to achieve the same thing with ZF2.
ZF2 provides:
FormCollection - is a collection of Fieldsets, which I think is wrong for storing an array of IDs passed.
MultiCheckbox - with the current set of ViewHelpers cannot be extracted using an interator
Checkbox - involves dynamically adding inputs with the ID of the name, but can't be looped through and validated so easily.
If FormCollection
supported inserting elements, I would say that is the best option as you could dynamically add them and loop through them when POSTed. I imagine in the near future FormCollection
will allow adding elements, replacing the need for MultiCheckbox
and MultiRadio
as you could iterate through a FormCollection and extract the individual parts
Has anyone else done something like this, how did you go about it?
As I always say: Frameworks make the hard things easy, and the easy things hard.
You can add new items quite easily:
http://framework.zend.com/manual/2.2/en/modules/zend.form.collections.html#adding-new-elements-dynamically
There's an example using a little simple Javascript to add new rows/items.