Foros del Web » Programando para Internet » ASP Clásico »

[SOLUCIONADO] Problema con formulario

Estas en el tema de Problema con formulario en el foro de ASP Clásico en Foros del Web. Tengo un problema con un formulario que le inclui captcha y para verificar si los datos estan correctos los mando a otra pagina donde me ...
  #1 (permalink)  
Antiguo 05/09/2013, 11:23
 
Fecha de Ingreso: noviembre-2012
Mensajes: 139
Antigüedad: 11 años, 5 meses
Puntos: 1
Problema con formulario

Tengo un problema con un formulario que le inclui captcha
y para verificar si los datos estan correctos los mando a otra pagina donde me valida si esta correcto o no ,
si no esta correcto me devuleve al formulario pero los datos de las cajas de texto se borran
como puedo hacer para que el formulario se quede con los datos que ingreso el usuario ?
  #2 (permalink)  
Antiguo 05/09/2013, 14:55
 
Fecha de Ingreso: noviembre-2012
Mensajes: 139
Antigüedad: 11 años, 5 meses
Puntos: 1
Respuesta: Problema con formulario

aqui se dan los datos
Código ASP:
Ver original
  1. <%@ Language="VBScript"  %>
  2. <!--#include file="conexion.asp" -->
  3. <%
  4. sub generaPaises()
  5.     Set B_REGIONES = Server.CreateObject("ADODB.Recordset")
  6.     set B_REGIONES=connBM.execute("BM_BUSCA_REGIONES ")
  7.     ' Voy imprimiendo el primer select compuesto por los paises
  8.     Response.Write "<select class=""combo"" id=""select_0"" name=""select_0"" onChange=""cargaContenido()"" style='width: 260px;'>"
  9.     While not B_REGIONES.EOF
  10.         Response.Write "<option value='"& B_REGIONES("BM_ID_REGION") &"'>" & B_REGIONES("BM_REGION") & "</option>"
  11.         B_REGIONES.MoveNext
  12.     Wend
  13.     Response.Write "</select>"
  14.  
  15.     B_REGIONES.Close   
  16. End sub
  17.  
  18. Set B_REGIONES = Server.CreateObject("ADODB.Recordset")
  19. Response.CodePage = 1252
  20. Response.CharSet = "windows-1252"  
  21. TXT_TUTULO_PRODUCTO_ = Request.querystring("TXT_TITULO")
  22. oid_oferta = Request.querystring("id_oferta")
  23. alerta_1 = Request.QueryString("rs")  
  24. if alerta_1="1"then
  25. %>
  26. <script> alert("usuario ya existe ")</script>
  27. <%end if %>
  28. <%if alerta_1="2"then %>
  29. <script> alert("Las contraseñas deben coincidir")</script>
  30. <%end if %>
  31. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  32. <html xmlns="http://www.w3.org/1999/xhtml">
  33. <head>    
  34.      <meta name="Barrio Meiggs" contents="Barrio Meiggs, Productos,  Locales Estación Central. Jugueterias, Novedades, Adornos, Navidad, Año Nuevo,  Fiestas, Disfrases, Juegos, Deportes,  Cotillon, Articulos de Temporada, Electronica, Utiles Escolares, Utiles de Aseo, Fiestas Patrias, Etc,  Seguridad, Muchos Locales, Arriendo, BarrioMeiggs, Meigs, Meyg, " lang="es">
  35.      <meta http-equiv="Content-Type" charset="iso-8859-1"/>
  36.         <link rel="stylesheet" type="text/css" href="css/formularios.css">
  37.         <script src="Scripts/jquery-1.9.0.js" type="text/javascript"></script>
  38.         <link rel="stylesheet" href="css/jquery.ketchup.css" type="text/css" media="screen" />
  39.         <script src="Scripts/jquery.ketchup.all.min.js" type="text/javascript"></script>
  40.         <title></title>
  41. <script language="javascript">
  42. $(document).ready(function () {
  43. $('#contacto').ketchup({}, {
  44. '.required' : 'required',
  45. '#comentario': 'minlength(10)',
  46. '#email': 'email',
  47. '#txtCant': 'number'    
  48. });
  49. $('#b_region').change(function () { llenarselect(); });  
  50. });
  51. function conMayusculas(campo)
  52. {
  53. campo.value = campo.value.toUpperCase()
  54. }
  55. function validarTexto(e)
  56. {
  57.     tecla = (document.all) ? e.keyCode : e.which;
  58.     if (tecla==8) return true;
  59.     patron =/[A-Za-zÑñ[email protected]]/; //  
  60.     te = String.fromCharCode(tecla);
  61.     return patron.test(te);
  62. }
  63. </script>
  64. <script language="javascript" type="text/javascript">
  65. function nuevoAjax()
  66. {
  67.     /* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
  68.     lo que se puede copiar tal como esta aqui */
  69.     var xmlhttp=false;
  70.     try
  71.     {
  72.         // Creacion del objeto AJAX para navegadores no IE
  73.         xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  74.     }
  75.     catch(e)
  76.     {
  77.         try
  78.         {
  79.             // Creacion del objet AJAX para IE
  80.             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  81.         }
  82.         catch(E) { xmlhttp=false; }
  83.     }
  84.     if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); }
  85.  
  86.     return xmlhttp;
  87. }
  88.  
  89. function cargaContenido()
  90. {
  91.     var valor=document.getElementById("select_0").options[document.getElementById("select_0").selectedIndex].value;
  92.     if(valor==0)
  93.     {
  94.         // Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
  95.         combo=document.getElementById("select_1");
  96.         combo.length=0;
  97.         var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Selecciona Pais...";
  98.         combo.appendChild(nuevaOpcion); combo.disabled=true;
  99.     }
  100.     else
  101.     {
  102. ajax=nuevoAjax();
  103. ajax.open("GET", "llenarprovincia.asp?id="+valor, true);
  104. ajax.onreadystatechange=function()
  105. {
  106. if (ajax.readyState==1)
  107. {
  108. // Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
  109. combo=document.getElementById("select_1");
  110. combo.length=0;
  111. var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Cargando...";
  112. combo.appendChild(nuevaOpcion); combo.disabled=true;   
  113. }
  114. if (ajax.readyState==4)
  115. {
  116. document.getElementById("fila_2").innerHTML=ajax.responseText;
  117. }
  118. }
  119. ajax.send(null);
  120. }
  121. }
  122. </script>
  123. </head>
  124. <body >
  125. <img src="img/fondo.jpg" alt="texto alternativo" id="fondo" />
  126. <div id="form-wrapper">
  127. <form id="contacto" action="Para_usuario.asp" method="POST" onload="cargaContenido()" >
  128. <table id="background-image">
  129. <tr >
  130. <th align="center">Registro<br><br>
  131. <a>Nombre &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </a><input name="txtNombre_usu" type="text" size="40" class="required" maxlength="50" onKeyPress="return validarTexto(event);"  /><br><br>      
  132. <a>Apellido &nbsp;&nbsp;&nbsp;&nbsp;   :</a> <input name="txtApellido_usu" type="text" size="40" class="required" maxlength="50" onKeyPress="return validarTexto(event);" /><br><br>
  133. <div id="fila_1">Región   &nbsp;&nbsp;&nbsp;&nbsp; : <% generaPaises() %></div><br>
  134. <div id="fila_2">Provincia &nbsp;&nbsp;&nbsp; :          
  135. <select class="combo" disabled="disabled" id="select_1" name="select_1" style='width: 282px;'>
  136. <option id="valor_defecto" value="0">Elija Región...</option>
  137. </select>
  138. </div><br>
  139. <a>Em@il  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :</a> <input  name="txtemail_usu" type="text" id="email" size="40"  maxlength="50" onKeyPress="return validarTexto(event);" /><br><br>  
  140. <a>Contrase&ntilde;a&nbsp;   :</a> <input name="txtpassword_usu"  type="password" size="40" class="required" maxlength="50" onKeyPress="return validarTexto(event);" /><br><br>
  141. <a>Contrase&ntilde;a&nbsp;   :</a> <input name="txtpassword1_usu" type="password" size="40" class="required" maxlength="50" onKeyPress="return validarTexto(event);" /><br><br>
  142. <a width="182"></a><img src="aspcaptcha.asp" alt="This Is CAPTCHA Image" width="86" height="21" /><br>
  143. <input name="strCAPTCHA" type="text" id="strCAPTCHA" maxlength="8" /><br><br>
  144. <input type="hidden" name="id_2" value="1"/>
  145. <input name="submit" type="submit"  value="Registrarse"/>              
  146. </th>
  147. </tr>
  148. </table>
  149. </form>  
  150. </div>
  151. </body>
  152. </html>
  #3 (permalink)  
Antiguo 05/09/2013, 14:55
 
Fecha de Ingreso: noviembre-2012
Mensajes: 139
Antigüedad: 11 años, 5 meses
Puntos: 1
Respuesta: Problema con formulario

aqui se validan todos los datos
Código ASP:
Ver original
  1. <%@LANGUAGE="VBSCRIPT" %>
  2. <%
  3. Response.CacheControl = "no-cache"
  4. Response.AddHeader "Pragma", "no-cache"
  5. Response.Expires = -1
  6. %>
  7. <%
  8. Function CheckCAPTCHA(valCAPTCHA)
  9. SessionCAPTCHA = Trim(Session("CAPTCHA"))
  10. Session("CAPTCHA") = vbNullString
  11. if Len(SessionCAPTCHA) < 1 then
  12. CheckCAPTCHA = False
  13. exit function
  14. end if
  15. if CStr(SessionCAPTCHA) = CStr(valCAPTCHA) then
  16. CheckCAPTCHA = True
  17. else
  18. CheckCAPTCHA = False
  19. end if
  20. End Function
  21. %>
  22. %
  23. if Request.ServerVariables("REQUEST_METHOD") = "POST" then
  24. strCAPTCHA = Trim(Request.Form("strCAPTCHA"))
  25. if CheckCAPTCHA(strCAPTCHA) = true then
  26. %>
  27. <!--#include file="conexion.asp" -->
  28. <!--#include file="rutinas.asp" -->
  29. <%
  30. set Registro_usuario= Server.CreateObject("ADODB.Recordset")
  31. set Inicio_sesion= Server.CreateObject("ADODB.Recordset")
  32. set validar_registro = Server.CreateObject("ADODB.Recordset")
  33. Set Cambiar_estado = Server.CreateObject("ADODB.Recordset")
  34. set validar_registro = connBM.execute("BM_BUSCA_CORREO_USU" )
  35. id_usuario = Request.querystring("cu")
  36. BM_id = request.form("id_2")
  37. Response.CodePage = 1252
  38. Response.CharSet = "windows-1252"  
  39. %>
  40. <%
  41. if BM_id = "1" then
  42. BM_nombre_usu = request.form("txtnombre_usu")
  43. BM_apellido_usu = request.form("txtapellido_usu")
  44. BM_ciudad_usu = request.form("select_0")
  45. BM_provincia_usu = request.form("select_1")
  46. BM_email_usu = request.form("txtemail_usu")
  47. BM_password_usu = request.form("txtpassword_usu")
  48. BM_password1_usu = request.form("txtpassword1_usu")
  49. BM_estado_usu = 0
  50. BM_TIPO_USU = 1
  51. 'validar la password
  52. if BM_password_usu <> BM_password1_usu then
  53. Response.Redirect("Registro.asp?rs=2")
  54. end if
  55. 'encriptar pasword
  56. xg_password = ""
  57. for j=1 to len(trim(BM_password_usu))
  58. xg_caracter = chr(asc(mid(BM_password_usu,j,1)) - 5)
  59. xg_newpassword = xg_newpassword + xg_caracter
  60. next
  61. 'validar que usurio ya existe
  62. if not validar_registro.eof then
  63. for i=1 to len(validar_registro("BM_EMAIL_USU"))
  64. if validar_registro.eof then
  65. else
  66. if BM_email_usu = validar_registro("BM_EMAIL_USU") THEN
  67. Response.Redirect ("Registro.asp?rs=1")
  68. else
  69. validar_registro.movenext
  70. end if
  71. end if
  72. next
  73. end if
  74. 'guarda nuevo usuario
  75. set Registro_usuario = connBM.execute("BM_GRABA_USUARIOS '"&BM_nombre_usu&"','"&BM_apellido_usu&"','"&BM_email_usu&"','"&xg_newpassword&"','"&BM_ciudad_usu&"','"&BM_estado_usu&"','"&BM_provincia_usu&"','"&BM_TIPO_USU&"' ")
  76. 'manda correo
  77. set mail = server.createObject("Persits.MailSender")
  78. mail.host = "mail.barriomeiggs.cl"
  79. Mail.Username = "[email protected]"
  80. Mail.Password = "labtuxlinktux"
  81. mail.from = "[email protected]"
  82. mail.addAddress BM_email_usu
  83. mail.Subject = "CONFIRMACION DE REGISTRO"
  84. set Inicio_sesion = connBM.execute("BM_BUSCA_POREMAIL_USU '"&BM_email_usu&"' ")
  85. BM_codigo_usu = Inicio_sesion("BM_ID_USU")
  86. xg_registro = ""
  87. for j=1 to len(trim(BM_codigo_usu))
  88. xg_caracter = chr(asc(mid(BM_codigo_usu,j,1)) - 5)
  89. xg_newregistro = xg_newregistro + xg_caracter
  90. next
  91. cuerpo = ""
  92. cuerpo = "GRACIAS POR REGISTRARSE EN NUESTRA PAGINA www.barriomeiggs.cl"& VBNEWLINE & VBNEWLINE
  93. cuerpo = cuerpo & "SR(A): " & BM_nombre_usu &  " " & BM_apellido_usu & VBNEWLINE
  94. cuerpo = cuerpo & "PARA ACTIVAR SU CUENTA DAR CLICK EN EL SIGUIENTE LINK" & VBNEWLINE
  95. cuerpo = cuerpo & "http://www.barriomeiggs.cl/Para_usuario.asp?cu=" &xg_newregistro & "&id_2=3" & VBNEWLINE
  96. mail.body = cuerpo
  97. mail.send
  98. Response.Redirect ("index.asp")
  99. end if
  100. %>
  101. <%
  102. 'inicio sesion
  103. if BM_id = "2" then
  104. EMAIL_USU = request.form("Email_usu")
  105. PASSWORD_USU = request.form("Password_usu")
  106. set Inicio_sesion = connBM.execute("BM_BUSCA_POREMAIL_USU '"&EMAIL_USU&"' ")
  107. xg_newpassword = ""
  108. if  Inicio_sesion.eof then
  109. Response.Redirect ("Inicio_sesion.asp?rs=1")
  110. else
  111. for j=1 to len(trim(Inicio_sesion("BM_PASSWORD_USU")))
  112. xg_caracter = chr(asc(mid(Inicio_sesion("BM_PASSWORD_USU"),j,1)) + 5)
  113. xg_newpassword = xg_newpassword + xg_caracter
  114. next
  115. if (EMAIL_USU = Inicio_sesion("BM_EMAIL_USU")) AND (xg_newpassword = PASSWORD_USU) AND (Inicio_sesion("BM_ESTADO_USU")="1") then
  116. session.contents("IDENTIFICADOR")= Inicio_sesion("BM_ID_USU")
  117. session.contents("usuario")=Inicio_sesion("BM_NOMBRE_USU")
  118. session.contents("apellido")=Inicio_sesion("BM_APELLIDO_USU")
  119. session.contents("correo")=Inicio_sesion("BM_EMAIL_USU")
  120. session.contents("ciudad")=Inicio_sesion("BM_CIUDAD_USU")
  121. IF Inicio_sesion("BM_TIPO_USU") = "1" THEN
  122. Response.Redirect ("index_prueba.asp")
  123. END IF
  124. IF Inicio_sesion("BM_TIPO_USU") = "2" THEN
  125. Response.Redirect ("BM_ADM.asp")
  126. END IF
  127. else
  128. Response.Redirect ("Inicio_sesion.asp?rs=1")
  129. end if
  130. end if
  131. end if
  132. %>
  133. <%
  134. for j=1 to len(trim(id_usuario))
  135. xg_caracter = chr(asc(mid(id_usuario,j,1)) + 5)
  136. xg_newid_usuario = xg_newid_usuario + xg_caracter
  137. next
  138. set Cambiar_estado = connBM.execute("BM_UPDATE_ESTADO_USU '"&xg_newid_usuario&"'" )
  139. set Inicio_sesion = connBM.execute("BM_BUSCA_PORID_USU '"&xg_newid_usuario&"' ")
  140. if Inicio_sesion.eof then
  141. Response.Redirect ("index_prueba.asp?rs=1")
  142. else
  143. session.contents("IDENTIFICADOR")= Inicio_sesion("BM_ID_USU")
  144. session.contents("usuario")=Inicio_sesion("BM_NOMBRE_USU")
  145. session.contents("apellido")=Inicio_sesion("BM_APELLIDO_USU")
  146. session.contents("correo")=Inicio_sesion("BM_EMAIL_USU")
  147. session.contents("ciudad")=Inicio_sesion("BM_CIUDAD_USU")
  148. IF Inicio_sesion("BM_TIPO_USU") = "1" THEN
  149. Response.Redirect ("index_prueba.asp")
  150. END IF
  151. IF Inicio_sesion("BM_TIPO_USU") = "2" THEN
  152. Response.Redirect ("BM_ADM.asp")
  153. END IF
  154. end if
  155. %>
  156. <% 'response.redirect("Para_usuario.asp.asp")%>
  157.  <%
  158. else
  159. %>
  160.  <!DOCTYPE html>
  161. <html lang="en">
  162. <head>
  163. <meta http-equiv="refresh" content="3;URL=registro.asp">
  164. </head>
  165. <body>
  166. No Valido.Intente Captcha Nuevamente.en 3 segundos
  167. </body>
  168. </html>  
  169. <form name="form2" id="contacto" action="registro.asp" method="POST" >
  170. <% 
  171. end if
  172. end if
  173. %>
  #4 (permalink)  
Antiguo 10/09/2013, 03:15
 
Fecha de Ingreso: abril-2012
Ubicación: Madrid (España)
Mensajes: 162
Antigüedad: 12 años
Puntos: 5
Respuesta: Problema con formulario

Cuando envies el formulario y evalues las variables, guarda las variables como variables de session y a la pagina del formulario le pasas una variable de fallo.

EJ:

Una vez hace el submit.
Código:
Nombre = Request.form("Nombre")
captcha = Request.form("captcha")

Session NombreSesion = Nombre

if captcha = VariableCorrecta then
...
...
else
response.redirect("Form.asp?Fallo="SI")
end if
-------------

Form.asp

Código:
Nombre = Session("Nombre")

if Fallo = "SI" then

Muestras los campos con value = <%=Nombre%>
else
Muestras el formulario normal
end if.
Ojo. lo estoy haciendo a ojo así que puede haber errores pero para que te hagas una idea.

Etiquetas: dato, formulario
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:29.