Skip to main content
Participating Frequently
November 22, 2013
Question

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

  • November 22, 2013
  • 2 replies
  • 2813 views

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

    This topic has been closed for replies.

    2 replies

    Legend
    November 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.

    mayer4Author
    Participating Frequently
    November 22, 2013

    I'll give it a shot thanks.

    Carl Von Stetten
    Legend
    November 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.

    mayer4Author
    Participating Frequently
    November 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

    Carl Von Stetten
    Legend
    November 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


    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.