1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Shopping cart - Submitting multiple items in one form

Discussion in 'HTML, Graphics & Programming' started by soul_child, 20 Apr 2010.

  1. soul_child


    Joined: 21 Sep 2007

    Posts: 28


    A client has asked that i implement the equivalent of a bulk order form which consists of multiple items, each with an option to enter a description and quantity so the table.

    i have attached a screen shot to illustrate how data s captured. For each row of items i have a hidden input which contains the value of the product id.


    When a customer enters details for each product i need to store this in a session variable so that i may later add the order details to the database on the order confirmation page.

    My only problem is that im not to sure how to store the form variables in a session in which i can later loop over and then add to the DB. can any body please advise. I'll provide any information on request. Thank you.
    Last edited: 20 Apr 2010
  2. Engram


    Joined: 6 Jul 2004

    Posts: 979

    Location: England

    Can't see a screenshot.
  3. soul_child


    Joined: 21 Sep 2007

    Posts: 28

    oops ...edited!
  4. Pho


    Joined: 18 Oct 2002

    Posts: 9,206

    Location: Derbyshire

    You could create a class, i.e. :

    (random psuedo code)
    class order_product {
    So for each 'line' you create an instance of the class and save it into an array for their shopping cart, and then into the session. Or you could use a database.
  5. soul_child


    Joined: 21 Sep 2007

    Posts: 28

    is that akin to storing objects in a session variable? I have very basic php knowledge and im using this as a platform to improve this.However if you dont mind could you please expand on your code?

    Also you suggestion to use a database to store the session. does that mean that i would then have to write a scheduled script that removes abandoned carts? e.g after 60 mins?
  6. lokkers

    Wise Guy

    Joined: 1 Mar 2004

    Posts: 1,930

    Location: Farnborough, Hants

    As Pho suggested, each line in your diagram would represent one object (say OrderProduct), and the whole lot would be in one collection (OrderProductList for example). This list would go into session state, and you'd recall it when you are ready to squirt it into your db.

    Off the top of my head (in C#):

    //Product Class
    public class Product
          public string Name {get; set; }
          public int Quantity {get; set; }
    //create a product collection
    List<Product> myListForSessionState = new List<Product>();
    //create a product object
    Product prod = new Product();
    /assign some values
    prod.Name = "Leeks";
    prod.Quantity = 5;
    //add it to the collection
    //finally, add the collection to session state
    Session.Add("ProductList", myListForSessionState);
    Last edited: 20 Apr 2010
  7. suarve


    Joined: 8 Oct 2005

    Posts: 4,190

    Location: Midlands, UK

    Name the inoput boxes as an array E.g. product[]. You can loop through them.

    If you're using PHP, I have a example someone posted on this forum a while ago.