tags:

views:

88

answers:

1

The Form variable in my form is being passed /retrieved via Session.

I have a troublesome Form variable(formField1) that was NOT DEFINED properly in the Session. But the whole form was put into use.Then this particular Form variable(formField1) was filled , and used .Hence this undefined Form variable, got trapped in the Session, as all the form variable is being passed /retrieved via Session for my from. This was throwing an error. I gave a stop gap solution:-

 <cfif isDefined("TTsession.filing.formField1")>
       <cfset TTD formField1 = TTsession.filing.formField1>
     <cfelse>
       <cfset TTD formField1 = "0">
     </cfif>

TTsession= name of the Session variable formField1=name of the erroneous form field.

As a result of which all the forms in which “TTsession.filing.formField1” was improperly defined are giving an output of “0”.

I do not want this. What I want to do is:

  1. Check Does form variable EXIST in session?
  2. If yes < cfset FormVar1=session. FormVar1>

  3. If NO a. KILL THE MISSING form variable in that Session. b. re-Define the form variable FormVar1 right here in that Session. < cfset FormVar1=session. FormVar1>

Kindly help me I am using CFMX6.1.

-Rames

+4  A: 
<cfparam name="FormVar1" default="0">

<!--- set overide defaults if in the session --->
<cfif StructKeyExists( TTsession.filing, "formField1")>
   <cfset FormVar1 = TTsession.filing.formField1>
</cfif>

I think the problem might be where you have created this session, however if you merely want to set defaults just use cfparam :

 <cfparam name="session.filling.formfield1" type="numeric" default="0">

So if the session var is defined, do nothing. Else define it with the value of zero. All in one line.

ethyreal
thanks "ethyreal".But I really want to tell it "if form variable is undefined in the session" DEFINE it right now.How to do this?
Rames
cfparam will define an undefined value, but not overwrite a defined one.
Ben Doom
Ben my worry is that those forms in which the formField1 is undefined in "Session" , are unable to EDIT /SAVE their forms...of course this needs a lengthy look at the code...what I want to Provide A condition that EVEN IF "formField1 " IS UNDEFINED IN THE "Session" (which an user used while SAVING the form some time ago),DEFINE IT NOW!
Rames
Any how thanks you, I will work it out as suggested here.
Rames
@Rames unless I'm missing something you just described cfparam's entire function. If this is not the case please provide more information or update your question.
ethyreal
thanks ethyreal , I will use CFPARAM
Rames
THANKS A MILLION "ethyreal" worked like charm!
Rames