Link to home
Start Free TrialLog in
Avatar of synergeticsoul
synergeticsoul

asked on

Form page says that session variables do not exist, but they do



I have a form which has a shopping cart (processed by Paypal). The user is able to register and buy their products successfully, but if the user wants to edit information, they get the error message that the "session.fieldname"  does not exist and that the cause of this error is very likely one of the following things:
The name of the session variable has been misspelled.
The session variable has not yet been created.
The session variable has timed out.

  if I comment certain fieldnames out, the error message just goes to the next field and repeats same message, different field. i have tried the following:

1) enabling session in my application.cfm file:
<CFAPPLICATION NAME="Cookies" SessionManagement="Yes" setDomainCookies="Yes" setClientCookies="Yes" sessiontimeout="#CreateTimeSpan(0,0,30,0)#">

2) making the edit page separate (instead of a part of the change mode condition).


Not sure what else to do. this is weird because this type of commerce page exists in other locations of the site, and I don't get this error message at all.  please advise.  do I need to create a different cfapplication for this page?  if so, how would I reference it in the edit page?

the form is long, so I won't post it, but here is the url (for testing purposes only):

http://bnaibrith.org/sservices/conventionReg.cfm 
Avatar of anandkp
anandkp
Flag of India image

hmmm not sure what exactly is happening - thou it looks like ur using a reserved keyword as ur variable name "session.fieldname" ... can u try changing the name of the variable & chk again ... just a thought ...

>> if I comment certain fieldnames out, the error message just goes to the next field and repeats same message, different >> field. i have tried the following:
didnt get this ...
Avatar of synergeticsoul
synergeticsoul

ASKER

no,  I just used fieldname as an example.  the fields vary.  the first one is Session.fname, Session.lname and so forth.

I was commenting my lines out to determine if the problem was the fields or the page.
are u sure u have set the session variables for these ???
can we see the code ... can u try outputting them on a page - just to confirm they exists.
what code shall I output?  There is the form and then there is the confirmation page that has the session variables? There is also the application.cfm file?  Not sure which to display without overwhelming anybody???

here is the URL too: http://bnaibrith.org/sservices/conventionReg.cfm 
SOLUTION
Avatar of James Rodgers
James Rodgers
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The best approach here is to use the following when dealing with sessions and form fields (store them in a session-scoped strcuture):

<cfparam name="session.structure_name" default="">
<cfif NOT IsStruct(session.structure_name)>
<cfset session.structure_name = StructNew()>
</cfif>

<!---Create default variables using cfparam--->
<cfparam name="session.structure_name.formFieldName1" default="">

<!-- Clear session of any existing values to allow new form Values passed from the form page to overwrite -->
<cfset StructClear(session.structure_name)>

<!---Place form values into session--->
<cfset session.structure_name.formFieldName1 = form.formFieldName1>

<!---Confirm that the session struct value has been set--->
<cfoutput>#session.structure_name.formFieldName1#</cfoutput>

Also, your CFAPPLICATION NAME value (cookies) may be a reserved word.  Try changing that to something else.

HTH,
Mike
I am just going to add my 2 cents.

You can use <cfdump var="#SESSION#"> if you are using cold fusion 5 server.  Use this as it shows for your variables, it shows everything that is in the page as far as variables.

Also check this portion of code:
An error occurred while evaluating the expression:

#SESSION.fname#

Error near line 26, column 45.

I got this error when I clicked my back & edit feature

So far I don't see anything about reserved words in any errors I am getting.

I would check to see if you have some sort of StructClear(session) in your code in the confimation page, because after you reach that screen everything goes to heck.  Are you preforming any add to database at the confirmation page?

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
synergeticsoul : put the code for the page that is aclled after the registration form is submitted...
I mean the page that forms the session variable....

Also i will suggest to create a session variable that will act as a structure..
i mean u create a variable called formdata...

that is <cfset session.formdata = structNew()>

and then in session.formdata add the keys w.r.t the fieldnames.....

But first paste the code for the page where  u create the session variables and display the Go back and edit btn...

Regards
Hart
Here is the code for the confirm.cfm page (it recalls the session  variables)

I am also including the page the user is redirected if editing is necessary.

Please don't scream at the length, since it was requested,  I will post:

Thank you.
_________________________________________________________________

====confirmReg.cfm

<!----------GET ALL FORM VARIABLES------------->
<cfset #SESSION.fname# = FORM.fname>
<cfset #SESSION.lname# = FORM.lname>
<cfset #SESSION.stno# = FORM.stno>
<cfif IsDefined("FORM.stno2") is "true">
      <cfset #SESSION.stno2# = FORM.stno2>
<cfelse>
      <cfset #SESSION.stno2# = "">
</cfif>
      
<cfset #SESSION.city# = FORM.city>
<cfset #SESSION.state# = FORM.state>
<cfset #SESSION.zip# = FORM.zip>
<cfset #SESSION.workphone# = FORM.workphone>
<cfset #SESSION.fax# = FORM.fax>
<cfset #SESSION.email# = FORM.email>
<cfset #SESSION.program# = FORM.program>

<cfset #SESSION.guests#=Form.guests>
<cfset #SESSION.guestsTotal#=Form.guestsTotal>
<cfset #SESSION.guestsName#=Form.guestsName>

<cfset #SESSION.CustMeals#=Form.CustMeals>
<cfset #SESSION.GuestMeals#=Form.GuestMeals>

<cfif isDefined('form.jobFunction') and form.jobFunction neq "">
   <cfset session.jobFunction=#form.jobFunction#>
<cfelse>
   <cfset session.jobFunction='Not Provided'>
</cfif>

<cfif isDefined('form.Status') and form.Status neq "">
   <cfset session.Status=#form.Status#>
<cfelse>
   <cfset session.Status='Not Provided'>
</cfif>

<cfset #SESSION.TotalSunday#=Form.TotalSunday>
<cfset #SESSION.TotalMonday#= Form.TotalMonday>
<cfset #SESSION.TotalTour#= Form.TotalTour>

<!--- Form variables --->
<table cellpadding="2" cellspacing="2" border="0">
<tr><td class="heading4">Registration Confirmation- Contd. <br><br></td></tr>
<tr><td class="boldtext">You entered the following:</td></tr>
<cfoutput>
<tr>
<Td class="text">
<b>First Name:</b> #Session.fname#<br><br>
<b>Last Name:</b>#SESSION.lname#<br><br>
<b>Address:</b> #Session.stno#<br><br>
<b>City:</b> #Session.city# <br><br>
<b>State:</b> #Session.state# <br><br>
<b>Zip:</b> #Session.zip#<br><br>
<b>Phone:</b> #Session.workphone#<br><br>
<b>Fax:</b> #Session.fax#<br><br>
<b>Email:</b> #Session.email#<br><br>
<b>Job Type:</b> #SESSION.jobFunction#<br><br>
<b>Status:</b> #Session.status#<br><br>
<b>Registrant Meals:</b> #Session.CustMeals#<br><br>
<b>Guests:</b> #Session.guests#<br><br>
<b>Guest Total:</b> #Session.guestsTotal#<br><br>
<b>Guest Names:</b> #Session.guestsName#<br><br>
<b>Guest Meals:</b> #Session.GuestMeals#<br><br>
</Td></tr><!--- </cfoutput> ---></table>



<cfparam name="form.regisAmt" default="200">
<cfset TotalSGuests = (TotalSunday * 40)>
<cfset TotalMGuests = (TotalMonday * 40)>
<cfset TotalTNumber = (TotalTour* 50)>

<!--- <cfset session.itemTotal = (session.price* session.qty)> --->

<cfif IsDefined("FORM.regisAmt")>
      <!--- <cfoutput> --->
      <cfif guestsTotal IS 0>
            <cfset regisAmt = 200>
      <cfelse>
            <cfset regisAmt = 200 + TotalSGuests + TotalMGuests + TotalTNumber>
      </cfif>
      <table cellpadding="2" cellspacing="2">      <tr><td class="text">      
      The following registration amount:<br><br>
            <span class="boldtext"><u>Registration Total</u></span><br>
      Registration Total: #DOLLARFORMAT(regisAmt)#<br>
      </td></tr></table>            
      <!--- </cfoutput> --->
</cfif>

      
<form action="conventionRegUpdate.cfm" method="post">
      <input type="hidden" name="mode" value="edit">
      <input type="submit" value="Go Back & Edit">
</form>
            
            
<!---       <cfoutput> --->
            <form action="https://www.paypal.com/cgi-bin/webscr" method="post">      
                  <input type="hidden" name="item_name" value="Senior Housing Conference- October 2004">
                  <input type="hidden" name="cmd" value="_ext-enter">
                  <input type="hidden" name="redirect_cmd" value="_xclick">
                  <input type="hidden" name="business" value="website@bnaibrith.org">
                  <input type="hidden" name="amount" value="#DOLLARFORMAT(regisAmt)#">
                  <input type="hidden" name="first_name" value="#SESSION.fname#">
                  <input type="hidden" name="last_name" value="#SESSION.lname#">
                  <input type="hidden" name="address_street" value="#SESSION.stno#">
                  <input type="hidden" name="address_city" value="#SESSION.city#">
                  <input type="hidden" name="address_state" value="#SESSION.state#">
                  <input type="hidden" name="address_zip" value="#SESSION.zip#">
                  <input type="hidden" name="payer_email" value="#SESSION.email#">
                  <input type="hidden" name="no_note" value="1">
                  <input type="hidden" name="currency_code" value="USD">
                  <input type="hidden" name="tax" value="0">
                  <input type="hidden" name="return" value="http://216.119.115.20/sservices/successReg.cfm">
                  <input type="hidden" name="notify_url" value="http://216.119.115.20/sservices/ipn.cfm">                  
<input type="submit" value="Confirm">
</form>            
</cfoutput>

------------------------------------------------------------------------------------------
conventionRegUpdate.cfm (where the session variables are recalled)

<cfoutput>
<table cellpadding="2" cellspacing="2" border="0"><tr><td class="heading4">Senior Housing Conference<br><br><span class="iboldtext">October 15-18, 2004<br><br></span></td></tr>
<tr><td>
      <form action="confirmReg.cfm" method="post">
<table cellpadding="2" cellspacing="2" border="0">
      <tr><td class="boldtext">Registrant's Information<br></td></tr>
      <tr>
            <td colspan="2">
                  <table>
                        <tr>
                              <td>
                                    <table><tr>
                        <td class="boldtext">First Name: </td>
                        <td class="text">
                        <input type="text" name="fname" value="#SESSION.fname#">
                        </td>
                        
                        <td class="boldtext">Last  Name:</td>
                        <td class="text">
                        <input type="text" size="20" name="lname" value="#SESSION.lname#"></td>
                        </tr></table>
                              </td></tr>
                              
                              <tr>                              
                              <td>
                                    <table><tr>
                        <td class="boldtext">Address 1:</td>
                        <td class="text"><input type="text" size="20" name="stno" value="#SESSION.stno#"></td>
                                    <td class="boldtext">Address 2</td>
                        <td class="text"><input type="text" size="20" name="stno2" value="#SESSION.stno2#"></td>
                        </tr></table>
                              </td>
                              </tr>
                              
                              
                              <tr>                              
                                    <td>
                                    <table><tr>
                        <td class="boldtext">City:</td>
                        <td class="text"><input type="text" size="20" name="city" value="#SESSION.city#"></td>
                                    <td class="boldtext">State</td>
                        <td class="text"><select name="State">
            <option selected>#SESSION.State#</option>
      <option value="AL">Alabama
    <option value="AK">Alaska
    <option value="AZ">Arizona
    <option value="AR">Arkansas
    <option value="CA">California
    <option value="CO">Colorado
    <option value="CT">Connecticut
      <option value="DE">Delaware
      <option value="DC">District of Columbia    
    <option value="FL">Florida
    <option value="GA">Georgia
    <option value="HI">Hawaii
    <option value="ID">Idaho
    <option value="IL">Illinois
    <option value="IN">Indiana
    <option value="IA">Iowa
    <option value="KS">Kansas
    <option value="KY">Kentucky
    <option value="LA">Louisiana
    <option value="ME">Maine
    <option value="MD">Maryland
    <option value="MA">Massachusetts
    <option value="MI">Michigan
    <option value="MN">Minnesota
    <option value="MS">Mississippi
    <option value="MO">Missouri
    <option value="MT">Montana
    <option value="NE">Nebraska
    <option value="NV">Nevada
    <option value="NH">New Hampshire
    <option value="NJ">New Jersey
    <option value="NM">New Mexico
    <option value="NY">New York
    <option value="NC">North Carolina
    <option value="ND">North Dakota
    <option value="OH">Ohio
    <option value="OK">Oklahoma
    <option value="OR">Oregon
    <option value="PA">Pennsylvania
    <option value="RI">Rhode Island
    <option value="SC">South Carolina
    <option value="SD">South Dakota
    <option value="TN">Tennessee
    <option value="TX">Texas
    <option value="UT">Utah
    <option value="VT">Vermont
    <option value="VA">Virginia
    <option value="WA">Washington
    <option value="WV">West Virginia
    <option value="WI">Wisconsin
    <option value="WY">Wyoming
</select></td>
                        <td class="boldtext">Zip</td>
                        <td class="text"><input type="text" size="10" name="zip" value="#SESSION.zip#"></td>
                        </tr></table>
                              </td>                              
                        </tr>
                        
                        <tr>                              
                              <td>
                                    <table><tr>
                        <td class="boldtext">Phone:</td>
                        <td class="text"><input type="text" size="10" name="workphone" value="#Session.workphone#"></td>
                                    <td class="boldtext">Fax</td>
                        <td class="text"><input type="text" size="10" name="fax" value="#Session.fax#"></td>
                        </tr></table>
                              </td>
                              </tr>
                              
                        <tr>                              
                              <td><table><tr><td class="boldtext">Email:</td><td class="text"><br>
                              <input type="text" size="50" name="email" value="#Session.email#"></td></tr></table>
                              </td>
                              </tr>                                                      
                        <tr>                              
                              <td>
                                    <table><tr>
                        <td class="boldtext">Please select:</td></tr><tr>
                        <td class="text">I am a management professional:</td>
                        <td class="text"><input type="checkbox" name="jobFunction" value="Management Professional"></td></tr><tr><td class="text">I am a volunteer:</td>
                        <td class="text"><input type="checkbox" name="jobFunction" value="Volunteer"></td></tr><tr><td class="text">I am a board member:</td>
                        <td class="text"><input type="checkbox" name="jobFunction" value="Board Member"></td></tr></table></td>
                              </tr>                              
                        <tr>                              
                              <td>
                                    <table><tr>
                        <td class="boldtext">Current Office:</td>
                        <td class="text"><input type="text" size="20" name="status" value="#SESSION.status#"></td>                              
                        </tr></table>
                              </td>
                              </tr>
                              
                                                            
                        <tr>                              
                              <td>
                                    <table><tr>
                        <td class="boldtext">Will you have guests?</td>
                        <td class="text">
                        <select name="guests">
                        <option selected>#SESSION.guests#</option>
                        <option value="Y">Yes</option>
                        <option value="N">No</option></select></td>
                        <td class="boldtext">Number of Guests:<br><span class="text">(Please    select 0 if none)</span></td>
                        <td class="text"><select name="guestsTotal">
                        <option selected>#SESSION.guestsTotal#</option>
                        <option value="0">0</option><option value="1">1</option>
                        <option value="2">2</option><option value="3">3</option>
                        </select></td>                        
                        </tr></table>
                              </td>
                              </tr>
                              
                              <tr>                              
                              <td>
                                    <table><tr>
                        <td class="boldtext">Guest Names:<br>
                        <span class="text">Please enter the names as they should be read on the badge.</span></td>
                        <td class="text"><textarea name="guestsName" cols="20" rows="5">#Session.guestsName#</textarea></td></tr></table></td></tr>
                        <tr><td class="boldtext"><hr width="100%"><br></td></tr>
                        
                              <tr><td class="boldtext">Registration Costs<br></td></tr>
                              
                              <tr><td class="text">Conference participants, cost is <b>$200</b>.  There is no registration fee for guests.  Guests must purchase tickets for meal sessions. <br></td></tr>
                              
                        <tr>                              
                              <td>
                                    <table><tr>
                        <td class="boldtext" colspan="2">Conference Registrant</td>
                        </tr><tr><td class="text">Please select your main course for Saturday's banquet:</td><td class="text"><select name="CustMeals">
                        <option selected>#Session.CustMeals#</option>
                        <option value="GC">Grilled Breast of Chicken Entree (GC)</option>
                        <option value="GF">Grilled Fish Entree (GF)</option>
                        <option value="VE">Vegetarian (VE)</option>
                        </select></td></tr></table>
                              </td>
                        </tr>
                        
                        <tr>                              
                              <td>
                                    <table><tr>
                        <td class="boldtext" colspan="2">Guests Only:</td>
                        </tr><tr><td class="text">Please select your main course for Saturday's banquet:</td><td class="text"><select name="GuestMeals">
                        <option selected>#Session.GuestMeals#</option>
                        <option value="GC">Grilled Breast of Chicken Entree</option>
                        <option value="GF">Grilled Fish Entree</option>
                        <option value="VE">Vegetarian</option>
                        </select></td></tr></table>
                              </td>
                        </tr>
                        
                        <tr>                              
                              <td><!--- $40/meal/person --->
                              <!--- variables: TotalMonday, TotalSunday --->
                                    <table><tr><td class="text">Number of guests for Sunday's luncheon:</td><td class="text"><select name="TotalSunday">
                        <option selected>#Session.TotalSunday#</option>
                        <option value="0">0</option><option value="1">1</option>
                        <option value="2">2</option><option value="3">3</option>
                        </select></td>
                        <td class="text">Number of guests for Monday's luncheon:</td><td class="text"><select name="TotalMonday">
                        <option selected>#Session.TotalMonday#</option>
                        <option value="0">0</option><option value="1">1</option>
                        <option value="2">2</option><option value="3">3</option>
                        </select></td>                  
                        </tr></table>
                              </td>
                        </tr>
                        
                  <tr>                              
                              <td>
                                    <table><tr><!--- $50/person --->
                                    <!--- variables: TotalTour --->
                        <td class="boldtext" colspan="2">Optional Tour:</td><td class="text"><select name="TotalTour">
                        <option selected>#Session.TotalTour#</option>
                        <option value="0">0</option><option value="1">1</option>
                        <option value="2">2</option><option value="3">3</option>
                        </select></td></tr></table>
                              </td>
                        </tr>
                        
                        <tr><td class="boldtext">You will be taken to PayPal for secure payment.</td></tr>
                              
                        
                  </table>
            </td>
      </tr>
      
      <tr>
                        <td colspan="2" align="middle" class="text">
                              <input type="submit" value=">> Save Changes">
                        </td>                                    
                  </tr>            
</table>
</form>
</cfoutput>
So far I havne't found any problems with the code.  I cut out most of the extra fields to take a look, but haven't found anything.

One thing I have noticed is the the inconsistants of CFSET you use:
<cfset #Session....# = Form.....>
<cfset #SESSION....# = Form.....>
<cfset SESSION.... = Form.....>
I don't know if the CAPS, and the '#' matter to much, I know it does when you clear out the sessions.

Since I am not an expert I provide as much help as I can.

Also are you sure your using the same page?  Check your directories if you have pages named the same, like one on development, and another on your pc, or production.  The reason I asked this is  because of the error:

An error occurred while evaluating the expression:

 #SESSION.jobFunction#=Form.jobFunction

Error near line 34, column 8.

This portion of your code should NOT give this error

<cfif isDefined('form.jobFunction') and form.jobFunction neq "">
   <cfset session.jobFunction=#form.jobFunction#>
<cfelse>
   <cfset session.jobFunction='Not Provided'>
</cfif>

synergeticsoul
here is my little sample pages I used to take a look at your problem.This may give you some insight on what is going on.

Test1.cfm
---------------------------------------
<html>
<head>
      <title>Untitled</title>
</head>

<body>
<FORM ACTION="test.cfm" METHOD="post">
      <INPUT TYPE="text" NAME="fname" VALUE="">
      <INPUT TYPE="checkbox" NAME="jobFunction" VALUE="1">
      <INPUT TYPE="checkbox" NAME="jobFunction" VALUE="2">
      <INPUT TYPE="checkbox" NAME="jobFunction" VALUE="3">
      <INPUT TYPE="submit" NAME="Submit" VALUE="Submit">
</FORM>


</body>
</html>

test.cfm
---------------------------------
<html>
<head>
      <title>Untitled</title>
</head>

<body>
<!----------GET ALL FORM VARIABLES------------->
<cfset #Session.fname# = FORM.fname>
<cfif isDefined('form.jobFunction') and form.jobFunction neq "">
   <cfset session.jobFunction=#form.jobFunction#>
<cfelse>
   <cfset session.jobFunction='Not Provided'>
</cfif>
<!--- Form variables --->
<table cellpadding="2" cellspacing="2" border="0">
<tr>
      <td class="heading4">Registration Confirmation- Contd. <br><br></td>
</tr>
<tr>
      <td class="boldtext">You entered the following:</td>
</tr>
<cfoutput>
<tr>
      <Td class="text"><b>First Name:</b> #Session.fname#<br><br></td>
</tr>
</table>
<form action="test_add.cfm" method="post">
     <input type="hidden" name="mode" value="edit">
     <input type="submit" value="Go Back & Edit">
</form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">    
      <input type="hidden" name="first_name" value="#SESSION.fname#">
                <input type="submit" value="Confirm">
</form>          
</cfoutput>
<CFDUMP VAR="#Session#">

</body>
</html>

test_add.cfm
-------------------------------------
<html>
<head>
      <title>Untitled</title>
</head>

<body>
<cfoutput>
<table cellpadding="2" cellspacing="2" border="0"><tr><td class="heading4">Senior Housing Conference<br><br><span class="iboldtext">October 15-18, 2004<br><br></span></td></tr>
<tr>
                <td>
            <form action="confirmReg.cfm" method="post">
            <table cellpadding="2" cellspacing="2" border="0">
            <tr>
            <td class="boldtext">Registrant's Information<br></td></tr>
            <tr>
                  <td colspan="2">
                              <table>
                              <tr>
                                    <td class="boldtext">First Name: </td>
                                    <td class="text"><input type="text" name="fname" value="#SESSION.fname#"></td>
                              </tr>
                              </table>
                  </td>
            </tr>
            <tr>
                  <td colspan="2" align="middle" class="text"><input type="submit" value=">> Save Changes"></td>                              
            </tr>          
            </table>
            </form>
      </td>                              
</tr>          
</table>
</cfoutput>


</body>
</html>

I hope this helps you, or someone to help solve your problem.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok only one ? left

in your appliication.cfm file:
<CFAPPLICATION NAME="Cookies" SessionManagement="Yes" setDomainCookies="Yes" setClientCookies="Yes" sessiontimeout="#CreateTimeSpan(0,0,30,0)#">

do u have sessionManagement as " yes"  or " no" ...
because by default it is " no"

just check this part out and set it to yes if its not defined....

Regards
Hart
ThanK You ALL!!!!!!

I deleted all duplicates of the <cfapplication>.  I check how I had my form organized, with the

a) <cfset SESSION.Whatever=Form.Whatever>

b) Finally my <form> tag was not arranged properly.  Once I fixed that and #1 and #2 above, the user can now make successful edits.

THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
glad you found my input helpful

thanks for the points