-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo.php
More file actions
52 lines (48 loc) · 1.5 KB
/
todo.php
File metadata and controls
52 lines (48 loc) · 1.5 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
<?php session_start(); // Inicia a sessão.
// Se a variável tarefas não existe, crie.
if (!isset($_SESSION['tarefas'])) {
$_SESSION['tarefas'] = array();
}
// Se esta recebendo uma nova tarefa do formulário, adicione na sessão.
if (!empty($_POST["tarefa"])) {
$_SESSION['tarefas'][] = $_POST["tarefa"];
}
// Removendo a tarefa.
if (isset($_GET['tarefa_id'])) {
unset($_SESSION['tarefas'][(int)$_GET['tarefa_id']]);
header("Location: todo.php"); // Redireciona para a mesma página para "limpar" o GET.
}
?>
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Lista de tarefas</title>
<link href="estilo.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>Lista de tarefas</h1>
<h2>Adicionar tarefa</h2>
<form method="post" action="todo.php">
<label for="tarefa">Tarefa:</label>
<input type="text" name="tarefa" id="tarefa" placeholder="Escreva sua tarefa aqui" required>
<button name="adicionar">Adicionar Tarefa</button>
</form>
<br>
<h2>Tarefas a fazer</h2>
<table>
<tr>
<th>id</th>
<th>tarefa</th>
<th>finalizar</th>
</tr>
<?php foreach ($_SESSION['tarefas'] as $chave => $valor): ?>
<tr>
<td><?php echo $chave; ?></td>
<td><?php echo $valor; ?></td>
<td><a href="todo.php?tarefa_id=<?php echo $chave; ?>">❌</a></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>