Problemas con las validaciones
Buenas tardes tengo un problema con una validación tengo un formulario que me validan los campos del formulario siempre y cuando no presione el botón de enviar o solamente enviar el formulario, al momento de oprimir el botón de enviar el formulario la envía los espacios en blanco a la base de dato
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Niceforms</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href= "niceforms-default.css" />
<script LANGUAGE="JavaScript">
function validarEntero(valor){
//intento convertir a entero.
//si era un entero no le afecta, si no lo era lo intenta convertir
valor = parseInt(valor)
//Compruebo si es un valor numérico
if (isNaN(valor)) {
//entonces (no es numero) devuelvo el valor cadena vacia
{
alert("Por favor ingrese un numero entero");
}
return true;
}else{
//En caso contrario (Si era un número) devuelvo el valor
return valor
}
}
/*
function IsNumeric(valor)
{
var log=valor.length; var sw="S";
for (x=0; x<log; x++)
{ v1=valor.substr(x,1);
v2 = parseInt(v1);
//Compruebo si es un valor numérico
if (isNaN(v2)) { sw= "N";}
}
if (sw=="S") {return true;} else {return false; }
}
var primerslap=false;
var segundoslap=false;
function formateafecha(tfecha_nacimiento)
{
var long = tfecha_nacimiento.length;
var dia;
var mes;
var ano;
if ((long>=2) && (primerslap==false)) { dia=tfecha_nacimiento.substr(0,2);
if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) { tfecha_nacimiento=tfecha_nacimiento.substr(0,2)+"/"+tfecha_nacimiento.substr(3,7); primerslap=true; }
else { tfecha_nacimiento=""; primerslap=false;}
}
else
{ dia=tfecha_nacimiento.substr(0,1);
if (IsNumeric(dia)==false)
{tfecha_nacimiento="";}
if ((long<=2) && (primerslap=true)) {tfecha_nacimiento=tfecha_nacimiento.substr(0,1); primerslap=false; }
}
if ((long>=5) && (segundoslap==false))
{ mes=tfecha_nacimiento.substr(3,2);
if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { tfecha_nacimiento=tfecha_nacimiento.substr(0,5)+"/"+tfecha_nacimiento.substr(6,4); segundoslap=true; }
else { tfecha_nacimiento=tfecha_nacimiento.substr(0,3);; segundoslap=false;}
}
else { if ((long<=5) && (segundoslap=true)) { tfecha_nacimiento=tfecha_nacimiento.substr(0,4); segundoslap=false; } }
if (long>=7)
{ ano=tfecha_nacimiento.substr(6,4);
if (IsNumeric(ano)==false) { tfecha_nacimiento=tfecha_nacimiento.substr(0,6); }
else { if (long==10){ if ((ano==0) || (ano<1900) || (ano>2100)) { tfecha_nacimiento=tfecha_nacimiento.substr(0,6); } } }
}
if (long>=10)
{
tfecha_nacimiento=tfecha_nacimiento.substr(0,10);
dia=tfecha_nacimiento.substr(0,2);
mes=tfecha_nacimiento.substr(3,2);
ano=tfecha_nacimiento.substr(6,4);
// Año no viciesto y es febrero y el dia es mayor a 28
if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { tfecha_nacimiento=tfecha_nacimiento.substr(0,2)+"/"; }
}
return (tfecha_nacimiento);
}
*/
function Validar(form)
{
if (form.numero_proyecto.value == "")
{ alert("Por favor ingrese su Numero del Proyecto");
form.numero_proyecto.focus();
return false;
}
if (form.nombre_proyecto.value == "")
{
alert("Por favor ingrese su Nombre");
form.nombre_proyecto.focus();
return false;
}
if (form.objetivo_proyecto.value == "")
{
alert("Por favor ingrese el Objetivo del Proyecto");
form.objetivo_proyecto.focus();
return false;
}
if (form.coordinador_proyecto.value == "")
{
alert("Por favor ingrese el nombre del coordinador de proyecto");
form.coordinador_proyecto.focus();
return false;
}
if (form.direccion_proyecto.value == "")
{
alert("Por favoringrese la Direccion del proyecto");
form.direccion_proyecto.focus();
return false;
}
return true;
form.submit();
}
</script>
</head>
<body>
<div id="container">
<form action="ingresar_proyecto.php" method="post" class="niceform" onsubmit="return validar(this.form)" name="Formvalidar(form)">
<fieldset>
<legend>Ingresar Nuevo Proyecto</legend>
<dl>
<dt>
<label for="numero_proyecto">Numero del proyecto</label>
</dt>
<dd><input type="text" name="numero_proyecto" id="numero_proyecto" size="32" maxlength="128" onClick="Validar(this.form)" onsubmit="return validar(this.form)" /></dd>
...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Niceforms</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href= "niceforms-default.css" />
<script LANGUAGE="JavaScript">
function validarEntero(valor){
//intento convertir a entero.
//si era un entero no le afecta, si no lo era lo intenta convertir
valor = parseInt(valor)
//Compruebo si es un valor numérico
if (isNaN(valor)) {
//entonces (no es numero) devuelvo el valor cadena vacia
{
alert("Por favor ingrese un numero entero");
}
return true;
}else{
//En caso contrario (Si era un número) devuelvo el valor
return valor
}
}
/*
function IsNumeric(valor)
{
var log=valor.length; var sw="S";
for (x=0; x<log; x++)
{ v1=valor.substr(x,1);
v2 = parseInt(v1);
//Compruebo si es un valor numérico
if (isNaN(v2)) { sw= "N";}
}
if (sw=="S") {return true;} else {return false; }
}
var primerslap=false;
var segundoslap=false;
function formateafecha(tfecha_nacimiento)
{
var long = tfecha_nacimiento.length;
var dia;
var mes;
var ano;
if ((long>=2) && (primerslap==false)) { dia=tfecha_nacimiento.substr(0,2);
if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) { tfecha_nacimiento=tfecha_nacimiento.substr(0,2)+"/"+tfecha_nacimiento.substr(3,7); primerslap=true; }
else { tfecha_nacimiento=""; primerslap=false;}
}
else
{ dia=tfecha_nacimiento.substr(0,1);
if (IsNumeric(dia)==false)
{tfecha_nacimiento="";}
if ((long<=2) && (primerslap=true)) {tfecha_nacimiento=tfecha_nacimiento.substr(0,1); primerslap=false; }
}
if ((long>=5) && (segundoslap==false))
{ mes=tfecha_nacimiento.substr(3,2);
if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { tfecha_nacimiento=tfecha_nacimiento.substr(0,5)+"/"+tfecha_nacimiento.substr(6,4); segundoslap=true; }
else { tfecha_nacimiento=tfecha_nacimiento.substr(0,3);; segundoslap=false;}
}
else { if ((long<=5) && (segundoslap=true)) { tfecha_nacimiento=tfecha_nacimiento.substr(0,4); segundoslap=false; } }
if (long>=7)
{ ano=tfecha_nacimiento.substr(6,4);
if (IsNumeric(ano)==false) { tfecha_nacimiento=tfecha_nacimiento.substr(0,6); }
else { if (long==10){ if ((ano==0) || (ano<1900) || (ano>2100)) { tfecha_nacimiento=tfecha_nacimiento.substr(0,6); } } }
}
if (long>=10)
{
tfecha_nacimiento=tfecha_nacimiento.substr(0,10);
dia=tfecha_nacimiento.substr(0,2);
mes=tfecha_nacimiento.substr(3,2);
ano=tfecha_nacimiento.substr(6,4);
// Año no viciesto y es febrero y el dia es mayor a 28
if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { tfecha_nacimiento=tfecha_nacimiento.substr(0,2)+"/"; }
}
return (tfecha_nacimiento);
}
*/
function Validar(form)
{
if (form.numero_proyecto.value == "")
{ alert("Por favor ingrese su Numero del Proyecto");
form.numero_proyecto.focus();
return false;
}
if (form.nombre_proyecto.value == "")
{
alert("Por favor ingrese su Nombre");
form.nombre_proyecto.focus();
return false;
}
if (form.objetivo_proyecto.value == "")
{
alert("Por favor ingrese el Objetivo del Proyecto");
form.objetivo_proyecto.focus();
return false;
}
if (form.coordinador_proyecto.value == "")
{
alert("Por favor ingrese el nombre del coordinador de proyecto");
form.coordinador_proyecto.focus();
return false;
}
if (form.direccion_proyecto.value == "")
{
alert("Por favoringrese la Direccion del proyecto");
form.direccion_proyecto.focus();
return false;
}
return true;
form.submit();
}
</script>
</head>
<body>
<div id="container">
<form action="ingresar_proyecto.php" method="post" class="niceform" onsubmit="return validar(this.form)" name="Formvalidar(form)">
<fieldset>
<legend>Ingresar Nuevo Proyecto</legend>
<dl>
<dt>
<label for="numero_proyecto">Numero del proyecto</label>
</dt>
<dd><input type="text" name="numero_proyecto" id="numero_proyecto" size="32" maxlength="128" onClick="Validar(this.form)" onsubmit="return validar(this.form)" /></dd>
...
1 respuesta
Respuesta de krlosnow
1