I'm attempting to create a form to update multiple rows of data from a table. The table has four columns ( cola, colb, colc, cold ). I am generating the form dynamically with a foreach loop in my view. At present I am using
text('cola[][cola]', $this->cola...
And on down to name and then populate the form fields. This works fine except that it returns an array of four arrays ( cola, colb, colc, cold ), so that I have all of my cola values in one array and all of my colb values in another etc.
What I would like is to return an array of each row that is submitted, so that my result would be something like
0(cola=3, colb=7, colc=2, cold=99)
So that I can access the values simply with a for each loop. I am, however, HTML remedial and cannot seem to get the name right on the form elements to accomplish this. I know that the answer is obvious, but I keep running into either the arrays I do not want or only submitting the data from the final row.
Edit for clarifications...
Use of
text('row[$this->key][cola]'
Or
text('row[$i][cola]'
with $i as an iterator results in one array with the name of $i or $this->key that only returns the last row submitted. Removing the quotes, as in
text(row[$i][cola]
Results in an undefined constant, because the string is expected.
The closest that I have come to success is
text('row['<php echo $i ?>'][cola]'
This actually names the form elements correctly, but breaks the elements themselves. They render as plain text and not as input boxes. I really am going a bit bonkers on this one.
text('row[][cola]', $this->cola...
- Landjeatext('row[$incrementer][cola]'
If you are in a for loop use the incrementer from that. Otherwise add a new $i++ to your foreach loop. So after your fourth col, you would increase $i by one, for the next row. - Landjea