February 7th, 2004, 06:54 AM
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
Here is my current code, which works fine..
<cfquery datasource="#request.dsn#" name="teamInfo">
WHERE team_name = '#form.team_name#'
<!--- 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
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#
February 7th, 2004, 01:13 PM
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>.
February 7th, 2004, 01:40 PM
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?
February 8th, 2004, 03:31 PM
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().