Per un lavoro di e-commerce devo spuntare attraverso l'utilizzo delle checkbox i prodotti che al cliente interessa acquistare. Utilizzando un file di testo, tengo al suo interno i valori che visualizzo attraverso una tabella in un modulo con un modulo form. Volevo sapere se è possibile assegnare un value alla checkbox in maniere che quando la richiamo (POST) nel php non debba andare a recuperare di nuovo i dati dal file di testo...
Grazie in anticipo per il supporto!
Codice PHP:
<html>
<head> <title> Sezione alimentari </title>
</head>
<body align="center">
<?php
$i=0;
$array=$_POST['p$i'];
echo"$array
";
$nomefile="alimenti.txt";
$fp=fopen($nomefile,"r");
$stringa=file($nomefile);
$somma=89;
for($i=0; $i<9; $i++)
{
$array[$i]=$_POST['p$i'];
echo"$array[$i]
";
$somma+=$array[$i];
}
fclose($fp);
?>
<form action="#" method="POST">
<?php
$nomefile="alimenti.txt";
$fp=fopen($nomefile,"r");
$stringa=file($nomefile);
echo"<table border='2' align='center' width='550' height='250'>";
for($i=0;$i<count($stringa);$i++)
{
$stringa_div=explode("**",$stringa[$i]);
echo"<tr align='center'>";
for($j=0;$j<count($stringa_div);$j++)
{
echo"<td> $stringa_div[$j] </td>";
}
if($i>0)
echo"<td><input type='checkbox' name='p$i' value='1' > </td>";
echo"</tr>";
}
echo"</table>";
fclose($fp);
?>
<input type="text" name="risu" size="6" maxlength="6" value="<?php echo "$somma"; ?>">Risultato
<input type="submit" value="Calcola">
</form>
</body>
</html>