I need to generate an input form for a series of measurements
(i.e. a Data Set).

Each measurment is stored in one record of the DataSetDtl table.

The number of measurements can vary from data set to data set.
(That is, the number of records in DatSetDtl can vary from
DsHdrID to DsHdrID.)

My dilemma is this.  How should I dynamically name the FORM
variables in a way that will make it easy to 1) create the FORM
itself and 2) post each measurement back to the DataSetDtl table
once the FORM is submitted?
(I can't "hard code" them because I don't know how many of them
there will be until run time.)

This application is running under CF 4.5 but could be moved to a
server running MX.

Right now, I took the following approach:

I fetch the measurments in the data set that is to be edited.
I then create an array of FORM variables and store the
existing readings in it.

<!---  Fetch all of the Point information  --->
<CFQUERY name="GetPoints" dataSource="#application.DS#">
SELECT *
FROM DataSetDtl
WHERE DataSetDtl.DsHdrID = #URL.DsHdrID#
</CFQUERY>

<CFSET Form.aReading    = ArrayNew(1)>
<CFSET Variables.nPoint = 1>

<CFLOOP query="GetPoints">
<CFSET Form.aReading [nPoint]  = GetPoints.Reading>
<CFSET Variables.nPoint = Variables.nPoint + 1>
</CFLOOP>

Next, I loop through the query and create the FORM using the
arrays to populate the <INPUT items.

<!---  Here is a snippet of how the FORM is being created  --->

<FORM name="DsDtlMaintenance" method="post"
action="">
<TABLE border="1" cellpadding="4" cellspacing="0" align="center"> <CFSET
Variables.nPoint    = 1>

<CFLOOP query="GetPoints">

<TR>
<TD align="right" valign="top">
<B>#GetPoints.PointBriefDescr#:</B>
</TD>

<TD align="left" valign="top">
<!---  Try dynamically naming the <INPUT item with the array element
name  --->
<INPUT type="text" name="aReading [#nPoint#]" size="10" maxLength="10"
value="#Form.aReading [nPoint]#">
</TD>
</TR>

<CFSET Variables.nPoint = Variables.nPoint + 1>

</CFLOOP>   <!---   query="GetPoints"   --->

</TABLE>
</FORM>

This all works great when creating the form.  Of course,
all hell broke loose when I clicked the Submit button.

CF doesn't like this, for example:
#Form.aReading [1]#

Apparently, this (and the other) FORM variables (Form.aReading [2],
Form.aReading [3], ...)
were never created, or I am just missing something.

I am sure there is an elegant way to handle situations where the
number of input elements on a FORM is dynamic and unknown until
run time.  Any suggestions on how to deal with this would be
much appreciated.

Thanks
Joe Tartaglia
High Caliber Solutions
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to