Ver Mensaje Individual
  #2 (permalink)  
Antiguo 26/06/2011, 00:43
Avatar de blakmetall
blakmetall
 
Fecha de Ingreso: diciembre-2010
Ubicación: Jalisco
Mensajes: 181
Antigüedad: 13 años, 4 meses
Puntos: 18
Respuesta: Problemas con validacion de formulario

Mas bien creo que este es tema de javascript.

Mira hice un codigo asi rapido para verificacion con javascript. lo checas.

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.     function submitFunction(){
  3.         var todoBien = true;
  4.        
  5.         var doc = document.forma;
  6.        
  7.         var nombres = doc.nombre.value;
  8.         var apellidos = doc.apellidos.value;
  9.         var telefono = doc.telefono.value;
  10.        
  11.         var mensaje = "";
  12.        
  13.         if( (nombres.match(/^[a-zA-Z ]+$/) == null) || nombres.length == 0){
  14.             todoBien = false;
  15.             mensaje = "- Nombre incorrecto.\n";
  16.         }
  17.        
  18.         if( (apellidos.match(/^[a-zA-Z ]+$/) == null) || apellidos.length == 0){
  19.             todoBien = false;
  20.             mensaje += "- Apellidos incorrectos.\n";
  21.         }
  22.        
  23.         if( (telefono.match(/^[0-9]+$/) == null) || telefono.length == 0){
  24.             todoBien = false;
  25.             mensaje += "- Telefono incorrecto.\n";
  26.         }
  27.        
  28.         if(doc.condiciones.checked == false){
  29.             todoBien = false;
  30.             mensaje += "-Aceptar condiciones.\n";
  31.         }
  32.        
  33.         if(!todoBien){
  34.             alert(mensaje);
  35.         }
  36.        
  37.         return todoBien;
  38.     }
  39.  
  40. </script>

Código HTML:
Ver original
  1. <form name="forma" action="escritorbase.php" onsubmit="return submitFunction()" method="post" >
  2.            
  3. INGRESE NOMBRES:
  4. <input type="text" id="nombre" name="nombre"><br>
  5. INGRESE APELLIDOS:
  6. <input type="text" id="apellidos" name="apellidos"><br>
  7. INGRESE TELEFONO:
  8. <input type="text" id="telefono" name="telefono"><br>
  9. TIPO DE USUARIO:
  10. <br>
  11. <select name="usuario" id="usuario">
  12. <option value="administrador">ADMINISTRADOR</option>
  13. <option value="comprador">COMPRADOR</option>
  14. <br>
  15. <input id="condiciones" type="checkbox" name="condiciones">Acepto las condiciones para el registro
  16.     <!-- en este boton va el llamado a la pg php que valida de cuanta del servidor, falta la validacion en el nevegador usando javascript -->      
  17. <input type="submit" name="enviar" value="Registrar">
  18.  
  19. </form>

y para llamar la funcion cuando se da sumbit ya sea por click o por enter:

<form name="forma" action="escritorbase.php" onsubmit="return submitFunction()" method="post" >