Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/03/2013, 02:55
xabut
 
Fecha de Ingreso: marzo-2013
Mensajes: 10
Antigüedad: 11 años, 1 mes
Puntos: 0
Recoger variables desde un formulario dinamco

Código:
<html> 
<head>
<title>Crear Campo de texto</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
 
icremento =0;
function crear(obj) {
  icremento++;
  
  field = document.getElementById('field'); 
 contenedor = document.createElement('div'); 
  contenedor.id = 'div'+icremento; 
  field.appendChild(contenedor); 
 
  boton = document.createElement('input'); 
  boton.type = 'text'; 
  boton.name = 'text'+'[]'; 
  contenedor.appendChild(boton); 
   
  boton = document.createElement('input'); 
  boton.type = 'button'; 
  boton.value = 'Borrar'; 
  boton.name = 'div'+icremento; 
  boton.onclick = function () {borrar(this.name)} //aqui llamamos a la funcion borrar
  contenedor.appendChild(boton); 
  return contenedor.id;
}
function borrar(obj) {//aqui la ejecutamos
  field = document.getElementById('field'); 
  field.removeChild(document.getElementById(obj)); 
}
</script>


</head>
<body>
<form name="form1" method="POST" action="validar5.php">
 
<fieldset id="field">
  <p>
  <input type="button" value="Crear caja de texto" onClick="crear(this)">
  <input name="send" type="submit" value="Enviar" onClick="enviar(this)" id="send">
  </p>
</fieldset>
</form>
Este es el código que uso y para leer las variables me recomendaron:

Código PHP:

<?php

echo "<pre>";
print_r($_POST);
echo 
"</pre>";

$_POST=array();
 
 
$camp1=$_POST[0];
 
 echo 
"$camp1";

?>

Y obtengo esto como resultado:


Array
(
[send] => Enviar
[text] => Array
(
[0] => campo1
[1] => campo2
[2] => campo3
)

)


Intento leer utillizando :

Código PHP:

$camp1
=$_POST[0];
 
 echo 
"$camp1"
pero me sale:
Notice: Undefined offset: 0

que hago???