This content has been marked as final. Show 5 replies
OK, I figured out my loop error - I replace my where form.rec_id with 'i' and it worked except now, it placed all the data in each record. Such as record id 1 field csd_focus has test1, test2, test3, test4 verses just test1. Any suggestions?
> OK, I figured out my loop error - I replace my where form.rec_id with 'i' and
> it worked except now, it placed all the data in each record. Such as record id
> 1 field csd_focus has test1, test2, test3, test4 verses just test1. Any
You are using the same form field name for each instance of the data.
In HTTP this means the data is returned as a list in the form submit
request. You could use listGetAt() type functionality to loop over your
form fields and pull each item out individually, but the HTTP request
does not guarantee the order of the list, and there is a small chance
that the record items may not match up.
What most developers do is dynamically name the form fields so that you
can tell which ones belong together. When you do this you will get form
fields like this:
CSD_FOCUS_1 = test1
CSD_FOCUS_2 = test2
CSD_FOCUS_3 = test3
CSD_FOCUS_4 = test4
CSD_POSITION_1 = Preferred Vendor
You can now be confident that all the '_1' fields belong to the same
record. You then can use array notation and string concatenation to
access the data with a loop.
<cfloop .... index="i">
#form['CSD_FOCUES_' & i]# - #form['CSD_POSITION_' & i]# ...
Ask away if you need further clarification.
Thank you. One question, how do I name my fields in the form so the names will be different? Also, I could have 1 record returned or 20. Here is what I have now
OK, I think I have it figured out. Thank you so much for your help!
How are you looping to create each form field collection?
Presuming a query loop.
<td><cfinput type="Text" name="csd_focus_#myQuery.currentRow#"
Presuming an index loop with 'i' as the index variable.
<td><cfinput type="Text" name="csd_focus_#i#" required="No"></td>
Of course the entire loop will need to be inside an output block of some