Skip to main content
September 12, 2010
Answered

How to get a form entry with index ?

  • September 12, 2010
  • 1 reply
  • 988 views

Guys:

I have a form and I submit data through this form.  Upon clicking a submit button, I want to get the data that a user entered.  Please review the following ColdFusion code to see what I mean:

for (i = 1; i LTE ArrayLen(cateNodes); i++) {
      itemNodes = cateNodes.item;
      for (j = 1; j LTE ArrayLen(itemNodes); j++) {
          if (IsDefined("FORM.submit_#i##j#")) {
             item = "FORM.item_" & i & j & "_sm";
             writeoutput(#item#);
          }
     }
}

This form has multiple submit buttons.  Suppose that the "submit_ij" button is clicked, I want to be able to get the value that a user entered for item_ij_sm.  For example, I want to get the value entered for

#FORM.item_21_sm#

Instead displaying the value that the user entered for item_21_sm, it displayed FORM.item_21_sm.  And, I can see why it did that.  It's because FORM.item_21_sm is a string.  It would have been very easy without the indecies.

I'm a ColdFusion newbie.  Any recommendation is appreciated !  Thanks a lot !

    This topic has been closed for replies.
    Correct answer ilssac

    Guys:  I would like to thank for your recommendation using HTML selection instead of multiple submit buttons and I will seriously consider this.  However, this is not the point of my question.  The point is that, for example, how do I get user's input for

    #FORM.item_21_sm#

    The difficult thing here is how to insert the two indeces i and j into item_.  If you spend your time and follow my example, you'll see that it does not work.  It does not display the value entered by the user for item_21.  Instead, it displays FORM.item_21_sm.  It would have been extremely easy without the indecies i and j because #FORM.item# works as expected.  So, the question here is that, if I have multiple items and if I don't use HTML selection/option, how can this be handled in ColdFusion ?  Please see my original post for details.  Thanks so much.


    Array Notation.

    <cfoutput>#form["submit" & i & j]#</cfoutput>

    1 reply

    Inspiring
    September 12, 2010

    My recommendation is to replace the multiple submit buttons with radio buttons.  It's more user friendly and simpler for you to process the form.

    September 13, 2010

    Thanks Mr Bracuk.  I will consider your recommendation.

    Hope to hear from other developers regarding my question in my original post.

    tclaremont
    Inspiring
    September 13, 2010

    Dan hit the nail on the head. Your life will be made much easier by following his suggestion.

    Additionally it will make maintenance much easier in the future in the event that you want to add or remove options from the form.