Reputation: 318
This question may look really simple but I can't find any answer on the web neither in the ZF2 "documentation".
I am simply trying to create a collection of inputs of type "email" and validates it but I don't find the way to do so properly using zend-form.
(The form may be able to add or remove some of these email elements)
The HTML should look like this :
<form>
<input name="additionalEmails[]" type="email" />
<input name="additionalEmails[]" type="email" />
<input name="additionalEmails[]" type="email" />
</form>
Please help!
Upvotes: 0
Views: 46
Reputation: 605
Zend Framework has 'Form Collections' that help you to achieve this.
You can read more about this in the Zend Framework documentation. https://framework.zend.com/manual/2.3/en/modules/zend.form.collections.html
In the documentation, they use the Collection type to create a collection of fieldsets, but you can use the same code to make a collection of basic elements (like your e-mail field).
The allow_add
flag will enable adding and deleting items. If you wish to do this dynamically, you might need to write some javascript, but Zend Form gives you a nice HTML template you can use. This is also described in the documentation here:
https://framework.zend.com/manual/2.3/en/modules/zend.form.collections.html#adding-new-elements-dynamically
Upvotes: 2