When you say "save form data", are you referring to saving the data to a database? Or some other persistence mechanism? Can you clarify what you want to achieve?
Sorry about that. The original page shows all the data. The form gets entered and then the user clicks submit....
and now the form data is gone with the data from the search displayed.
Laura, use hidden form fields to pass the data in the form forward. This is the most common way of passing form data back to the same template.
I'll give it a shot thanks.
If you are submittiing the form to itself (to the same page that contains the form), then what I do typically is:
- Add <cfparam> tags at the top of the page to define defaults for the form fields, usually an empty string: <cfparam name="form.myField" default="">
- Put the form inside a <cfoutput> block.
- Put the default values into the form fields: <input id="myField" name="myField" type="text" value="#form.myField#">
Now the form will show the value that was submitted to it. No hidden form fields required.
Thanks to all for your help. However the same problem remains. I can keep the session information until I get to the cflocation page then it erases everything. The token and id remain constant so I'm not getting a new one. I have tried adding addtoken to the cflocation tag as well. It still doesnt care. I'm about to tell the user cold fusion cant do this.
Thanks again for all your help.
I think maybe we need to see some code. This is the first time you've mentioned either session information or the use of <cflocation>. Why are you using <cflocation>? Are you submitting the form to a processing page and then using <cflocation> at the bottom to redirect back to the form page?
This is something I inherited. The original programmer used cflocation to bring the user back to main page. When I was requested to change it . I did this:
On page 1 at the top of the page. I have this.
<cfapplication name="qsErrorVals" sessionmanagement="yes">
<CFinclude template="/include/checkidtop.cfm"> ---css infromation
<CFPARAM name="startDate" default="">
<CFPARAM name="EndDate" default="">
<CFPARAM name="SearchFor" default="">
<CFPARAM name="SearchIn" default="">
<cflock scope="session" type="readonly" timeout="200">
<cfset session.startDate = startDate>
<cfset session.EndDate = EndDate>
<cfset session.SearchFor= SearchFor>
<cfset session.SearchIn= SearchIn>
Then it gets sent back to itself to perform a search. When the user searches the session state is maintained and I can see the data fine. They click on a row to edit and brings them off the current page to an edit page. Session state is still maintained. Once the user clicks on I'm done it brings them back to the main form page via cflocation where session state is lost. I have also added hidden fields to save the form data and again it it fine until the user clicks on I'm done and the hidden form data is erased.
Does that help?
That <cflock> seems wrong. First, if you are using a fairly recent version (8, 9 or 10) I don't think it's even necessary. But if it is, the type "readonly" will actually negate the lock if you try to set session variables inside of the lock (as this codes does). Change the type to "exclusive" (or remove the type attribute as "exclusive" is the default). Then, on any other page where you read those session variables, you could wrap those calls in a <cflock type="readonly">. But I still think the whole locking thing is not necessary (unless you are running a really old version of ColdFusion, like CF6).
As far as the hidden form data or any other form data goes, none of that will survive a <cflocation>. You'd have to make sure any form data that you want to reuse across a <cflocation> is stored in a persistent scope like session or client. Are the session variables you show in the code above the ones you need to reuse? If so, you can use my previous commend about how I reuse form variables, but substitute the references to "form.variablename" with "session.variablename".
This is ancient, its about 10 years old.
I will try that thanks for your help Carl. Much appreciated.