Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/06/2011, 05:43
sirdaiz
 
Fecha de Ingreso: diciembre-2010
Mensajes: 459
Antigüedad: 13 años, 4 meses
Puntos: 21
problema validar datos

Hola buscandopor internet encontre esto muy interesante, lo he probado en local y funciona:

Código PHP:
Ver original
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es">
  3. <head>
  4. <title>Jquery Validate email checkbox select box</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta http-equiv="content-language" content="es" />
  7. <script type="text/javascript" src="js/jquery_1.4.js"></script>
  8. <script type="text/javascript" src="js/jquery_validate.js"></script>
  9. <script type="text/javascript">
  10. $(function(){
  11.     $('#formInscripcion').validate({
  12.         rules: {
  13.         'nombre': 'required',
  14.         'apellido': 'required',
  15.         'numero_identidad': { required: true, number: true },
  16.         'email': { required: true, email: true },
  17.         'tipo_identidad': 'required',
  18.         'deportes[]': { required: true, minlength: 1 }
  19.         },
  20.         messages: {
  21.         'nombre': 'Debe ingresar el nombre',
  22.         'apellido': 'Debe ingresar el apellido',
  23.         'numero_identidad': { required: 'Debe ingresar el número de documento de identidad', number: 'Debe ingresar un número' },
  24.         'email': { required: 'Debe ingresar un correo electrónico', email: 'Debe ingresar el correo electrónico con el formato correcto. Por ejemplo: [email protected]' },
  25.         'tipo_identidad': 'Debe ingresar el número de documento',
  26.         'deportes[]': 'Debe seleccionar mínimo un deporte'
  27.         },
  28.         debug: true,
  29.         /*errorElement: 'div',*/
  30.         //errorContainer: $('#errores'),
  31.         submitHandler: function(form){
  32.             alert('El formulario ha sido validado correctamente!');
  33.         }
  34.     });
  35. });
  36. </script>
  37. </head>
  38. <body>
  39. <h1>Jquery Validate email checkbox select box</h1>
  40.     <form id="formInscripcion" method="post" action="">
  41.         <fieldset>
  42.             <legend>Datos Personales</legend>
  43.             <p><label for="nombre">Primer Nombre:</label> <input type="text" name="nombre" id="nombre" /></p>
  44.             <p><label for="apellido">Primer Apellido:</label> <input type="text" name="apellido" id="apellido" /></p>
  45.             <p><label for="numero_identidad">Número Documento Identidad:</label> <input type="text" name="numero_identidad" id="numero_identidad" /></p>
  46.             <p><label for="email">Email:</label> <input type="text" name="email" id="email" /></p>
  47.             <p><label for="tipo_identidad">Tipo Documento Identidad:</label>
  48.                 <select name="tipo_identidad" id="tipo_identidad">
  49.                     <option value="">Tipo de Documento</option>
  50.                     <option value="1">Tarjeta Identidad</option>
  51.                     <option value="2">Cédula</option>
  52.                 </select>
  53.             </p>
  54.         </fieldset>
  55.         <fieldset>
  56.             <legend>Seleccione deportes</legend>
  57.             <p><label for="deporte_1">Baloncesto</label> <input type="checkbox" name="deportes[]" id="deporte_1" value="1" /></p>
  58.             <p><label for="deporte_2">Natación</label> <input type="checkbox" name="deportes[]" id="deporte_2" value="2" /></p>
  59.             <p><label for="deporte_3">Fútbol</label> <input type="checkbox" name="deportes[]" id="deporte_3" value="3" /></p>
  60.             <p><label for="deporte_4">Ciclismo</label> <input type="checkbox" name="deportes[]" id="deporte_4" value="4" /></p>
  61.         </fieldset>
  62.         <p><input type="submit" name="enviar" value="Enviar" /></p>
  63.     </form>
  64. </body>
  65. </html>

y quize adaptarlo al mio:

Código PHP:
Ver original
  1. en los head tengo los respectivos:
  2.  
  3. <script language="text/javaScript" SRC="../js/verificar2.js"></script>
  4. <script language="text/javascript" src="../js/jquery_1.4.js"></script>
  5. <script language="text/javascript" src="../js/jquery_validate.js"></script>
  6.  
  7. <FORM id="formRegistro"  name="formRegistro" ACTION="" METHOD="POST">
  8.         <div class="formularioDP">
  9.             <div class="formularioDP2">DATOS PERSONALES</div>
  10.                 <table align="center">
  11.                 <tr>
  12.                     <td class="alinearDerecha"><label for=Nombre>Nombre</label></td>
  13.                     <td class="centroForm"><input type="text" id="nombre"/></td>
  14.                     <td class="requerido"><label for=r1>*</label></td>
  15.                 </tr>
  16.  
  17. <tr>
  18.                     <td colspan="3"><input  value="Registrarse" type="submit"/></td>
  19.                 </tr>
  20.  
  21.             </table>
  22.         </div>
  23.        
  24.     </form>

y el .js. weno aki te pongo todos los que uso(aparte de los .js que venian con el codigo, ya que me lo he descargado

Código PHP:
Ver original
  1. $(function(){
  2.     $('#formRegistro').validate({
  3.         rules: {
  4.         'nombre': 'required',
  5.         'apellido': 'required',
  6.         'usuario': { required: true, minlength: 4 },
  7.         'correo': { required: true, email: true },
  8.         'pass': { required: true, minlength: 6 },
  9.         'pass2': { required: true, minlength: 6 }
  10.         },
  11.         messages: {
  12.         'nombre': 'Debe ingresar el nombre',
  13.         'apellido': 'Debe ingresar el apellido',
  14.         'usuario': { required: 'Debe ingresar el apellido', number: 'Debe ingresar mínimo 4 caracteres' },
  15.         'pass': { required: 'Debe ingresar una contraseña', number: 'Debe ingresar mínimo 6 caracteres'},
  16.         'pass2': { required: 'Debe ingresar una contraseña', number: 'Debe ingresar mínimo 6 caracteres'},
  17.         'email': { required: 'Debe ingresar un correo electrónico', email: 'Debe ingresar el correo electrónico con el formato correcto. Por ejemplo: [email protected]' }
  18.        
  19.         },
  20.         debug: true,
  21.         /*errorElement: 'div',*/
  22.         //errorContainer: $('#errores'),
  23.         submitHandler: function(form){
  24.             alert('El formulario ha sido validado correctamente!');
  25.         }
  26.     });
  27. });

Gracias