Skip to main content
June 5, 2009
Answered

Accesing Post Data in Forms using variables

  • June 5, 2009
  • 1 reply
  • 591 views

I have a problem when I tried to access post data from a form using a variable...

Thhe form


<cfquery name="ConsultaPrecios" datasource="#Application.DB#">
    SELECT * FROM
    VwConsultaPrecios
    ORDER BY NOMBRE_PRE
</cfquery>

<cfform preservedata="yes" name="formaVentaGastos"    action="" onsubmit="verificaCampos()" enctype="multipart/form-data">

    <cfloop query="consultaPrecios">
            <cfoutput>
              <tr align="center" class="forma">
              <td class="forma" align="right">#consultaPrecios.NOMBRE_PRE# - #NumberFormat(consultaPrecios.PRECIO_PRE, "$___.__")# </td></cfoutput>
                 <td class="forma"><cfinput validate="integer" value="0" onChange="if(this.value==''){this.value=0;}validateInt(this, #consultaPrecios.PRECIO_PRE#,'#consultaPrecios.Nombre_Pre#');" maxlength="3" message="El campo de cantidad debe ser entero!!!" type="text" size="8" name="#consultaPrecios.Nombre_Pre#_venta"></td>
                 <td class="forma"><cfinput style="background-color:##999999;" validate="integer" readonly="yes" value="0" type="text" size="8" name="#consultaPrecios.Nombre_Pre#"></td>             
              </tr>
        </cfloop>

</cfform>

Processing the form

<cfloop list="#Form.FieldNames#" index="i">

        <cfif findNocase('Venta',#i#) AND NOT findNoCase('TOTAL', #i#) AND NOT findNoCase('FECHA', #i#) AND NOT findNoCase('RUTA', #i#)>
             <cfset a = 'form.Interno'>
             <cfoutput>#Ii#</cfoutput>

            <br>
        </cfif>

    This topic has been closed for replies.
    Correct answer ilssac

    I do not beleive that I understand what you are trying to do or what probelm you are really having.

    Looking at your logic, I would expect your list loop variable "i" to contain the value of "fieldnames" for one of the loop's iterations.  That logic will loop over each of the values in the list "form.fieldnames" and output one each itteration.

    If you want to access the value from the form structure for each itteration, array notation is the common approach.

    <cfloop list="#form.fieldnames#" index="i">

      <cfoutput>#i#: #form#<br/></cfoutput>

    </cfloop>

    You can do the same thing with a collection loop.

    <cfloop collection="#form#" item="field">

      <cfoutput>#field#: #form[field]#<br/></cfoutput>

    </cfloop>

    HTH

    Ian

    1 reply

    June 5, 2009

    the problem is that instead of bringing variable in form value, brings the string for "i" in the collection... I want to get the value posted in the form, If I use the sintax #FORM.FIELDNAME# then it'll bring the value but using #i# will show me the String "FIELDNAME"..

    Thanks

    ilssac
    ilssacCorrect answer
    Inspiring
    June 5, 2009

    I do not beleive that I understand what you are trying to do or what probelm you are really having.

    Looking at your logic, I would expect your list loop variable "i" to contain the value of "fieldnames" for one of the loop's iterations.  That logic will loop over each of the values in the list "form.fieldnames" and output one each itteration.

    If you want to access the value from the form structure for each itteration, array notation is the common approach.

    <cfloop list="#form.fieldnames#" index="i">

      <cfoutput>#i#: #form#<br/></cfoutput>

    </cfloop>

    You can do the same thing with a collection loop.

    <cfloop collection="#form#" item="field">

      <cfoutput>#field#: #form[field]#<br/></cfoutput>

    </cfloop>

    HTH

    Ian

    June 5, 2009

    Thank you, that was what I was looking for!