Ver Mensaje Individual
  #9 (permalink)  
Antiguo 10/03/2011, 09:20
Avatar de JoseTejada
JoseTejada
 
Fecha de Ingreso: diciembre-2007
Ubicación: Peru.Lima.Cercado.MDuarez.Granaderos172
Mensajes: 218
Antigüedad: 16 años, 5 meses
Puntos: 11
Respuesta: Campos obligatorios con php

A ver un pokito más no viene mal... cheka este a ver si te sirve:

Código PHP:
<?php
ini_set
("display_errors"1);
error_reporting(E_ALL);
$txtNombres = isset($_REQUEST["txtNombres"])?$_REQUEST["txtNombres"]:"";
$txtApellidos = isset($_REQUEST["txtApellidos"])?$_REQUEST["txtApellidos"]:"";
$txtFechaNac = isset($_REQUEST["txtFechaNac"])?$_REQUEST["txtFechaNac"]:"";

$err_Nom="";
$err_Ape="";
$err_FechaNac="";
if(isset(
$_REQUEST["btnEnviar"])) {

    
$sw true;
    if (
strlen(trim($txtNombres))==0) {
        
$err_Nom "El dato Nombres es obligatorio";
        
$sw false;
    }
    if (
strlen(trim($txtApellidos))==0) {
        
$err_Ape "El dato Apellidos es obligatorio";
        
$sw false;
    }
    if (
strlen(trim($txtFechaNac))==0) {
        
$err_FechaNac "El dato Fecha de Nacimiento es obligatorio";
        
$sw false;
    }
    if (
$sw) {
        
//AQUI SE SUPONE QUE TODOS LOS VALORES FUERON VALIDADOS CORRECTAMENTE
        //Y PUEDES EFECTUAR LO QUE NECESITAS
        
ECHO "CAMPOS LLENOS CORRECTAMENTE";
    }
}
?>
<html>
    <head>
        <title>Validando en PHP</title>
    </head>
    <body>
        <form action="">
            Nombres : <input type="text" name="txtNombres" id="txtNombres" value="<?= $txtNombres ?>" /><?= $err_Nom ?><br />
            Apellidos : <input type="text" name="txtApellidos" id="txtApellidos" value="<?= $txtApellidos ?>" /><?= $err_Ape ?><br />
            Fecha de Nacimiento : <input type="text" name="txtFechaNac" id="txtFechaNac" value="<?= $txtFechaNac ?>" /><?= $err_FechaNac ?><br />
            <input type="submit" name="btnEnviar" id="btnEnviar">
        </form>
    </body>
</html>
__________________
Un poco de Karmita no te va a hacer a ti pobre ni a mi rico... colabórame px ;)... Twitter: @josetejadauch