Despabilando la MonoNeurona::Internet es de todos [Inicio] [Regresar]
WWW \ Array en formulario de PHP
WWW
Array en formulario de PHP

Este artículo ha sido consultado en 554 ocasiones.

En muchas ocasiones es necesario enviar un array (o arreglo) a través de un formulario HTML, ya sea para modificar o borrar muchos renglones de la tabla SQL. Esto es muy sencillo de hacer con PHP, basta colocar el mismo nombre con corchetes (postre[]) a una serie de elementos con valores diferentes:


1:<html>
2:<head>
3: <title>Array en Forma :: PHP</title>
4:<head>
5:<body>
6:
7:<br />
8:<b>Selecciona tus postres favoritos:</b><br /><br />
9:<form method="post" action="= $_SERVER['PHP_SELF'] ?>">
10:<input name="postre[]" type="checkbox" value="Helado de Vainilla">Helado de vanilla<br />
11:<input name="postre[]" type="checkbox" value="Pastel de Chocolate">Pastel de Chocolate<br />
12:<input name="postre[]" type="checkbox" value="Pay de elote">Pay de elote<br />
13:<input name="postre[]" type="checkbox" value="Bubulubu">Bubulubu<br />
14:<input name="postre[]" type="checkbox" value="Duraznos en almibar">Duraznos en almibar<br />
15:<input name="postre[]" type="checkbox" value="Fresas con crema">Fresas con crema<br />
16:<input name="send" type="submit" id="send" value="Enviar!">
17:</form>
18:
19:
20:if (isset($_POST['postre']))
21:{
22: $postre = $_POST['postre'];
23: $n = count($postre);
24: $i = 0;
25:
26: echo "Tus postres favoritos son: \r\n" .
27: "<ol>";
28: while ($i < $n)
29: {
30: echo "<li>{$postre[$i]}</li> \r\n";
31: $i++;
32: }
33: echo "</ol>";
34:}
35:?>
36:
37:</body>
38:</html>

Última actualización: 2007-04-29 10:56:59-05



ir arriba
The Queen is here Mozilla Firefox The Best DataBase CakePHP Framework CSS GNU Hacker