Skip to main content
Inspiring
November 18, 2009
Question

Dynamic input fields...

  • November 18, 2009
  • 3 replies
  • 836 views

Hi all

I've got the following question:

Assume I have a file called form.cfm which contains a form where certain input fields (input type=text) are generated dynamically from a query. More specifically I loop through my query and generate these input fields. For naming of each field I use a result ID out of my query. I looks about this way:

<cfloop>

<inpt type="text" name="#part_ID#" value="">

</cfloop>

After I try processing the form mentioned above resp. passing the form values to a file called result.cfm. There I do not understand how to get the dynamically created variables and its values!

I made a <cfdump> for the form and everything was shown fine in a struct, but I do not have any clue how to represent the struct result on a web page.

This question is most probably very basic!?

Many thanks for inputs

Kind regards

This topic has been closed for replies.

3 replies

Inspiring
November 18, 2009

When I do stuff like this, I have a static part of the form field name.

<cfoutput query="aquery">

<input name = "abc#partnumber#">

Then on the results page, when I loop through the form fields, I look for things that start with "abc".

This method is more robust when you have more than one form field associated with the same database record.

BKBK
Community Expert
Community Expert
November 19, 2009
This method is more robust when you have more than one form field associated with the same database record.

I think it is just a different method, and just as robust as the others.

chrisbowyer
Known Participant
November 18, 2009

A slight variation to exclude  the name and value for submit can be written like this:

<cfloop index="i" list="#form.fieldnames#">
    <cfif #i# IS NOT "submit">
        <cfoutput>#i#: #form#</cfoutput><br>
    </cfif>
</cfloop>

BKBK
Community Expert
Community Expert
November 18, 2009

On the action page, result.cfm, the story is much simpler than on the form page. When a form is submitted Coldfusion stores all the submitted fields in a comma-delimited  list. The list is form.fieldnames.

That is, you can obtain the field names (and this includes the submit field), from

<cfloop list="#form.fieldnames#" index="field">
<cfoutput>
field name:#field# <br>
field value: #form[field]#<br><br>
</cfoutput>
</cfloop>