Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Jun 25th, 2010 | Syntax: PHP | Size: 1.91 KB | Hits: 245 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. <?php
  2. /**
  3.  * Verifica se existe um método post
  4.  */
  5. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  6.     //inclui a classe Validacao.class.php
  7.     require("Validacao.class.php");
  8.     //Instancia a classe Validacao
  9.     $val = new Validacao();
  10.     //Guarda a Variavel Global $_POST
  11.     $p = $_POST;
  12.     //Chama o Método set() atribuitndo o valor e nome do campo, e a verificação
  13.     $val->set($p['nome'], 'Nome')->obrigatorio();
  14.     $val->set($p['email'], 'E-mail')->email();
  15.     $val->set($p['telefone'], 'Telefone')->tel();
  16.     //Verifica se ocorreu algum erro
  17.     if ($val->validar()) {
  18.        
  19.         echo 'Passou';
  20.     } else {
  21.         //se ocorreu algum erro, lista todos os erros
  22.         foreach ($val->getErrors() as $erro) {
  23.             echo "$erro <br />";
  24.         }
  25.     }
  26. }
  27. ?>
  28.  
  29. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  30. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br" lang="pt-br">
  31.     <head>
  32.         <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  33.         <title>Teste Formulário</title>
  34.         <link rel="stylesheet" type="text/css" href="css/style.css" media="all" />
  35.     </head>
  36.     <body>
  37.         <form action="" method="post">
  38.             <fieldset>
  39.                 <legend>Formulário</legend>
  40.                 <label>
  41.                     <span>Nome :</span>
  42.                     <input type="text" name="nome" size="40"/>
  43.                 </label>
  44.  
  45.                 <label>
  46.                     <span>Email :</span>
  47.                     <input type="text" name="email" size="40"/>
  48.                 </label>
  49.  
  50.                 <label>
  51.                     <span>Telefone :</span>
  52.                     <input type="text" name="telefone" size="40"/>
  53.                 </label>
  54.  
  55.                 <input type="submit" value="Enviar" />
  56.  
  57.             </fieldset>
  58.         </form>
  59.     </body>
  60. </html>