Advertisement
mvsp

Aula 35

Jul 5th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <html>
  2. <body>
  3.  
  4.  
  5. <?php
  6. if(isset($_POST['enviar-formulario'])):
  7.     //array de erros
  8.     $erros = array();
  9.  
  10.     //Validações
  11.     if(!$idade = filter_input(INPUT_POST, 'idade', FILTER_VALIDATE_INT)):
  12.         $erros[] = "Idade precisa ser um inteiro";
  13.     endif;
  14.  
  15.     if(!$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)):
  16.         $erros[] = "E-mail invalido";
  17.     endif;
  18.  
  19.     if(!$peso = filter_input(INPUT_POST, 'peso', FILTER_VALIDATE_FLOAT)):
  20.         $erros[] = "Peso precisa ser um float";
  21.     endif;
  22.  
  23.     if(!$ip = filter_input(INPUT_POST, 'ip', FILTER_VALIDATE_IP)):
  24.         $erros[] = "IP inválido";
  25.     endif;
  26.  
  27.     if(!$url = filter_input(INPUT_POST, 'url', FILTER_VALIDATE_URL)):
  28.         $erros[] = "URL inválida";
  29.     endif;
  30.  
  31.     //exibindo mensagens de erro
  32.     if (!empty($erros)):
  33.         foreach($erros as $erro){
  34.             echo "<li> $erro </li>";
  35.         }
  36.     else:
  37.         echo "Seus dados estão corretos.";
  38.     endif;
  39.  
  40. endif;
  41. ?>
  42.  
  43.  
  44. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method ="POST"><br>
  45. Idade: <input type="text" name="idade"><br>
  46. Email: <input type="email" name="email"><br>
  47. Peso: <input type="text" name="peso"><br>
  48. IP: <input type="text" name="ip"><br>
  49. URL: <input type="text" name="URL"><br>
  50. <button type="submit" name = "enviar-formulario">Enviar<br>
  51. </form>
  52.  
  53.  
  54. </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement