Cita:
Iniciado por sumolari
No es necesario que uses Javascript, como ya ha dicho Caricatos, puedes leer el valor del campo cantidad usando $_POST['cantidad'], en lugar de $_GET['cantidad'].
Dejando de lado el tema de la cantidad, creo que es muy inseguro enviar el precio del producto a través del formulario. El precio debería estar almacenado en una base de datos o en un archivo externo, porque el código HTML puede ser editado usando WebDeveloper Toolbar sin mucha dificultad, y podría ocasionar muchos problemas de seguridad.
Si tenes razón pero una vez finalizada la elección del/los productos cuando completan el formulario este se envía a mi email y yo antes de enviárselo al comprador para que este lo confirme me fijo que todos los datos estén bien, y si no, los modifico yo como deberían ir y ahí si le envío el email al comprador...
EDIT: Volviendo al tema:
Vamos a hacer una cosa para hacerlo más simple yo les dejo el codigo y ustedes me dice que debería modificar para que funcione de esa manera:
"
pagina_del_producto.php"
Cita: <?
include("lib_carrito.php");
?>
<form action="agregar_producto.php?id=1&nombre=Nombre+De l+Producto&cantidad=<? $_POST['cantidad'] ?>&precio=125$" method="post" name="form1">
<table width="164" border="0" align="left">
<tr>
<td width="61">Cantidad:</td>
<td width="29"><input name="cantidad" type="text" id="cantidad" value="1" size="4" maxlength="3"></td>
<td width="96"><input name="submit" type="submit" id="submit" value="Agregar"></td>
</tr>
</table>
</form>
"
agregar_producto.php"
Cita: <?
include("lib_carrito.php");
$_SESSION["ocarrito"]->introduce_producto($_GET["id"], $_GET["nombre"], $_GET["precio"], $_GET["cantidad"]);
?>
"
lib_carrito.php"
Cita: <?
class carrito {
var $num_productos;
var $array_id_prod;
var $array_nombre_prod;
var $array_precio_prod;
var $cantidad;
function carrito () {
$this->num_productos=0;
}
function introduce_producto($id_prod,$nombre_prod,$precio_p rod,$cantidad){
$this->array_id_prod[$this->num_productos]=$id_prod;
$this->array_nombre_prod[$this->num_productos]=$nombre_prod;
$this->array_precio_prod[$this->num_productos]=$precio_prod;
$this->cantidad[$this->num_productos]=$cantidad;
$this->num_productos++;
}
function imprime_carrito(){
$suma = 0;
$articulos = 0;
echo '<table width="487" border="0" cellspacing="0" cellpadding="0" align="center">
<tr bgcolor="#333333" class="tit">
<td width="124">Producto</td>
<td width="121">Precio</td>
<td width="128" align="center"><div align="left">Unidades</div></td>
<td width="70" align="center"><div align="left">Borrar</td>
</tr>';
for ($i=0;$i<$this->num_productos;$i++){
if($this->array_id_prod[$i]!=0){
echo '<tr>';
echo "<td>" . $this->array_nombre_prod[$i] . "</td>";
echo "<td>" . $this->array_precio_prod[$i] . "</td>";
echo "<td>" . $this->cantidad[$i] . "</td>";
echo "<td><a href='eliminar_producto.php?linea=$i'><img src='trash.gif' width='12' height='14' border='0'></a></td>";
echo '</tr>';
$suma += $this->array_precio_prod[$i] * $this->cantidad[$i];
$articulos += $this->cantidad[$i];
}
}
echo '</table>';
if($articulos==0){
echo "No hay productos";
}
else{
echo "Cantidad de articulos: $articulos |
Total: $suma$";
}
}
function elimina_producto($linea){
$this->array_id_prod[$linea]=0;
}
}
session_start();
if (!isset($_SESSION["ocarrito"])){
$_SESSION["ocarrito"] = new carrito();
}
?>