This content has been marked as final. Show 7 replies
<cfparam> Set a default value if none is passed.
I understand what you're getting at, but where would I put the cfparam? The form is like the attached. So, if there are two event dates, but only one end time, a simplified version of the lists look like this:
FORM.Event_ID = 200, 200 = TheEvent_ID
FORM.eventDatesID = 365, 366 = List_EventIDs
FORM.endTime = 4:30 = ListOfEndTimes
So, when the loop happens, there is no #ListGetAt(ListEndOfTimes,2)# the second time through and there's an error.
Maybe my basic concept is wrong. Where would I put the cfparam?
Ok, I thought you had empty lists being passed by the form action. So <cfparam> might have helped you there.
This code I'm pretty sure works, I seem to remember reading that you can loop through scope variables like arrays, so that FORM[index] works like...
That would make all lists the same length, but I don't think it would put the correct values at the right point in the list. Would it?
Say the 2nd item lacked an end time. The code would pad the list to create this:
EventDateID = 1, 2, 3
EndTime = 11pm, 11pm, (Empty)
But I need the end times to correspond with the EventDateIDs:
EventDateID = 1, 2, 3
EndTime = 11pm, (Empty),11pm
I know the problem can be resolved by making each row of fields be a form, processing the one that needs to be updated and then starting over, but that seems annoyingly inefficient.
No need for separate forms. Use a counter to number each group of field names
<input name="EventDateID1" ...>
<input name="EventDate1" ...>
<input name="EventDateID2" ...>
<input name="EventDate2" ...>
Then loop through the form fields on your action page
<cfloop from="1" to="#form.maxCounter#" index="counter">
<cfset EventDateID = form["EventDateID#counter#">
<cfset EventDate = form["EventDate#counter#">
... rest of fields
<cfquery name="UpdateFeatures" datasource="#dsn#">
SET EventDate = '#EventDate#', ....
WHERE EventDateID = #EventDateID#
You should validate the values and/or use cfqueryparam
Sounds like it will work. Thanks. I'll try it Monday when my brain has recovered enough. ;-)
Close the square brackets in the real code of course ...
<cfset EventDateID = form["EventDateID#counter#"]>
<cfset EventDate = form["EventDate#counter#"]>