Forms - Variable Number of Form Fields
Posted: Mon Apr 23, 2007 6:47 pm
I am currently putting together a web form in table fashion. Each row is a unique office location from the database. Each location has the same five columns, which consist of drop-down menus for user selection.
I would like to make this form as dynamic as possible--basically, not having to update the form processing code every time an office is added to the database, while also avoiding any hard-coded location information in the HTML. Since all the elements belong to the same form--and not separate forms--I'm running into problems. Currently, to identify form elements and to demarcate where one location's fields stop and another begins, I have element names like location01Employee, location01TimeIn, location01TimeOut, location01Coverage, location01Backup, location02Employee, location02TimeIn, location02TimeOut, location02Coverage, location02Backup, etc. The problem is that the form also is meant to handle different scenarios--sometimes, there will be 10 locations on the page, other times there will be 5.
How can I make this form process a variable number of locations and fields, but still uniquely identify all the form elements contained therein? It seems like what I really need to do is "variable-ize" the variable names themselves, so that the "01", "02" portions would be filled in as you go, but I'm guessing that PHP won't go for that.
Any suggestions on how to make this form as dynamic as possible and avoid all hard-coded maintenance? Any help would be appreciated.
I would like to make this form as dynamic as possible--basically, not having to update the form processing code every time an office is added to the database, while also avoiding any hard-coded location information in the HTML. Since all the elements belong to the same form--and not separate forms--I'm running into problems. Currently, to identify form elements and to demarcate where one location's fields stop and another begins, I have element names like location01Employee, location01TimeIn, location01TimeOut, location01Coverage, location01Backup, location02Employee, location02TimeIn, location02TimeOut, location02Coverage, location02Backup, etc. The problem is that the form also is meant to handle different scenarios--sometimes, there will be 10 locations on the page, other times there will be 5.
How can I make this form process a variable number of locations and fields, but still uniquely identify all the form elements contained therein? It seems like what I really need to do is "variable-ize" the variable names themselves, so that the "01", "02" portions would be filled in as you go, but I'm guessing that PHP won't go for that.
Any suggestions on how to make this form as dynamic as possible and avoid all hard-coded maintenance? Any help would be appreciated.