Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about shopping carts

Status
Not open for further replies.

csphard

Programmer
Apr 5, 2002
194
0
0
US
I am learning to build a shopping cart
I see carts where the have a add to cart image
and when they click that it only sends the text field
value associated to that image.

When you click the image all my text fields are passed.

How do I associate a text field with a submit button
without creating forms for each.

example of what I am trying to accomplish is the following.


Even though there are many textfields with a quantity only the
quantity associated with the add to cart button gets sent.

how is this accomplished.

My example

<?php

include("basket.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Literature Request Form</title>
</head>

<body style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">
<form action="mybasket.php" method="get">
<a href="print_basket.php">test</a>

<table cellspacing="10" style="margin: auto; width: 450px;">
<tr>
<td colspan="2">
<?php

echo "Items In Your Basket: ".array_sum($basket);

?>
<br />
<a href="mailform.php">Proceed to Checkout</a>
</td>
</tr>
<tr>
<td valign="top">
<img alt="Penguins" src="penguins.jpg" width="125" />
</td>
<td valign="top">
<p><strong>Penguins: A Conservation Guide</strong><br />
<br />
Our Penguins conservation guide is free and tells you all you need to know about
Penguins in the wild and in captivity.<br />
<br />
<a href="orderform.php?add=Penguins">Add to Basket</a>
<input type="text" name="penquins" id="textfield" value="1" />
<input type="image" src="cart_btn_add.gif" name="image" width="90" height="20">
</p>
<p>&nbsp; </p></td>
</tr>
<tr>
<td valign="top">
<img alt="Tamarins" src="tamarins.jpg" width="125"/>
</td>
<td valign="top">
<strong>Tamarins: A Conservation Guide</strong><br /><br />
Our Tamarins conservation guide is free and tells you all you need to know about
Tamarins in the wild and in captivity.<br /><br />
<a href="orderform.php?add=Tamarins">Add to Basket</a>
<input type="text" name="tamarins" id="textfield" value="1" />
<input type="image" src="cart_btn_add.gif" name="image" width="90" height="20">

</td>
</tr>
<tr>
<td valign="top">
<img alt="Tortoises" src="tortoises.jpg" width="125"/>
</td>
<td valign="top">
<strong>Tortoises: A Conservation Guide</strong><br /><br />
Our Tortoises conservation guide is free and tells you all you need to know about
Tortoises in the wild and in captivity.<br /><br />
<a href="orderform.php?add=Tortoises">Add to Basket</a>
</td>
</tr>
<tr>
<td valign="top">
<img alt="Monkeys" src="monkeys.jpg" width="125">
</td>
<td valign="top">
<strong>Monkeys: A Conservation Guide</strong><br /><br />
Our Monkeys conservation guide is free and tells you all you need to know about
Monkeys in the wild and in captivity.<br /><br />
<a href="orderform.php?add=Monkeys">Add to Basket</a>
</td>
</tr>
</table>
<?php
print_r($basket);
?>
</form>
</body>
</html>

howard
 
How do I associate a text field with a submit button
without creating forms for each.

using javascript? but since this is a php forum what is wrong with creating a form for each line item.

i have a work in progress shopping cart I am building here: you will note that each add to cart image is wrapped in a form. however there is some javascript that interrupts the page refresh and using ajax, sends the necessary data to the server and handles the response. the residual form tags are there to protect against broken javascript and/or instances where the user has turned off js. in that case you still want the form to perform.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top