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

2006-05-18 Thread Andras Kende

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

Andras,

input type=hidden name=item[] value=applesApples 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



Re: [PHP] Add Multiple Items, Qty to Cart from html form

2006-05-18 Thread Jochem Maas

Wolf wrote:

Andras,

input type=hidden name=item[] value=applesApples input type=text
name=qty[] value=0 input type=text name=price[] value=0


a useful addition can be to use the item id in the 'key' of the input names
(and always quoting your element attributes is highly recommended):

input type=hidden name=item[18] value=applesApples input type=text
name=qty[18] value=0 input type=text name=price[18] value=0

that way you can easily fish out the quantities when looping the
selected items (example mostly ignores input cleaning/validation for brevity 
etc -
but you shouldn't :-) e.g. get anal about make sure things are actually 
integers when
that is what you require, etc):

foreach ($_POST['item'] as $itemId = $itemName) {
if (isset($_POST['item'][$itemId])  ($qty = 
intval($_POST['item'][$itemId])) {
addItem($itemId, $qty);
}
}

another thing that popped into my head was the fact that it's
probably not intended behaviour to allow the customer to determine the
unit price of an item -
but if it is then can I have 10 Plasma Screens at 1 dollar a pop? ;-)



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





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



Re: [PHP] Add Multiple Items, Qty to Cart from html form

2006-05-18 Thread Wolf
SNIP
 a useful addition can be to use the item id in the 'key' of the input names
 (and always quoting your element attributes is highly recommended):
Yes, when I generate my cart I use the itemID as a key field (since the
ID stayed the same but the # in the database could change).

And ALWAYS quote your inputs in HTML.  It makes for a lot less
headaches.  But then I wasn't sending COMPLETE code, just enough to get
him on the right track. :)

We should all be using the guidelines within http://phpsec.org/ to keep
good coding practices.


SNIP
 another thing that popped into my head was the fact that it's
 probably not intended behaviour to allow the customer to determine the
 unit price of an item -
 but if it is then can I have 10 Plasma Screens at 1 dollar a pop? ;-)
I too need the screens at 1 dollar (52 Wide-screen format please) as
well as the 6-person hot-tub and deck combo.

Wolf

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



Re: [PHP] Add Multiple Items, Qty to Cart from html form

2006-05-18 Thread Richard Lynch
On Wed, May 17, 2006 6:59 pm, Andras Kende wrote:
 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: [__]

apple : qty: input name=quantity[apple] / price: input
name=price[apple] /br /
orange : qty: input name=quantity[orange] / price: input
name=price[orange] /br /

 Add Items to Cart

 I could add multiple items with checkboxes but without selecting
 quantity
 and price..


if (isset($_POST['quantity'])){
  var_dump($_POST['quantity']);
  var_dump($_POST['price']);
}

  if (isset($_POST['itemschecked'])) {
  foreach($_POST['itemschecked'] as $itemschecked = $checkeditems ){
  AddItem($checkeditems, 1);
  }

 Any help is appreciated..

 Thanks,

 Andras

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




-- 
Like Music?
http://l-i-e.com/artists.htm

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



[PHP] Add Multiple Items, Qty to Cart from html form

2006-05-17 Thread Andras Kende

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 


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



Re: [PHP] Add Multiple Items, Qty to Cart from html form

2006-05-17 Thread Wolf
Andras,

input type=hidden name=item[] value=applesApples 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

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