Please help with dynamic form field names in cfloop
Hi,
I need to create a form with day, date, month, year and time for 12 months
Instead of coding them 12 times, I create day,date,month,year and time fileds in my form 1 time and then I use cfloop from="1" to="12" index="i" to loop these form fields 12 times.
I gave each form field name such as: <input type="text" name="ScheduleDate_# i #" value=" "> this way each of those field will be named differently such as:
ScheduleDate_1, ScheduleDate_2,ScheduleDate_3, ScheduleTime_1,ScheduleTime_2, etc
I'm facing problem when this form is submitted, I think the error has something to do with the pound sign (##) when it comes to updating the back end
I use MS SQL
It doesn like this:
<CFLOOP From="1" To="12" index="k">
<CFIF Len(Trim(Form.MeetYear_#k#)) NEQ 0 AND Len(Trim(Form.MeetTime_#k#)) NEQ 0>
<cfquery name="CreateSchedule" datasource="#DSN#">
UPDATE TableSchedule
SET SchedDay = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SchedDay_#k##">,
SchedMonth =
<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SchedMonth_#k##">,
SchedDate =
<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SchedDate_#k##">,
SchedYear =
<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SchedYear_#k##">,
SchedTime =
<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SchedTime_#k##">
Where SchedId = <cfqueryparam cfsqltype="cf_sql_numeric" value="#k#">
</cfquery>
</CFIF>
</CFLOOP>
Can anyone help please?
