4 Replies Latest reply on Nov 19, 2009 10:47 AM by BKBK

    Dynamic input fields...

    tomtomtom Level 1

      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

        • 1. Re: Dynamic input fields...
          BKBK Adobe Community Professional & MVP

          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>    

          • 2. Re: Dynamic input fields...
            chrisbowyer Level 1

            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[i]#</cfoutput><br>
                </cfif>
            </cfloop>

            1 person found this helpful
            • 3. Re: Dynamic input fields...
              Dan Bracuk Level 5

              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.

              • 4. Re: Dynamic input fields...
                BKBK Adobe Community Professional & MVP
                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.