-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidacao-e-sanitizaçao.php
65 lines (55 loc) · 2.23 KB
/
validacao-e-sanitizaçao.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
/*Sanitizaçao
* Funçoes (filter_input - filter_var)
* FILTER_SANITIZE_SPECIAL_CHARS
* FILTER_SANITIZE_NUMBER_INT
* FILTER_SANITIZE_EMAIL
* FILTER_SANITIZE_URL
*
*/
if(isset($_POST['enviar-formulario'])){
echo "enviou <br><pre>";
//var_dump($_POST);
$erros = array();
$nome = filter_input(INPUT_POST, 'nome', FILTER_SANITIZE_SPECIAL_CHARS);
$idade = filter_input(INPUT_POST, 'idade', FILTER_SANITIZE_NUMBER_INT);
if(!filter_var($idade, FILTER_VALIDATE_INT)){
$erros[] = "Idade precisa ser em numeros";
}
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$erros[] = "Email incorreto";
}
$url = filter_input(INPUT_POST, 'url', FILTER_SANITIZE_URL);
if(!filter_var($url, FILTER_VALIDATE_URL)){
$erros[] = "URL incorreto";
}
if(!empty($erros)){
foreach ($erros as $erro){
echo "<li> $erro </li>";
}
}else{
echo "Parabens, seus dados estao corretos!";
}
echo "</pre>";
}
?>
<fieldset>
<legend>Cadastro</legend>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<label>Nome: </label> <input type="text" name="nome" value="" /><br>
<label>idade: </label> <input type="text" name="idade" value="" /><br>
<label>E-mail: </label> <input type="text" name="email" value="" /><br>
<label>URL: </label> <input type="text" name="url" value="" /><br>
<button type="submit" name="enviar-formulario" > Enviar </button> <br
</form>
</fieldset>
</body>
</html>