Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to you save form data on a form submitted to itself?

New Here ,
Nov 22, 2013 Nov 22, 2013

I haven't touched cold fusion in 10 years so I'm a bit out of practice. I have a request from a user to save the form data on a form she submitted. I looked at the code and even made it just a simple form with no cf tags at all. And it still deletes the form data, is there a way to save it when the user clicks submit? I've tried adding the preservedata = "true" and that doens't help either. Any thoughts would be great.

Thanks

Laura

2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 22, 2013 Nov 22, 2013

@mayer4,

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?

-Carl V.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 22, 2013 Nov 22, 2013

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.

Thanks

Laura

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 22, 2013 Nov 22, 2013

If you are submittiing the form to itself (to the same page that contains the form), then what I do typically is:

  1. 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="">
  2. Put the form inside a <cfoutput> block.
  3. 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.

-Carl V.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2013 Nov 25, 2013

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.

Laura

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 25, 2013 Nov 25, 2013

@mayer4,

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?

-Carl V.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2013 Nov 25, 2013

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>

</cflock>

<cfdump var="#session#">

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?

Laura

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 25, 2013 Nov 25, 2013

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".

-Carl V.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 25, 2013 Nov 25, 2013
LATEST

This is ancient, its about 10 years old.

I will try that thanks for your help Carl. Much appreciated.

Laura

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 22, 2013 Nov 22, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 22, 2013 Nov 22, 2013

I'll give it a shot thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources