Ver Mensaje Individual
  #3 (permalink)  
Antiguo 02/05/2010, 07:32
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Formulario dinamico

Hola

No he entendido muy bien cual es la configuración de tu formulario

Esto es un ejemplo

Código HTML:
Ver original
  1. </head>
  2. <form action="RecogerSOLOCamposRellenos.asp" method="post">
  3. <input type="text" id="1" name="cam_form" value="" tabindex="1" />
  4. <input type="text" id="txt1" name="cam_form" value="" tabindex="2" />
  5. <input type="text" id="txt11" name="cam_form" value="" tabindex="3" />
  6. <textarea id="txtarea1" name="cam_form" tabindex="4"></textarea><br />
  7.  
  8. <input type="text" id="2" name="cam_form" value="" tabindex="5" />
  9. <input type="text" id="txt2" name="cam_form" value="" tabindex="6" />
  10. <input type="text" id="txt22" name="cam_form" value="" tabindex="7" />
  11. <textarea id="txtarea2" name="cam_form" tabindex="8"></textarea><br />
  12.  
  13. <input type="text" id="3" name="cam_form" value="" tabindex="9" />
  14. <input type="text" id="txt3" name="cam_form" value="" tabindex="10" />
  15. <input type="text" id="txt33" name="cam_form" value="" tabindex="11" />
  16. <textarea id="txtarea3" name="cam_form" tabindex="12"></textarea><br />
  17.  
  18. <input type="text" id="4" name="cam_form" value="" tabindex="13" />
  19. <input type="text" id="txt4" name="cam_form" value="" tabindex="14" />
  20. <input type="text" id="txt44" name="cam_form" value="" tabindex="15" />
  21. <textarea id="txtarea4" name="cam_form" tabindex="16"></textarea><br />
  22.  
  23. <input type="submit"  value="Enviar" />
  24. </form>
  25. </body>
  26. </html>


RecogerSOLOCamposRellenos.asp

Código ASP:
Ver original
  1. <&#37;
  2. Dim Arr() ' Valores de todos los campos recibidos
  3. For each campo in Request.Form
  4. valCampos = valCampos & Request.Form(campo)
  5. Next
  6.  
  7. division = Split(valCampos, ",")
  8.  
  9. for i = 0 to UBound(division)
  10. Redim preserve Arr(i+1)
  11. Arr(i) = Trim(division(i))
  12. next
  13.  
  14. Dim Arr2() ' Valores del primer campo de cada tr
  15. Dim Arr3() ' Valores del segundo campo de cada tr
  16. Dim Arr4() ' Valores del tercer campo de cada tr
  17. Dim Arr5() ' Valores del cuarto campo de cada tr
  18.  
  19. j = 0
  20. for i = 0 to ubound(Arr)-1 step 4
  21. if Arr(i) <> "" then
  22. Redim preserve Arr2(j)
  23. Arr2(j) = Arr(i)
  24. j = j +1
  25. end if
  26. next
  27.  
  28. x = 0
  29. for i = 1 to ubound(Arr)-1 step 4
  30. if Arr(i) <> "" then
  31. Redim preserve Arr3(x)
  32. Arr3(x) = Arr(i)
  33. x = x +1
  34. end if
  35. next
  36.  
  37.  
  38. p = 0
  39. for i = 2 to ubound(Arr)-1 step 4
  40. if Arr(i) <> "" then
  41. Redim preserve Arr4(p)
  42. Arr4(p) = Arr(i)
  43. p = p +1
  44. end if
  45. next
  46.  
  47. z = 0
  48. for i = 3 to ubound(Arr)-1 step 4
  49. if Arr(i) <> "" then
  50. Redim preserve Arr5(z)
  51. Arr5(z) = Arr(i)
  52. z = z +1
  53. end if
  54. next
  55.  
  56. ' conexión bd
  57.  
  58. for i = 0 to j-1
  59. 'Response.Write Arr2(i) & ","
  60. 'Response.Write Arr3(i) & ","
  61. 'Response.Write Arr4(i) & ","
  62. 'Response.Write Arr5(i) & "<br />"
  63. SQL="INSERT INTO tabla (campo, campo2, campo3, campo4) VALUES ('"&Arr2(i)&"', '"&Arr3(i)&"', #"&Arr4(i)&"#, #"&Arr5(i)&"#);"
  64. oConn.Execute(SQL)
  65. next
  66. oConn.Close
  67. set oConn = nothing
  68.  
  69. Response.Write("Datos Insertados con &eacute;xito")
  70. %>

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />