Forum Moderators: coopster

Message Too Old, No Replies

General online store functionality and layout.

         

TheSeoGuy

11:02 pm on Jul 27, 2004 (gmt 0)

10+ Year Member



I have written a few user interfaces for online stores and have always had one item purchasable on one page. I have never really had multiple items displayed on one page with each item having its own buy button. Can anyone give some tips as to an “easy” way to do this or to keep track of everything? For example, with multiple buy buttons, how do you determine which button the user clicked? I imagine there is no “easy” answer, but I thought I would ask if anyone had some tips or knew of any pitfalls to watch out for.

Thanks in advance.

Birdman

11:32 pm on Jul 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I imagine there is no “easy” answer

Actually, there is! Two even.

1: Use separate forms for each item and have a hidden field for the item id.

2: Use one form for all items and name your submit buttons accordingly.
<input type="submit" name="item-number_abc123" value="Buy Now!" />

In the form processing script, loop the POST until you get the item key and then grab the actual item id off of it.

<?
foreach ($_POST as $key => $val){
if (strpos("item-number", $key)){
$i = explode ("_", $key);
$item_number = $i[1];
}
}
?>

$item_number now contains the id of the item.