Created
December 7, 2019 13:16
-
-
Save ivanelson/fbf69a0cfc224e2421ca0cfd2b0ccd67 to your computer and use it in GitHub Desktop.
index.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<title>.:: Calculadora de Massa Corporal ::.</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<link rel="stylesheet" type="text/css" media="screen" href="style.css" /> | |
<script src="main.js"></script> | |
<?php | |
// define variables and set to empty values | |
$nomeErr = $emailErr = $sexoErr = $idadeErr = $pesoErr = $alturaErr = ""; | |
$cpf = $nome = $peso = $altura = $email = $sexo = $comment = $idade = ""; | |
$valida = False; | |
if ($_SERVER["REQUEST_METHOD"] == "POST") { | |
$valida = True; | |
if (empty($_POST["nome"])) { | |
$nomeErr = "Nome é requerido"; | |
$valida = False; | |
} else { | |
$nome = test_input($_POST["nome"]); | |
// check if name only contains letters and whitespace | |
if (!preg_match("/^[a-zA-Z ]*$/",$nome)) { | |
$nomeErr = "Apenas letras e espaços são aceitos no nome"; | |
} | |
} | |
if (empty($_POST["email"])) { | |
$emailErr = "Email é requerido"; | |
} else { | |
$email = test_input($_POST["email"]); | |
// check if e-mail address is well-formed | |
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
$emailErr = "Email invalido"; | |
} | |
} | |
if (empty($_POST["comment"])) { | |
$comment = ""; | |
} else { | |
$comment = test_input($_POST["comment"]); | |
} | |
if (empty($_POST["sexo"])) { | |
$sexoErr = "Sexo é requerido"; | |
} else { | |
$sexo = test_input($_POST["sexo"]); | |
} | |
if (empty($_POST["altura"])) { | |
$alturaErr = "Altura é requerido"; | |
} else { | |
$altura = test_input($_POST["altura"]); | |
} | |
if (empty($_POST["peso"])) { | |
$pesoErr = "Peso é requerido"; | |
} else { | |
$peso = test_input($_POST["peso"]); | |
} | |
if (empty($_POST["idade"])) { | |
$idadeErr = "Idade é requerido"; | |
} else { | |
$idade = test_input($_POST["idade"]); | |
} | |
} | |
function test_input($data) { | |
$data = trim($data); | |
$data = stripslashes($data); | |
$data = htmlspecialchars($data); | |
return $data; | |
} | |
?> | |
</head> | |
<body> | |
<div class="header"> | |
<h1><img src="img/calcula-imc-icon.png" alt="Calculadora IMC" width="80" height="30"> Calculadora IMC </h1><br> | |
</div> | |
<div class="content"> | |
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> | |
<label for="lnome">Nome</label> | |
<span class="error">* <?php echo $nomeErr;?></span> | |
<input type="text" id="lnome" name="nome" value="<?php echo $nome;?>" placeholder="Digite seu nome.."> | |
<label for="lidade">Idade</label> | |
<span class="error">* <?php echo $idadeErr;?></span> | |
<input type="text" id="lidade" name="idade" placeholder="Digite sua idade.."> | |
<label for="lpeso">Peso</label> | |
<span class="error">* <?php echo $pesoErr;?></span> | |
<input type="text" id="lpeso" name="peso" placeholder="Digite seu peso.."> | |
<label for="laltura">Altura</label> | |
<span class="error">* <?php echo $alturaErr;?></span> | |
<input type="text" id="lpeso" name="altura" value="<?php echo $altura;?>" placeholder="Digite sua altura.."> | |
<label for="lsexo">Sexo</label> | |
<span class="error">* <?php echo $sexoErr;?></span> | |
<select id="lsexo" name="sexo" > | |
<option value="femino" <?php if (isset($sexo) && $sexo=="feminino") echo "selected";?> >Feminino</option> | |
<option value="masculino" <?php if (isset($sexo) && $sexo=="masculino") echo "selected";?> >Masculino</option> | |
</select> | |
<input type="submit" value="Calcula"> | |
</form> | |
<?php | |
if ($valida == True) { | |
echo "<h2>Olá fulano</h2>"; | |
echo "<p>Você precisa praticar exercicios:</p>"; | |
echo '<div class="container">'; | |
echo '<img src="img/homem-obeso.jpg" alt="Cinque Terre" width="300" height="210">'; | |
echo '<div class="bottomleft"></div>'; | |
echo "</div>"; | |
} | |
?> | |
</div> | |
<div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment