RE: Add Multiple Items, Qty to Cart from html form

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----Original Message-----
From: Wolf [mailto:LoneWolf@xxxxxxxxx] 
Sent: Wednesday, May 17, 2006 9:47 PM
To: Andras Kende
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  Add Multiple Items, Qty to Cart from html form

Andras,

<input type=hidden name=item[] value=apples>Apples <input type=text
name=qty[] value=0> <input type=text name=price[] value=0>

Will get you where you need to go on the HTML side of things, then on
the back end you need to process each array.  By setting a default value
of 0 for the qty, you force users to change the values, but you also
keep your arrays intact and easier (IMHO) to deal with.

Wolf

Andras Kende wrote:
> Hello,
> 
> I trying to add multiple items to a shopping cart with selectable
> quantity and price form text field like..
> 
> apple   : qty: [__]  price: [__]
> orange : qty: [__]  price: [__]
> <Add Items to Cart>
> 
> 
> I could add multiple items with checkboxes but without selecting
> quantity and price..
> 
> if (isset($_POST['itemschecked'])) {
> foreach($_POST['itemschecked'] as $itemschecked => $checkeditems ){
> AddItem($checkeditems, 1);
> }
> 
> Any help is appreciated..
> 
> Thanks,
> 
> Andras


Wolf,

The tip worked great !! All working as expected now...

	$listvals=$_POST['item'];
	$n=count($listvals);
	$i=0;
	while ( $i < $n )  {
	if ($qty[$i] > 0) {
	AddItem($item[$i], $qty[$i]);
	UpdatePrice($item[$i], $price[$i]);
	}
	$i++;
	}

Thanks,

Andras Kende
http://www.kende.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux