Skip to main content
Inspiring
May 18, 2006
Answered

Session variable

I have the attached code for declaring and then using session values. However anytime I submit a form to the page with the session variables I am told that the varaibles are not defined, which should not be so since I have declared the said variables.

For example I am currently getting the following error: Element PRODUCTNAME is undefined in FORM. But as per my code, this has been defined. I have also tested the other elements and they are all being shown as undefined.

As always I aprreciate the help

    This topic is closed to new replies. Start a new post to keep the conversation going.
    BKBK
    BKBKCorrect answer
    Community Expert
    May 19, 2006
    <cfif not isDefined("requestProfile")>
    Probably an error. It appears you wanted to do <cfif not isDefined("session.requestProfile")>.

    For example I am currently getting the following error: Element RODUCTNAME is undefined in FORM. But as per my code, this has been defined. I have also tested the other elements and they are all being shown as undefined.
    You probably haven't submitted a form or, if you did, some of the fields are not in it. To be sure, do something like this

    <cfif isdefined("form.productname")>
    <!--- Remember only details for product if customer (via email) already exists else remember all--->
    <cfif chkEmail.recordcount IS 0>
    <cfset Session.requestProfile.title = Form.title>
    <cfset Session.requestProfile.lastname = Form.lastname>
    <cfset Session.requestProfile.firstname = Form.firstname>
    <cfset Session.requestProfile.addrs1 = Form.addrs1>
    <cfset Session.requestProfile.addrs2 = Form.addrs2>
    <cfset Session.requestProfile.city = Form.city>
    <cfset Session.requestProfile.country = Form.country>
    <cfset Session.requestProfile.zipcode = Form.zipcode>
    <cfset Session.requestProfile.mobile= Form.mobile>
    <cfset Session.requestProfile.phone = Form.phone>
    <cfset Session.requestProfile.fax = Form.fax>
    </cfif>
    <cfset Session.requestProfile.productname = Form.productname>
    <cfset Session.requestProfile.productmodel = Form.productmodel>
    <cfset Session.requestProfile.producttype = Form.producttype>
    <cfset Session.requestProfile.productyear = Form.productyear>
    <cfset Session.requestProfile.productdescription = Form.productdescription>
    </cfif>

    5 replies

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    May 19, 2006
    <cfif not isDefined("requestProfile")>
    Probably an error. It appears you wanted to do <cfif not isDefined("session.requestProfile")>.

    For example I am currently getting the following error: Element RODUCTNAME is undefined in FORM. But as per my code, this has been defined. I have also tested the other elements and they are all being shown as undefined.
    You probably haven't submitted a form or, if you did, some of the fields are not in it. To be sure, do something like this

    <cfif isdefined("form.productname")>
    <!--- Remember only details for product if customer (via email) already exists else remember all--->
    <cfif chkEmail.recordcount IS 0>
    <cfset Session.requestProfile.title = Form.title>
    <cfset Session.requestProfile.lastname = Form.lastname>
    <cfset Session.requestProfile.firstname = Form.firstname>
    <cfset Session.requestProfile.addrs1 = Form.addrs1>
    <cfset Session.requestProfile.addrs2 = Form.addrs2>
    <cfset Session.requestProfile.city = Form.city>
    <cfset Session.requestProfile.country = Form.country>
    <cfset Session.requestProfile.zipcode = Form.zipcode>
    <cfset Session.requestProfile.mobile= Form.mobile>
    <cfset Session.requestProfile.phone = Form.phone>
    <cfset Session.requestProfile.fax = Form.fax>
    </cfif>
    <cfset Session.requestProfile.productname = Form.productname>
    <cfset Session.requestProfile.productmodel = Form.productmodel>
    <cfset Session.requestProfile.producttype = Form.producttype>
    <cfset Session.requestProfile.productyear = Form.productyear>
    <cfset Session.requestProfile.productdescription = Form.productdescription>
    </cfif>

    Translate
    AbdlahAuthor
    Inspiring
    May 20, 2006
    Thanks, the code works. I am just a little confused as to why I have to check that one of the fields is defined(i.e <cfif isdefined("form.productname")> before my assignment of values will work. Basically ColdFusion is refusing to recognize
    form fields until one of them has been tested to check for existence.

    Translate
    BKBK
    Community Expert
    Community Expert
    May 20, 2006
    why I have to check that one of the fields is defined(i.e <cfif isdefined("form.productname")>
    Suppose Coldfusion enters a page and encounters, for example, <cfset myVar = form.fieldVal>. If this is just the "first pass" of the page, and a form has not yet been submitted, Coldfusion will generate an error. There is no form scope yet, hence the need for <cfif isdefined("form.productname")>. In fact, you may use any form field for the test, e.g. <cfif isdefined("form.someOtherFormFieldName")>

    Translate
    Participating Frequently
    May 18, 2006
    You've misread the error message. it's telling you thatt Form.ProductName is undefined not Session.ProductName.
    <cfif IsDefined("Form.ProductName")>
    Translate