#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    4
    Rep Power
    0

    Cfloop through custom form fields


    I am using CF 9 on Win 2008.

    I have a loop to generate form fields for a shopping cart.

    Every item added to a shopping cart adds the same form name with a number on the end.

    I am then looping to the recieving page and tring to grab those form values using the Post method.

    if I use something like this
    <cfloop name="count" from="1" to="#arrayLen( session.mycart )#">
    <cfif session.mycart[count].ProdID EQ form.Prodid#count#>
    </cfif>
    </cfloop>

    I get an error saying "Invalid CFML construct found". If I put hyphens around the variable the error stops but it still doesn't use the form variable.

    If I set the form field to a variable Durring the loop I doesn't actually grab the form data.

    Here is an example.
    <cfloop name="count" from="1" to="#arrayLen( session.mycart )#">
    <cfset newFormID='form.ID#count#'>
    <cfif session.mycart[count].ProdID EQ #newFormID#>
    </cfif>
    </cfloop>

    This does not error even though it is almost the same as the above example. The newFormID returns the correct form variable name but the problem is CF doesn't test over it again with the correct variable name.

    If I use the same form name for all the items in the cart then in the loop it would not work because it would use the first item every time in the loop right?

    Any ideas on how something like this can be accomplished?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Originally Posted by Cursian
    form.Prodid#count#
    To access the values of dynamic variables, use array notation :

    ie
    FORM["theFieldName"] ....
    FORM["Prodid"& count]
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    4
    Rep Power
    0
    Originally Posted by cfSearching
    To access the values of dynamic variables, use array notation :

    ie
    FORM["theFieldName"] ....
    FORM["Prodid"& count]
    Brilliant! thank you

IMN logo majestic logo threadwatch logo seochat tools logo