I have a form with a multi-level tree of one to many relationships. For example:
Match -> Phase 1 -> Phase Property 1
-> Phase 1 -> Phase Property 2
-> Phase 2 -> Phase Property 1
-> Phase 2 -> Phase Property 2
-> Phase 2 -> Phase Property 3
-> Phase 3 -> Phase Property 1
-> Phase 3 -> Phase Property 2
So, on the front-end I am able to add many phases to a match and many phase properties to a phase.
In the PHP back-end, I would like to be able to represent this data in a multi-dimensional array, so that I can loop through all the phases and then loop through each phase’s properties. Ideally, I would like to stay away from managing Ids/names through JavaScript.
I know I can receive an array in PHP using something like this:
<input type="text" name="phases[]" />
But, how do I continue this pattern for the properties? Can I do something like:
<input type="text" name="phaseProperties[][]" />
and then somehow “link” each property to the right phase?
If the input fields appear on a static page, then you should already know how much input fields you are going to make on the server side. So why is using fields like:
such a bad thing? If the fields are being dynamically (client-side) generated then there shouldn’t be a problem naming them dynamically aswell. You seem to be constraining yourself too much for no apparent reason.