Created
August 14, 2019 11:16
-
-
Save joseolinda/bbf92928e9cb5dae338c602c42591ec2 to your computer and use it in GitHub Desktop.
Arquivos para validação de formulário. Os arquivos "variaveis.php" e "funcoes.php" devem ser criados na pasta "validar". Já o arquivo "mostar.php" deverá ser criado na pasta "pedido".
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
<?php | |
// Limpar dados para evitar possíveis scripts | |
function __e($input) { | |
$input = trim($input); | |
$input = stripslashes($input); | |
$input = htmlspecialchars($input); | |
return $input; | |
} | |
function limparVetor($varPost) { | |
$arrayLimpo = []; | |
foreach ($varPost as $indice => $valor) { | |
$arrayLimpo[$indice] = $valor; | |
} | |
return $arrayLimpo; | |
} | |
// Verificar se o formulário foi enviado | |
function formEnviado($postArray) { | |
global $dados; | |
if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
// Limpar post | |
$dados = limparVetor($postArray); | |
return true; | |
} else { | |
header('Location: ../index.php'); | |
die(); | |
} | |
} | |
// Criar mensagem de erro | |
function gerarMensagensErro($postArray) { | |
global $mensagem_erro; | |
if ($postArray["prato_principal"]) { | |
$mensagem_erro["prato_principal_vazio"] = "Informe um prato principal"; | |
} | |
} |
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
<?php | |
// Importar funcoes e variaveis | |
require_once ( "../validar/variaveis.php" ); | |
require_once ( "../validar/funcoes.php" ); | |
// Validar se o usuário chegou a página via formulário | |
// e limpar post | |
formEnviado($_POST); | |
// | |
gerarMensagensErro($dados); | |
var_dump( $dados ); | |
var_dump( $mensagem_erro ); | |
?> |
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
<?php | |
$dados = []; | |
$mensagem_erro = []; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment