I have a shopping cart where users have added a list of documents for
purchase. I want to allow users to remove documents from the cart before
checkout. There are no quantities involved-- this is a "yes I want
$docID" or "no I don't" situation.
I thought the easiest way might be to have a checked checkbox before
each item (. . . name=checkbox value=true checked) with instructions to
uncheck the box and click on a "save changes" button to refresh the
cart. I've spent many hours trying to get this scheme to work. Before I
spend more time beating my head against the same 'ol wall, I thought I'd
ask those more knowledgeable if a checkbox is the best method of
achieving this. If so, this is the code I tried to use (the $save
variable is passed as a hidden form field, $cart is an array and a
registered session variable)
if($save)
{
if($checkbox != true)
unset($cart[$docID]);
else
$cart[$docID] = $$docID;
}
(I should say this is the latest version. I've tried lots of way, but
none have worked. I've tried "foreach" in lots of ways, but I may not
understand this construct properly. For example I've tried:
if($save)
{
foreach ($cart as $docID => $checkbox)
{
if($checkbox != true)
unset($cart[$docID]);
else
$cart[$docID] = $$docID;
}
)
If you can suggest code that works, that would be great, or at least
point me in the right direction if I'm on the wrong track with
checkboxes. If you haven't noticed already, I'm very, very new to PHP
and haven't quite got the hang of it yet. :=)
Thanks, Vicki
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php