Jump to content

Dynamic text fields


Schlo_50

Recommended Posts

Hi all,

 

I have a shopping cart page that displays items added to it. Next to each product displayed is a quantity box which by default should be 1. (This website does what I want to achieve: http://www.romancart.com/cart.asp?storeid=19169&itemcode=4C6156&Add%20to%20Basket)

 

I would like for users to be able to type a quantity greater than 1 and press a update cart button to refresh the page and display the new quantities. Trouble is, im not sure what to do with the dynamic text fields 'quantity' and their values? I want to some how put the quantities into a session and then put them back into the text fields in the correct order but am a bit stuck.

 

I've condensed my code and have the following:

 

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="cart"> 
<?php

if(isset($_SESSION['sid'])){

if($_SESSION['quantity'][$i] != 1){
$updateQuantity[$i] = $_SESSION['quantity'][$i];
} else {
$updateQuantity[$i] = 1;
}

$sid = $_SESSION['sid'];

if(file_exists("admin/data/orders/$sid.txt") && count(file("admin/data/orders/$sid.txt")) > 0){
	$bcartfile = file("admin/data/orders/$sid.txt");
	print "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	print "<tr>";
	print "<td width=\"65%\" valign=\"top\"><img src=\"images/arrow.gif\"><strong>Quantity</strong></td>";
	print "</tr>";
	foreach($bcartfile as $bKey => $Val){
		$Data[$bKey] = explode("|", $Val);
		$item = $Data[$bKey][0];
		print "<tr>";
		print "<td width=\"35%\" valign=\"top\"><p align=\"left\">    <input name=\"quantity[]\" class=\"form\" type=\"text\" size=\"3\" maxlength=\"4\" value=\"".$updateQuantity[$i]."\" /></p></td>";		
		print "</tr>";
	}

} else {
	print "<i>Your cart is empty</i><hr><p align=\"right\">Total: £0.00</p>";  
}
}
?>
<input type="submit" name="Submit" value="Recalculate" />
</form>

 

Any help would be great!

Link to comment
https://forums.phpfreaks.com/topic/134511-dynamic-text-fields/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.