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

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