Skip to main content
Participating Frequently
July 10, 2008
Answered

loop through post variables?

  • July 10, 2008
  • 3 replies
  • 615 views
I'm trying to make my own viewstate setup (I'm a .NET guy trying to work on a CF site for a client). Is there a way I can cycle through all the available post variables when a form is submitted? I want to capture these and put them into a struct which will then be saved to the session, from which I can grab or modify fields as I need.

I know I can grab them individually, such as FORM.myinputfield, but how can I blindly cycle through them and put them into a struct? Thanks!

Ryan
    This topic has been closed for replies.
    Correct answer Newsgroup_User
    rpeters1983 wrote:
    >
    > I know I can grab them individually, such as FORM.myinputfield, but how can I
    > blindly cycle through them and put them into a struct? Thanks!
    >
    > Ryan
    >

    Here is how to take the FROM structure and put it into a SESSION
    structure for persistent across request. It should be easy to follow
    through.

    <cfset session.myFormData = form>

    The form data is already a structure and can be handled exactly like any
    structure you create.

    An Examples:

    <cfloop collection="#form#" item="field">
    #field# contains the value of #form[field]#
    </cfloop>


    3 replies

    Inspiring
    July 10, 2008
    rpeters1983 wrote:
    > OK, I spoke too soon. I was able to get it to cycle through the loop. Now I'm trying to find out how to save that to a struct and then to a session variable. Do I have to use WDDX? Thanks again.

    Not of you follow the suggestions in my previous post.
    Participating Frequently
    July 11, 2008
    quote:

    Originally posted by: Newsgroup User
    rpeters1983 wrote:
    > OK, I spoke too soon. I was able to get it to cycle through the loop. Now I'm trying to find out how to save that to a struct and then to a session variable. Do I have to use WDDX? Thanks again.

    Not of you follow the suggestions in my previous post.



    Your answer is correct. I posted my followup before I noticed your post. Thanks.

    Participating Frequently
    July 10, 2008
    OK, I spoke too soon. I was able to get it to cycle through the loop. Now I'm trying to find out how to save that to a struct and then to a session variable. Do I have to use WDDX? Thanks again.
    Newsgroup_UserCorrect answer
    Inspiring
    July 10, 2008
    rpeters1983 wrote:
    >
    > I know I can grab them individually, such as FORM.myinputfield, but how can I
    > blindly cycle through them and put them into a struct? Thanks!
    >
    > Ryan
    >

    Here is how to take the FROM structure and put it into a SESSION
    structure for persistent across request. It should be easy to follow
    through.

    <cfset session.myFormData = form>

    The form data is already a structure and can be handled exactly like any
    structure you create.

    An Examples:

    <cfloop collection="#form#" item="field">
    #field# contains the value of #form[field]#
    </cfloop>