-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathformulario.php
More file actions
70 lines (64 loc) · 2.12 KB
/
formulario.php
File metadata and controls
70 lines (64 loc) · 2.12 KB
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
66
67
68
69
70
<?php
$host = getenv('DB_HOST');
$port = getenv('DB_PORT');
$dbname = getenv('DB_NAME');
$user = getenv('DB_USER');
$password = getenv('DB_PASSWORD');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$nome = trim($_POST['nome'] ?? '');
$email = trim($_POST['email'] ?? '');
$atualizacoes = isset($_POST['atualizacoes']);
if (empty($nome) || empty($email) || !$atualizacoes) {
echo "Por favor, preencha todos os campos obrigatórios.";
exit;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Email inválido.";
exit;
}
try {
$pdo = new PDO("pgsql:host=$host;port=$port;dbname=$dbname", $user, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare("INSERT INTO formulario (nome, email) VALUES (:nome, :email)");
$stmt->execute([':nome' => $nome, ':email' => $email]);
// Exibe mensagem com contagem regressiva
echo '<!DOCTYPE html>
<html>
<head>
<title>Enviado</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; padding: 50px; }
#countdown { font-size: 24px; color: #E38417; }
</style>
</head>
<body>
<p>Dados enviados com sucesso!</p>
<p>Você será redirecionado em <span id="countdown">3</span> segundos...</p>
<script>
let timeLeft = 3;
const countdownElement = document.getElementById("countdown");
const timer = setInterval(() => {
timeLeft--;
countdownElement.textContent = timeLeft;
if (timeLeft <= 0) {
clearInterval(timer);
window.location.href = "https://padariafamiliasantos.onrender.com/";
}
}, 1000);
</script>
</body>
</html>';
exit;
} catch (PDOException $e) {
if ($e->getCode() == '23505') {
echo "Esse email já está cadastrado.";
} else {
echo "Erro ao conectar ou inserir dados: " . $e->getMessage();
}
exit;
}
} else {
echo "Acesso inválido.";
exit;
}
?>