Ver Mensaje Individual
  #7 (permalink)  
Antiguo 15/06/2010, 18:57
Dany_s
 
Fecha de Ingreso: diciembre-2009
Ubicación: Misiones
Mensajes: 867
Antigüedad: 14 años, 4 meses
Puntos: 65
Respuesta: Array desde formulario a php, input con el mismo nombre!

esto está mal $_POST[dni[$i]]; php seguro te tiró un error

el valor de $_POST['dni'] es un array asociativo con los valores de los campos, entonces accedes a ellos mediante el índice

$_POST['dni'][0], $_POST['dni'][1]...

podés verlo haciendo print_r($_POST['dni']); o para ver todos los campos que enviaste print_r($_POST);


entonces

Código HTML:
Ver original
  1. <form method="POST" action="">
  2.     <input type="text" name="dni[]" />
  3.     <input type="text" name="dni[]" />
  4.     <input type="text" name="dni[]" />
  5.     <input type="text" name="dni[]" />
  6.     <input type="text" name="dni[]" />
  7.     <input type="submit">
  8. </form>

Código PHP:
$valores $_POST['dni'];
for (
$i=0$icount($valores); $i++){
    echo 
$valores[$i]."<br />";
}
?> 
o
Código PHP:
Ver original
  1. <?php
  2. foreach ($_POST['dni'] as $value){
  3.     echo $value."<br />";
  4. }
  5. ?>