Untitled
By: a guest | Jun 25th, 2010 | Syntax:
PHP | Size: 1.91 KB | Hits: 245 | Expires: Never
<?php
/**
* Verifica se existe um método post
*/
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//inclui a classe Validacao.class.php
require("Validacao.class.php");
//Instancia a classe Validacao
$val = new Validacao();
//Guarda a Variavel Global $_POST
$p = $_POST;
//Chama o Método set() atribuitndo o valor e nome do campo, e a verificação
$val->set($p['nome'], 'Nome')->obrigatorio();
$val->set($p['email'], 'E-mail')->email();
$val->set($p['telefone'], 'Telefone')->tel();
//Verifica se ocorreu algum erro
if ($val->validar()) {
echo 'Passou';
} else {
//se ocorreu algum erro, lista todos os erros
foreach ($val->getErrors() as $erro) {
echo "$erro <br />";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br" lang="pt-br">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>Teste Formulário</title>
<link rel="stylesheet" type="text/css" href="css/style.css" media="all" />
</head>
<body>
<form action="" method="post">
<fieldset>
<legend>Formulário</legend>
<label>
<span>Nome :</span>
<input type="text" name="nome" size="40"/>
</label>
<label>
<span>Email :</span>
<input type="text" name="email" size="40"/>
</label>
<label>
<span>Telefone :</span>
<input type="text" name="telefone" size="40"/>
</label>
<input type="submit" value="Enviar" />
</fieldset>
</form>
</body>
</html>