I’m trying to create a form using Zend_Form (Zend_Framework component). The users should be able to add arbitrary number of fields. Just as you can upload files with gmail GUI.
Example:
[_____] [+]
After clicking on the [+] button:
[_____]
[_____] [+]
To get things complicated, I’d like to add field pairs, so it would look like this:
[_____] [_____]
[_____] [_____] [+]
How can I keep the availability of the easy built-in validation and assign methods while implementing this feature? Do I need a subform? Do I need something else? After submitting the form, the code should be able to map the fields into and array.
I’m afraid I must subclass Zend_Form or SubForm, but I want to be aware of the easiest/prettiest way.
Here is my own solution:
I have created two hidden fields, one for the keys, one for the values. A javascript piece of code creates fake field pairs on deamand, and onChange, it maps all the fake fields into the hidden ones using JSON.
It’s easy to handle on server side, but the used javascript techique is not discrete.