I am using Zend Framework I have a form that allows me to create a user. It has all of the necessary validation and it works well.
I was tasked with creating a single page that allows me to create up to 25 new users with a single submit.
example:
- salutation / first name / last name / email
- salutation / first name / last name / email
- salutation / first name / last name / email
- salutation / first name / last name / email
How can I leverage the form I created for a single user and allow for each new user to get validated separately?
Is there some way to have an array of forms or something else that will achieve the same thing?
Try something like this (untested):
Usage:
Explanation:
The
setElementsBelongTo()call on subforms should create notations similar to this (simplified of course):You form should be able to automatically recognize the submitted POST values when validating.
Of course you should probably also look into the laying out / decorating of the sub forms, but I’ll leave that up to you as an exercise. 😉
EDIT
Sorry, the second param to
addSubForm()is mandatory (added it now, and also added the optional$orderparam). I believe it should also automatically set the sub form to belong to the correct namespace already. Not completely sure about that though. See what happens if you leave out thesetElementsBelongTo()call on the sub form.