Click to See Complete Forum and Search --> : Add To Cart Button Problem
rbailer
01-25-2006, 09:35 PM
I have an add to cart button and for some reason when i try to make it a picture it doesnt work, but just a normal submit button works. It just returns me to the same page that Im on. (if it helps, the add to cart button is just referring back to the same page where I have the PHP set up so that if it detects the $addtocart variable, it will add the item to the cart and then forward itself to the next page)
Works
<input type='submit' name='addtocart' alt='Add to Cart' value='Add To Cart'>
Doesnt Work
<input type='image' src='https://www.paypal.com/en_US/i/btn/x-click-but22.gif' border='0' name='addtocart' alt='Add to Cart' >
NogDog
01-25-2006, 10:11 PM
Just a thought: maybe try using a hidden field to send the 'addtocart' post variable instead? (You shouldn't have to, but maybe there's either a PHP bug or a browser bug in sending/receiving the name from an image input?)
shimul
01-25-2006, 10:12 PM
at the code where u r adding product to cart , may be you are checking button's value. there is no such difference between submit button and image button on this perspective . however if u can send your php code where you are adding to cart. it will be better to find exact solution .
Best Regards
Stranger
chazzy
01-25-2006, 10:55 PM
just wondering, what browser did you test this on?
I remember hearing something about firefox not liking image submit buttons.
rbailer
01-25-2006, 10:57 PM
<?php
include('include/connect.php');
//direct the customer to the cart page
if ($addtocart)
{
//basically write item to the shopping cart then go to the next page
}
else
{
include('include/header.php');
include('include/template.php');
echo "
<form action=\"product.php\" method=\"post\">
//bunch of inputs to be written to the shopping cart
<input type='image' src='https://www.paypal.com/en_US/i/btn/x-click- but22.gif' border='0' name='addtocart' alt='Add to Cart' >
</form>
";
}
?>
bathurst_guy
01-26-2006, 02:26 AM
You need to also give the button a value, otherwise the form doesnt send the addtocart
<input type='image' src='https://www.paypal.com/en_US/i/btn/x-click- but22.gif' border='0' name='addtocart' alt='Add to Cart' value="Add" >
NogDog
01-26-2006, 07:06 AM
You need to also give the button a value, otherwise the form doesnt send the addtocart
<input type='image' src='https://www.paypal.com/en_US/i/btn/x-click- but22.gif' border='0' name='addtocart' alt='Add to Cart' value="Add" >
Good eye: I hadn't noticed that difference. Could likely be the culprit.
bokeh
01-26-2006, 07:59 AM
You need to also give the button a value, otherwise the form doesnt send the addtocart
<input type='image' src='https://www.paypal.com/en_US/i/btn/x-click- but22.gif' border='0' name='addtocart' alt='Add to Cart' value="Add" >A submit image does not need a value by default. If you had the following:<input type="image" src="./image.png" border="0" name="submit" alt="submit form"> You can test for it like this:if(@$_POST['submit_x'] or @$_POST['submit_y']){ This is because submit images also submit the selected coordinates. After all that was what they were designed for.
bathurst_guy
01-26-2006, 08:01 AM
Answered in your edit
bokeh
01-26-2006, 08:38 AM
Answered in your edit$_POST['submit'] (<image type="image" name="submit">) will exist only if there was a value attribute whereas the coordinates ($_POST['submit_x'] and $_POST['submit_y']) exist even if there is no value or value attribute. This is because the real use for <image type="image"> is a map where it is necessary to know the coordinates where the client clicked. With normal inputs (including type="submit") on the other hand the superglobal array key is even if there is no value atribute.
NogDog
01-26-2006, 10:13 AM
Might be worth looking into using the button element:
<button type="submit" name="submit" value="Add to Cart" id="submit">
<img src='https://www.paypal.com/en_US/i/btn/x-click-but22.gif' alt="Add to Cart">
</button>
CSS:
#submit {
border: none;
background-color: transparent;
margin: 0;
padding: 0;
}
dude_man_dude
02-27-2006, 11:35 PM
The solution is to reference the name of your submit button in your PHP code by appending an "_x" to the end of its name. For example, if your submit button is named "submit" you would reference it in your PHP code as follows :
if(isset($_POST['submit_x']))
You'll be able to sleep at night now.
Best regards,
The dude
SpectreReturns
02-28-2006, 12:41 AM
Just for reference, image input types return the co-ordinates on the image that you clicked.
chazzy
02-28-2006, 11:49 AM
I will never understand why people post solutions in threads that are a month old. And already solved.
dude_man_dude
02-28-2006, 04:28 PM
Just to annoy the h * * l outta peeps like u ;)
bathurst_guy
02-28-2006, 07:04 PM
I will never understand why people post solutions in threads that are a month old. And already solved.
It hasn't been marked as resolved so hows one to know if it is or not without checking it out