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

Retaining form values when moving between forms

Participant ,
Aug 07, 2009 Aug 07, 2009

I can't remember if I asked this or someone else did, but I still cannot understand how to do this, so I am posting for help.

I have a form where I have to check off some values with checkboxes. I then have to enter an employee number. If I do not know it, I can click on an icon and it will take me to the master employee lookup site. Once I find what I am looking for, I click on that employee number and it returns me back to the original form, bringing back the selected employee number and plugging it into the employee number field. This works fine. But the problem I am having is that the check boxes that were checkws prior to the lookup are now gone and I have to recheck them all again.

How can I retain the checked checkboxes on the form after if comes back from the employee lookup ?

2.1K
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
Guest
Aug 07, 2009 Aug 07, 2009

you can store your form structure in a session variable and when you return from the master employee application just read the session variable back and populate the checkboxes based on that.

assuming you are using session handling, otherwise you will have to store the form selections using another method (file, database - posibly with cookies) and assuming the user returns to the form before thier session expires.

-sean

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
Participant ,
Aug 07, 2009 Aug 07, 2009

Thanks for the response. How would I do that ?

assuming I have <cfinput type="checkbox" name="fault" value="A">, <cfinput type="checkbox" name="fault" value="b">, and I check A only,

would I do <cfif isDefined("form.fault")> to check for the existence of at least one checkbox, then redefine it as as session varialble,

<cfset session.fault="#form.fault#"> ?

And when I return from the other form, how to I put the check, in the checkbox ?

This is where I do not understandn what do to.

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
Guest
Aug 07, 2009 Aug 07, 2009

hum - ok, first off, I think you are looking for a radio button type instead of checkboxes of the same name. the way you have it set up is that if any user selects both boxes you will only get the last checked "fault" box value. If the user is only to pick one, use a radio button, if they can make multiple selections, name you checkboxes different. Let's assume you want a checkbox type.

<cfif session.fault.form.faultA is "A"><cfset selected="selected" /><cfelse><cfset selected="" /></cfif>

<cfinput type="checkbox" name="faultA" value="A" #selected# />

<cfif session.fault.form.faultB is "B"><cfset selected="selected" /><cfelse><cfset selected="" /></cfif>

<cfinput type="checkbox" name="faultB" value="b" #selected# />

It may be as easy as:

<cfinput type="checkbox" name="faultB" value="b" <cfif IsDefined("session.fault.form.faultB")>selected</cfif> />

But I don't recall offhand if a form name is passed even if it's value is null

You'll have to test

now, getting your form variables into the session variable is easy, whenever you submit a form CF passes the entire form as a structure so all you need to do is <cfset session.fault = #form# />

But you have a problem that I can see now, you have to submit the form to set the form values in any circumstance so you are going to have to do some extra checking to be sure if the form is actually submitted or if it is just needing the extra values.

And you are going to have the problem of passing the value from your user application back to your current application, that is going to be much more difficult than this.

Dan's thoughts may be worth pursuing and actually I think is a better solution, personally I'm thinking "webservice". what you think Dan?

also, code above, not tested, the "session.fault.form.faultA" may be the wrong way to address a structure inside of an array, read docs, test, etc....

-sean

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
Participant ,
Aug 09, 2009 Aug 09, 2009

So is there a solution to this problem ?

The form is not submitted yet. All the checkboxes are checked, then it goes to the lookup and when it comes back, the checkboxes are then unchecked because the form is never submitted.

Is there a way to keep the checkboxes checked without submitting the form ?

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
LEGEND ,
Aug 07, 2009 Aug 07, 2009

Sean's approach will work, but it's nice to have choices.  You can use a javascript pop up or a modal dialog to get to the master employee lookup site and send your variable back to the current page once the user is done.

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
Participant ,
Aug 09, 2009 Aug 09, 2009

Dan, will your solution work if the form has not been submitted yet ? If it will work, can you show me how to do it ?

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
Participant ,
Aug 10, 2009 Aug 10, 2009

I really need some help on this topic.

Can it even be done, and if it can, can somebody please show me how to do it ?

The checkboxes are checked and the form not submitted  yet, they go to the lookup and then return to th form and all the checked checkboxes are now unchecked. Is there a way to keep them checked ?

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
Valorous Hero ,
Aug 10, 2009 Aug 10, 2009

No, you can't keep them checked.

But there are many ways to use CFML and|or JavaScript to default them to checked when the form is rebuilt

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
LEGEND ,
Aug 10, 2009 Aug 10, 2009

google "javascript return value to parent window"

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
Advocate ,
Aug 11, 2009 Aug 11, 2009

In addition to using a JavaScript pop-up window for the look-up, this also seems like a great opportunity to use the <cfwindow> tag.  That way you can provide your look up functionality to your user right on the same screen, without having to change URLs.

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
Engaged ,
Aug 12, 2009 Aug 12, 2009
LATEST

Here's how I do it...

(1) I always use Sessions.  In the main form of my application, I set up the session and I store a single variable:  Session.Exists = True.  All other forms begin something like this:  (It's actually an include-file.)

<cflock ...>

<cfset SessionExists = StructKeyExists(Session, "Exists")>

</cflock>

<cfif NOT SessionExists>

   <cflocation ... send 'em back to the home 'cuz their session has expired>

   <cfabort>

</cfif>

(2) Now that we know that a session exists, we store various structs in the Session to contain the default or current values that have been used in a particular form.  If the Session scope does not contain a particular struct, it is automagically created with appropriate default values.)  This becomes "what we display," and when we capture the user's responses, we store them there, even before we validate them.  The session pool therefore becomes the vehicle for communication between the various forms.

(3) If we reach a point where a particular piece of information is no longer useful, we delete the appropriate structure from the Session, thereby wiping out the entire set of values at once.

(4) Structs and Arrays can, of course, contain other Structs and Arrays.  You can build data structures of arbitrary complexity.

(5) As of late, I have found myself specifying individual CFCs for each logical "object" in my application.  This is true object-oriented programming, as best as ordinary CFC techniques can do without plunging headlong into the underlying nether-world of Java.  In those CFCs, I deliberately try to conceal just how information is maintained and stored, so that these necessary inter-dependencies within my application are concentrated in just one place.  "The structure is 'the object,' and the methods are found 'here and only here.' "

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