Forum Moderators: coopster
Im looking at some oscommerce code here (php), not sure if this is a 100% php question though.
The form has 3 buttons: update cart, delete cart and checkout.
The update cart and delete cart are just input of type=image.
What is confusing me is how does the form know which button was clicked?
Code:
<form name="cart_quantity" action="https://www.example.com/shopping_cart.php/action/update_product" method="post">
<input type="image" src="includes/languages/english/images/buttons/button_update_cart.gif" border="0" alt="Update Cart" title=" Update Cart " name="update_cart">
<input type="image" src="includes/languages/english/images/buttons/button_empty_cart.gif" border="0" alt="Empty Cart" title=" Empty Cart " name="empty_cart" onclick="return confirmEmpty()">
<input type="image" src="includes/languages/english/images/buttons/button_checkout.gif" border="0" alt="Checkout" title=" Checkout " name="checkout">
Obviously the processing is going on the backend via PHP, but how does PHP know which button was clicked?
if (isset($_POST['update_cart']) ¦¦ isset($_POST['update_cart_x']))
{
// do something
}
if (isset($_POST['empty_cart']) ¦¦ isset($_POST['empty_cart_x']))
{
// do something
}
if (isset($_POST['checkout']) ¦¦ isset($_POST['checkout_x']))
{
// do something
}
For a better understanding and to see whats coming in on the post array, do the following:
echo '<pre>';
print_r($_POST);
echo '</pre>';
Its just an easy way of having multiple buttons.
dc