Lo primero felicitar a la gente del foro, moderadores, webmaster, usuarios etc... por prestar sus conocimientos a la gente que los necesita :D como yo en estos momentos jejeje
Me di una vuelta por la busqueda del foro pero no encontre una contestacion clara a mi duda, no se si por que busque mal o porque no esta contestada, os la explico:
He realizado un formulario enlazado a bases de datos, hasta aqui todo bien, envias el formulario, guarda los datos en los campos correspondientes, el problema fue cuando incorpore unos cuantos IF's para que no me manden formularios con campos en blanco, letras donde deberian ir numeros etc... aqui os abjunto el formulario:
Cita:
Como ya vereis lo que quiero es que si un campo obligatorio no esta rellenado o es incorrecto vuelva a mostar el formulario indicando donde se encuentran los errores y sin borrar los campos que esten bien rellenados, eso funciona pero el problema es que no logro que si existen errores no lo envie, y que si no los hay no lo envie.<html>
<head>
<title>::Formulario</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$mostrarFormulario = FALSE;
$errorNombre="";
$errorApellidos="";
$errorDireccion="";
$errorCodigo="";
$errorEntidadFacturacion ="";
$nombre="";
$apellidos="";
$direccion="";
$codigoPostal="";
$tlf="";
$fax="";
$entidadFacturacion="";
$entidadDireccion="";
$entidadCodigoPostal="";
$nif="";
if (count($_POST) == 0 ) {
$mostarformulario = TRUE;
}else{
$nombre = $_POST["nombre"];
$apellidos = $_POST["apellidos"];
$direccion = $_POST["direccion"];
$codigoPostal = $_POST["codigoPostal"];
$entidadFacturacion = $_POST["entidadFacturacion"];
if ($nombre == "") {
$errorNombre = " ERROR Campo Obligatorio";
$mostarformulario = TRUE;
}
if ($apellidos == "") {
$errorApellidos = " ERROR Campo Obligatorio";
$mostarformulario = TRUE;
}
if ($direccion == "") {
$errorDireccion = " ERROR Campo Obligatorio";
$mostarformulario = TRUE;
}
if (is_numeric ($codigoPostal) == FALSE) {
$errorCodigo = " ERROR Campo Obligatorio";
$mostarformulario = TRUE;
$codigoPostal = "";
}
if ($entidadFacturacion == "") {
$errorEntidadFacturacion = " ERROR Campo Obligatorio";
$mostarformulario = TRUE;
}
}
if ($mostarformulario == TRUE) {
?>
<form action="insertarDatos.php" method="post">
<font color="#FF0000">* </font>Nombre: <input type="text" name="nombre" size="20" maxlength="20" value="<? echo $nombre; ?>"><? echo $errorNombre; ?>
<br>
<font color="#FF0000">* </font>Apellidos: <input type="text" name="apellidos" size="40" maxlength="40" value="<? echo $apellidos; ?>"><? echo $errorApellidos; ?>
<br>
<font color="#FF0000">* </font>Dirección: <input type="text" name="direccion" size="50" maxlength="50" value="<? echo $direccion; ?>"><? echo $errorDireccion; ?>
<br>
<font color="#FF0000">* </font>Codigo Postal: <input type="text" name="codigoPostal" size="5" maxlength="5" value="<? echo $codigoPostal; ?>"><? echo $errorCodigo; ?>
<br>
<font color="#FF0000">* </font>Telefono: <input type="text" name="tlf" size="9" maxlength="9">
<br>
Fax: <input type="text" name="fax" size="12" maxlength="12">
<br>
<font color="#FF0000">* </font>Entidad de facturación: <input type="text" name="entidadFacturacion" size="50" maxlength="50" value="<? echo $entidadFacturacion; ?>"><? echo $errorEntidadFacturacion; ?>
<br>
Dirección: <input type="text" name="entidadDireccion" size="50" maxlength="50">
<br>
Codigo Postal: <input type="text" name="entidadCodigoPostal" size="5" maxlength="5">
<br>
<font color="#FF0000">* </font>N.I.F. / C.I.F. : <input type="text" name="nif" size="8" maxlength=""> Letra: <input type="text" size="1" maxlength="1">
<br>
<input type="submit">
</form>
<?php
}
?>
</body>
</html>
<head>
<title>::Formulario</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$mostrarFormulario = FALSE;
$errorNombre="";
$errorApellidos="";
$errorDireccion="";
$errorCodigo="";
$errorEntidadFacturacion ="";
$nombre="";
$apellidos="";
$direccion="";
$codigoPostal="";
$tlf="";
$fax="";
$entidadFacturacion="";
$entidadDireccion="";
$entidadCodigoPostal="";
$nif="";
if (count($_POST) == 0 ) {
$mostarformulario = TRUE;
}else{
$nombre = $_POST["nombre"];
$apellidos = $_POST["apellidos"];
$direccion = $_POST["direccion"];
$codigoPostal = $_POST["codigoPostal"];
$entidadFacturacion = $_POST["entidadFacturacion"];
if ($nombre == "") {
$errorNombre = " ERROR Campo Obligatorio";
$mostarformulario = TRUE;
}
if ($apellidos == "") {
$errorApellidos = " ERROR Campo Obligatorio";
$mostarformulario = TRUE;
}
if ($direccion == "") {
$errorDireccion = " ERROR Campo Obligatorio";
$mostarformulario = TRUE;
}
if (is_numeric ($codigoPostal) == FALSE) {
$errorCodigo = " ERROR Campo Obligatorio";
$mostarformulario = TRUE;
$codigoPostal = "";
}
if ($entidadFacturacion == "") {
$errorEntidadFacturacion = " ERROR Campo Obligatorio";
$mostarformulario = TRUE;
}
}
if ($mostarformulario == TRUE) {
?>
<form action="insertarDatos.php" method="post">
<font color="#FF0000">* </font>Nombre: <input type="text" name="nombre" size="20" maxlength="20" value="<? echo $nombre; ?>"><? echo $errorNombre; ?>
<br>
<font color="#FF0000">* </font>Apellidos: <input type="text" name="apellidos" size="40" maxlength="40" value="<? echo $apellidos; ?>"><? echo $errorApellidos; ?>
<br>
<font color="#FF0000">* </font>Dirección: <input type="text" name="direccion" size="50" maxlength="50" value="<? echo $direccion; ?>"><? echo $errorDireccion; ?>
<br>
<font color="#FF0000">* </font>Codigo Postal: <input type="text" name="codigoPostal" size="5" maxlength="5" value="<? echo $codigoPostal; ?>"><? echo $errorCodigo; ?>
<br>
<font color="#FF0000">* </font>Telefono: <input type="text" name="tlf" size="9" maxlength="9">
<br>
Fax: <input type="text" name="fax" size="12" maxlength="12">
<br>
<font color="#FF0000">* </font>Entidad de facturación: <input type="text" name="entidadFacturacion" size="50" maxlength="50" value="<? echo $entidadFacturacion; ?>"><? echo $errorEntidadFacturacion; ?>
<br>
Dirección: <input type="text" name="entidadDireccion" size="50" maxlength="50">
<br>
Codigo Postal: <input type="text" name="entidadCodigoPostal" size="5" maxlength="5">
<br>
<font color="#FF0000">* </font>N.I.F. / C.I.F. : <input type="text" name="nif" size="8" maxlength=""> Letra: <input type="text" size="1" maxlength="1">
<br>
<input type="submit">
</form>
<?php
}
?>
</body>
</html>
¿Alguna solucion? Gracias a todos de antemano