Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dynamic input fields...

Participant ,
Nov 18, 2009 Nov 18, 2009

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

TOPICS
Advanced techniques
802
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2009 Nov 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>    

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 18, 2009 Nov 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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 18, 2009 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2009 Nov 19, 2009
LATEST
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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources