Naming dynamic form elements
Posted: Tue May 14, 2002 5:42 pm
Hi all -
I'm new here and am hoping that someone might be able to help me with a problem I'm having. I've been coding PHP for a couple of months now, so I'm still trying to figure alot of things out, especially forms processing.
I have a script for a parts inventory app that I'm building. Basically, there are 3 screens -- Count Parts, Reconcile Count, Results -- the details for which follow.
The Count Parts form is built dynamically from an array that contains data retrieved from MS SQLServer. I loop through the data array and output "rows" of data -- qtyOnHand (hidden field, from DB query), qtyCounted (text input), itemNumber and itemDescription (both HTML text from DB). For each item, the user enters a physical count and then submits the form.
The Reconcile Count form is built dynamically from the form post variables array based on the items where qtyOnHand and qtyCounted do not match. The user will be able to then enter a reason for the discrepancy, something like backordered, lost, or returned, and specify whether this reason applies to all items in the discrepancy. The data in the form is the difference between qtyOnHand and qtyCounted (HTML text, calculated), reasonCode (HTML select with codes that will go into my DB insert query), and appliesToAll (HTML checkbox, to go in insert query). The user fills out and submits this form, and is then presented with the Results screen, which takes care of compiling the form results and creating and executing the DB query in the background.
The problem I'm having is how to best name my form elements so that the input data is easily accessed and updated from screen to screen. I wasn't really worried about it at first, and I was simply using an array for each form element and looping through the arrays, comparing values based on the array index. Then I ran into the checkboxes, and that's where my troubles stared. I totally forgot that checkboxes do not pass "false" or "no" or "off" when they are not checked -- they don't pass anything -- so my appliesToAll[] array indexes get messed up when a user unchecks an item on the Reconcile screen. And unfortunately I have to keep the checkbox since the project/management team has already signed off on the design/functionality of the application.
Is there a convenient way to keep up with the data from form to form? I thought of trying multidimensional arrays or associative arrays, but I haven't been able to make that work. I also thought of possibly using the part number as the index for my arrays and using foreach() as the looping structure rather than for(). I even thought of using session variables until the director of development here canned that idea for some reason.
So what about it? Any PHP gurus want to try to tackle this and help me out?
Thanks in advance,
-- phil --
I'm new here and am hoping that someone might be able to help me with a problem I'm having. I've been coding PHP for a couple of months now, so I'm still trying to figure alot of things out, especially forms processing.
I have a script for a parts inventory app that I'm building. Basically, there are 3 screens -- Count Parts, Reconcile Count, Results -- the details for which follow.
The Count Parts form is built dynamically from an array that contains data retrieved from MS SQLServer. I loop through the data array and output "rows" of data -- qtyOnHand (hidden field, from DB query), qtyCounted (text input), itemNumber and itemDescription (both HTML text from DB). For each item, the user enters a physical count and then submits the form.
The Reconcile Count form is built dynamically from the form post variables array based on the items where qtyOnHand and qtyCounted do not match. The user will be able to then enter a reason for the discrepancy, something like backordered, lost, or returned, and specify whether this reason applies to all items in the discrepancy. The data in the form is the difference between qtyOnHand and qtyCounted (HTML text, calculated), reasonCode (HTML select with codes that will go into my DB insert query), and appliesToAll (HTML checkbox, to go in insert query). The user fills out and submits this form, and is then presented with the Results screen, which takes care of compiling the form results and creating and executing the DB query in the background.
The problem I'm having is how to best name my form elements so that the input data is easily accessed and updated from screen to screen. I wasn't really worried about it at first, and I was simply using an array for each form element and looping through the arrays, comparing values based on the array index. Then I ran into the checkboxes, and that's where my troubles stared. I totally forgot that checkboxes do not pass "false" or "no" or "off" when they are not checked -- they don't pass anything -- so my appliesToAll[] array indexes get messed up when a user unchecks an item on the Reconcile screen. And unfortunately I have to keep the checkbox since the project/management team has already signed off on the design/functionality of the application.
Is there a convenient way to keep up with the data from form to form? I thought of trying multidimensional arrays or associative arrays, but I haven't been able to make that work. I also thought of possibly using the part number as the index for my arrays and using foreach() as the looping structure rather than for(). I even thought of using session variables until the director of development here canned that idea for some reason.
So what about it? Any PHP gurus want to try to tackle this and help me out?
Thanks in advance,
-- phil --