Ola soy nueva en este foro y toy aciendo un kursillo d php y stoy probando a acer formularios y tengo este codigo como ejemplo k me venia en un manual:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>New Document</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
<FORM ACTION="ejer8.php" METHOD="POST" NAME="formu">
<table width="550" cellpadding="0" cellspacing="0" height="80%" border="0" align="center">
<TR>
<TD colspan="4"><BR>FORMULARIO DE INSCRIPCIÓN</td>
</tr>
<TR>
<TD colspan="4">Introduce tus datos personales. * Los campos con asterisco son obligatorios</td>
</tr>
<TR>
<TD height="10">Nombre*: </TD><TD colspan="3"><INPUT TYPE="text" NAME="nombre"></TD>
</TR>
<TR>
<TD height="10">Apellidos*: </TD><TD colspan="3"><INPUT TYPE="text" NAME="apellidos" size="50"></TD>
</TR>
<tr>
<td>Dirección*:</td><td colspan="3"><input name="direccion" type="text" size="50"></td>
</tr>
<tr>
<td width="30" height="10">Población*:</td><td><input name="poblacion" type="text"></td>
<td align="right" width="30">Provincia:</td><td><select name="provincia">
<option value="Alava">Álava</option>
<option value="Burgos">Burgos</option>
<option value="La Rioja">La Rioja</option>
<option value="Madrid">Madrid</option>
</select></td>
</tr>
<tr>
<td width="30">C.P.:</td><td><input name="cp" type="text"></td>
<td align="right" width="30">DNI*:</td><td><input name="dni" type="text"></td>
</tr>
<tr>
<td width="30" height="10">Teléfono*:</td><td><input name="telefono" type="text"></td>
<td align="right" width="30">Email:</td><td><input name="email" type="text"></td>
</tr>
<tr>
<td colspan="4" align="center">
<INPUT TYPE="submit" value="enviar" name="envia">
</td>
</tr>
</TABLE>
</FORM>
</body>
</html>
<?php
if(isset($_POST['nombre']))
{
if($_POST['nombre']=='' || $_POST['apellidos']=='' || $_POST['direccion']=='' || $_POST['poblacion']=='' || $_POST['telefono']=='' || $_POST['dni']=='')
echo "<br><br><h2> Los campos nombre, apellidos, direccion, poblacion, telefono y DNI son obligatorios</h2>";
else
{
$longitud=strlen($_POST['nombre']);
if($longitud < 3)
echo "<br><b> El nombre debe tener por lo menos 3 caracteres</b>";
$longitud=strlen($_POST['apellidos']);
if($longitud < 3)
echo "<br><b> Los apellidos deben tener por lo menos 3 caracteres</b>";
$longitud=strlen($_POST['direccion']);
if($longitud < 5)
echo "<br><b> La dirección debe tener por lo menos 5 caracteres</b>";
$longitud=strlen($_POST['poblacion']);
if($longitud < 2)
echo "<br><b> La población debe tener por lo menos 2 caracteres</b>";
$longitud=strlen($_POST['cp']);
if($longitud !=5)
echo "<br><b> El C.P. debe tener 5 caracteres</b>";
$longitud=strlen($_POST['dni']);
if($longitud < 8)
echo "<br><b> El dni debe tener por lo menos 8 numeros</b>";
$longitud=strlen($_POST['telefono']);
if($longitud <9)
echo "<br><b> El telefono debe tener por lo menos 9 numeros</b>";
$arroba=substr_count($_POST['email'],"@") ;
$caracteres=strstr($_POST['email'],'.');
$longitud=strlen($caracteres);
if($arroba!=1 && ($longitud!=3 || $longitud!=4))
echo "<br><b> Email incorrecto </b>";
}
?>
Y serie aceptable utilizar un switch ????? alguien save sobre ste tema
Y ota kosa sobre este mismo formulario x ejemplo y kisiera k muestre x pantalla el formulario y oto k se encargue d la validacion d los datos, sabrian km se aria xa ver un ejemplo???