Skip to main content
Participant
September 24, 2010
Question

Mulitple row submit value

  • September 24, 2010
  • 4 replies
  • 774 views

I will like to submit mutliple rows using form, but found out that if a certain value is empty. Coldfusion does not append to the submit string.

See example:

form.cfm

<form action="action.cfm" method="post">

      <input type="text" name="a" value="1">

      <input type="text" name="a" value="2">

      <input type="text" name="a" value="3">

      <input type="text" name="b" value="1">

      <input type="text" name="b">

      <input type="text" name="b" value="3">

</form>

action.cfm

<cfoutput>
#form.a#
<br>
#form.b#
</cfoutput>

Result: 1,2,3    for #form.a#
Result: 1,3       for #form.b#

I think this is coldfusion default behaviour, is there any way i can return the results as folllow?

Expected Result: 1,2,3    for #form.a#
Expected Result: 1,,3       for #form.b#

    This topic has been closed for replies.

    4 replies

    BKBK
    Community Expert
    Community Expert
    September 30, 2010

    Why don't you just get the browser to display a space, like this

    <input type="text" name="b" value="1">

    <input type="text" name="b" value="& #160;">

    <input type="text" name="b" value="3">

    or

    <input type="text" name="b" value="1">

    <input type="text" name="b" value="& nbsp;">

    <input type="text" name="b" value="3">

    [ignore the space after the &]

    September 30, 2010

    First you are going to want to name each of your fields in the input form uniquely.  There is not much of a reason not to even if it's dynamically generated.  (Especially if it's a dynamically generated form.)

    Then in your action page you should be scrubbing the input anyway.  (You are scrubbing your input right?)  If you are not start.

    While scrubbing your input, within the same logic it should be easy to identify that one of the form fields did not submit any input and simply set the value of the variable to nothing <cfset myvar=""> or add a blank into your csv string.  (Or doe what ever.)

    Remember that no input comming through is still data but if you don't have a unique name on the form field it's usless to you.

    You can specifically look for blanks by using the data passed in the Form.Fieldnames structure available to your processing template.  Try this out to see what I mean.

    <CFLOOP INDEX="myField" list="#Form.FieldNames#">
      #myField# = #Evaluate(myField)#<BR>
    </CFLOOP>

    Alternately you can loop over the entire Form structure which at times includes some additional handy information.

    Hope that helps!

    -Joe

    Inspiring
    September 24, 2010

    I think you will have more control over your form fields if you gave them different names.  If you insist on having the same names, try this:

    <input type="text" name="a" value="1">

    <input type="hidden" name="a" value="^">

    <input type="text" name="a" value="2">

    <input type="hidden" name="a" value="^">

    <input type="text" name="a" value="3">

    Then you can use list and string functions to get your desired results.

    Inspiring
    September 24, 2010

    I suspect the browser is not submitting input elements which do not have a value. From the W3C "If a control doesn't have a current value when the form is submitted, user agents are not required to treat it as a successful control."  In the case of your sample one of the input elements lacks a value.

    http://www.w3.org/TR/html401/interact/forms.html#successful-controls