Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Variables for Shopping Cart

Status
Not open for further replies.

junkjones

Programmer
Jul 14, 2000
52
GB
Hi Guys -

I'm trying to setup an events registration form. I've got everything done (selecting the event from the list, reading about the event, entering how many people are going to be attending, filling out the form, adding that info to a database, and emailing the coordinator). Here's my problem: I want to set up a shopping cart kind of system so that the user can enter how many people are going to attend an event, and then go back and enter more events to their 'cart', before entering their info and checking out. Standard shopping cart stuff right? I have been playing around with session variables... here is what I have been doing:

<!-- form to enter how many people they are registering for the event on this page -->

<FORM ACTION=&quot;registration.cfm?ID=#ID#&quot; METHOD=&quot;Post&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;event&quot; VALUE=&quot;#event#&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;price_member&quot; VALUE=&quot;#price_member#&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;price_nonmember&quot; VALUE=&quot;#price_nonmember#&quot;>
<table border=&quot;1&quot; bordercolor=&quot;003366&quot; cellpadding=&quot;3&quot; cellspacing=&quot;0&quot;>
<TR><TD colspan=2 bgcolor=&quot;003366&quot;><p class=&quot;white&quot;><b>Register for this Event</b></p></td></tr>
<TR><TD><p>Number of Members</p></td><TD><INPUT TYPE=&quot;text&quot; SIZE=2 NAME=&quot;members&quot;></td></tr>
<TR><TD><p>Number of Non-Members</p></td><TD><INPUT TYPE=&quot;text&quot; SIZE=2 NAME=&quot;nonmembers&quot;></td></tr>
<TR><TD colspan=2><INPUT TYPE=&quot;submit&quot; VALUE=&quot;Register!&quot;></td></tr></table>
</form>

Next I have the registration.cfm page which sets the following variables:

<cfset session.event=#form.event#>
<cfset session.price_member=#form.price_member#>
<cfset session.event=#form.price_nonmember#>

But if I try to add more events, they just write themselves over top of the exising session variables! How do I add more and more event registrations, and then how do I display them on the checkout page? I hope I make sense :)
 
One way is to use a list instead of a single variable. By changing this

<cfset session.event=#form.event#>
<cfset session.price_member=#form.price_member#>
<cfset session.event=#form.price_nonmember#>

to this,

<cfset session.event=listappend(session.event,#form.event#)>
<cfset session.price_member=listappend( session.price_member,#form.price_member#)>
<cfset session.event=listappend( session.event,#form.price_nonmember#)>

you will create a session variable that holds an entire list of events. You can then use the standard CF list functions to loop through and retrieve them (listlen,listgetat,listsetat,...).

Hope this helps,
GJ
 
Okay, I really really really tried to figure this out on my own, but to date I've only done simple stuff in CF, and I just can't figure this one out....

Here's the code I have now:

<cfset session.event=&quot;&quot;>
<cfset session.price_member=&quot;&quot;>
<cfset session.price_nonmember=&quot;&quot;>
<cfset session.eventday=&quot;&quot;>
<cfset session.event=listappend(session.event,#event#)>
<cfset session.price_member=listappend(session.price_member,#price_member#)>
<cfset session.event=listappend(session.event,#price_nonmember#)>
<cfset session.eventday=listappend(session.eventday,#eventday#)>

So how do I display a list of all the events they have selected? How do I add more and more events to this list if they go back and select a new event? I tried stuff with cfloop and stuff like that, but i have to enter a delimiter... how do i get these things seperated with commas? I'm really clueless here :D
 
This should output a list events they have signed up for.

<cfloop list=#session.event# index=&quot;x&quot;>
<cfoutput>#x#</cfoutput>
<p>
</cfloop>

This will add another event to their existing list.

<cfset session.event=listappend(session.event,#event#)>

When you use the list functions, they will automaticly handle the delimeters for you so you don't have to be concerned with the commas. I would suggest reading up on the list functions as I think this will give you ideas on how to work with your lists.

Hope this helps,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top