-
Notifications
You must be signed in to change notification settings - Fork 0
/
inscreva-se.php
138 lines (117 loc) · 5.14 KB
/
inscreva-se.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
require_once 'autor_class.php';
require_once 'professor_class.php';
$aluno = new Aluno("UFBNA", "localhost", "root", "123456");
$professor = new Professor("UFBNA", "localhost", "root", "123456");
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- icons -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="./style/inscreva-se.css">
<!-- components -->
<link rel="stylesheet" href="./style/reset.css">
<link rel="stylesheet" href="./components/header.css">
<link rel="stylesheet" href="./components/nav.css">
<link rel="stylesheet" href="./components/footer.css">
<title>Formulários</title>
</head>
<body>
<?php include_once './components/header.php' ?>
<main>
<div class="form-container">
<div class="toggle-buttons">
<div>
<button id="aluno-button" class="active">Aluno</button>
<button id="professor-button">Professor</button>
</div>
</div>
<form id="aluno-form" class="active-form" action="inscreva-se.php" method="POST">
<h2>Formulário do Aluno</h2>
<div>
<input name="aluno-name" type="text" placeholder="Nome">
<input name="aluno-email" type="email" placeholder="E-mail">
</div>
<button class="button-enviar" type="submit">Enviar</button>
</form>
<form id="professor-form" action="inscreva-se.php" method="POST">
<h2>Formulário do Professor</h2>
<div>
<input name="professor-name" type="text" placeholder="Nome">
<input name="professor-email" type="email" placeholder="E-mail">
</div>
<button class="button-enviar" type="submit">Enviar</button>
</form>
<?php
require_once('./autor_class.php');
if ($_SERVER['REQUEST_METHOD'] === "POST") {
if (isset($_POST['aluno-name'])) {
$nome = $_POST['aluno-name'];
$email = $_POST['aluno-email'];
try {
if ($aluno->inserirAluno($nome, $email) == true) {
echo "<script>
setTimeout(function() {
window.location.href = 'main.php';
}, 1000);
</script>";
} else {
echo "<h3>insira todos os campos</h3>";
}
exit();
} catch (PDOException $e) {
echo "Erro no BD " . $e->getMessage();
exit();
} catch (Exception $e) {
echo "Erro genérico " . $e->getMessage();
}
} elseif (isset($_POST['professor-name'])) {
$nome = $_POST['professor-name'];
$email = $_POST['professor-email'];
try {
$professor->inserirProfessor($nome, $email);
echo "<script>
setTimeout(function() {
window.location.href = 'main.php';
}, 1000);
</script>";
exit();
} catch (PDOException $e) {
echo "Erro no BD " . $e->getMessage();
exit();
} catch (Exception $e) {
echo "Erro genérico " . $e->getMessage();
}
} else {
echo "deu pau :/";
}
}
?>
</div>
</main>
<?php include_once './components/footer.php' ?>
<script>
const alunoButton = document.getElementById('aluno-button');
const professorButton = document.getElementById('professor-button');
const alunoForm = document.getElementById('aluno-form');
const professorForm = document.getElementById('professor-form');
const buttonEnviar = document.querySelectorAll('.button-enviar');
alunoButton.addEventListener('click', () => {
alunoForm.classList.add('active-form');
professorForm.classList.remove('active-form');
alunoButton.classList.add('active');
professorButton.classList.remove('active');
});
professorButton.addEventListener('click', () => {
professorForm.classList.add('active-form');
alunoForm.classList.remove('active-form');
professorButton.classList.add('active');
alunoButton.classList.remove('active');
});
</script>
</body>
</html>