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

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0

    How to save form data to be recalled at a later date


    I have an app written in fusebox 3, and all is working well. I would, however, like to break the part where users register down into smaller fuses.

    Scenario - currently, users submit form info which is then checked against a database to make sure the 'team_name' field is unique. If it is not, they are redirected to submit new info, otherwise it is written to a database. At the moment I use an exit fuseaction to redirect to the URL if the form entries fail. I would like to do the same for a successful registration - an exit fuseaction that then uses a query to write their form info to a database and emails the administrator. However, when I try this, cold fusion cannot remember the previous form entries, and thus chokes.

    My question: Is there any way to save the form info as a variable to be recalled when that fuseaction is triggered?

    All help greatly appreciated
    TIA
    Mark

    Here is my current code, which works fine..
    ===============================

    <cfquery datasource="#request.dsn#" name="teamInfo">
    SELECT team_name
    FROM client
    WHERE team_name = '#form.team_name#'
    </cfquery>

    <cfif teamInfo.recordcount>
    <cflocation URL="#self#?fuseaction=#XFA.failedRegister#">

    <cfelse>
    <!--- ideally, this is where I would like to insert the fuseaction called #XFA.addRegisterInfo# --->
    <!--- insert new record --->
    <cfquery datasource="#request.dsn#" name="register">

    INSERT INTO client (
    team_name, username, password, company_name, address_1, address_2, phone, email
    )

    VALUES (
    '#trim(form.team_name)#',
    '#trim(form.username)#',
    '#trim(form.password)#',
    '#trim(form.company_name)#',
    '#trim(form.address_1)#',
    '#trim(form.address_2)#',
    '#trim(form.phone)#',
    '#trim(form.email)#'
    )
    </cfquery>

    <cfmail
    from="admin@gorebiz.co.nz"
    to="email address go here"
    subject="Super 12 Registration">
    A new team has just signed up for the Super 12 2004 Tipping Competition. Details are as follows:

    Team Name: #form.team_name#
    Address 1: #form.address_1#
    Address 2: #form.address_2#
    Contact Phone: #form.phone#
    Contact Email: #form.email#
    </cfmail>

    <cflocation URL="#self#?fuseaction=#XFA.successfulRegister#">

    </cfif>
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    There are a few options. You could use cfmodule to recursively call the application and run the desired fuseaction, passing in the form structure as an attribute. This may be difficult depending on how you have your application structured.

    You could save the form struct as a session variable so that it is available in the next fuseaction.

    Another option is to serialize the form struct into a WDDX XML string using <cfwddx> and store it in a database or as a client variable. On the next fuseaction you'd have to deserialize the XML back into a CFML structure.

    For the future, you might consider looking at Fusebox 4. Since you can easily call multiple fuseactions from within the controller XML, it makes things like this very easy. No need to copy the variables around, use <cfmodule>, or even use <cflocation>.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    24
    Rep Power
    0
    Yes fusebox 4 is the next step, but not right now. A session variable seems the most apropriate at this stage. So how would I go about doing this?
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    Copy the form structure to a session variable:
    <cfset session.formStruct = form />

    and then on the next page, copy it back to the form scope:
    <cfset form = session.formStruct />

    Don't forget to lock your session reads and writes if a race condition is possible. And you may also want to purge the data from the session scope after you copy the structure back to the form scope. You can do this with structDelete().

IMN logo majestic logo threadwatch logo seochat tools logo