Hi all
I am working a on a shopping cart which needs to allow users to choose if they want to gift wrap an item or not before paying for it.
I have so far got the code below to update the 'giftwrap' value of my session array to '1' when the user ticks a checkbox to say 'yes, please gift wrap my item'. However, I am stuck as I need to be able to allow the user to un-tick the checkbox and update the session array to be '0'.
Can anyone help me out please and maybe alter my function below to allow this?
Webpage displaying the Basket has:
foreach ($_SESSION['cart'] as $k => $v) {
// find out if the session array key 'giftwrap' is set to 1 or 0...
if ($v['giftwrap'] == 0) {
$checkedvalue = "";
} else {
$checkedvalue = "checked";
}
// display the product data the user wishes to purchase and also display the gift wrap checkbox as such...
<input type=\"checkbox\" name=\"giftwrap[]\" value=\"$k\" $checkedvalue />
}
And the function i call once the page is posted is:
if ($_POST['somefield']) {
GiftWrapItem($_POST['giftwrap']);
}
function GiftWrapItem($selecteditems) {
foreach ($selecteditems as $productid) {
$_SESSION['cart'][$productid]['giftwrap'] = 1;
}
}
Your help will be greatly appreciated. I simply need to allow the session array to updated back to '0'.
Thankyou