-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
178 lines (144 loc) · 7.73 KB
/
index.php
File metadata and controls
178 lines (144 loc) · 7.73 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<!-- Meta tags Obrigatórias -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="style.css">
<title>Projeto TecWeb2</title>
</head>
<body>
<div class="container">
<div class="row justify-content-center mb-3">
<h1>Projeto TecWeb2</h1>
</div>
</div>
<div class="container">
<div class="row justify-content-center mb-5">
<form action="" method="GET" class="col-md-10 form_content">
<div class="row mb-3">
<div class="col-md-7">
<div class="form-group">
<label for="nome">Nome: </label>
<input type="text" class="form-control" name="nome" id="nome" aria-describedby="nome" placeholder="Seu nome">
</div>
<div class="form-group">
<label for="senha">Idade:</label>
<input type="text" class="form-control" name="idade" id="idade" placeholder="Idade">
</div>
<span>Tem filhos:</span>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="radioOptions" id="radio_nao" value="0">
<label class="form-check-label" for="radio_nao">Não</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="radioOptions" checked="checked" id="radio_sim" value="1">
<label class="form-check-label" for="radio_sim">Sim</label>
</div>
</div>
<div class="col-md-2 text-center mt-3">
<button type="submit" class="btn btn-primary mt-2">Enviar</button>
</div>
</div>
<div class="row justify-content-center">
<div class="col-md-8 filhos_group_content">
<div class="filhos_group mb-2">
<div class="filho_input_group">
<label class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" >Nome:</span>
</div>
<input type="text" class="form-control" name="nome_filho" placeholder="Nome do filho" aria-label="nome_filho" aria-describedby="nome_filho">
</label>
<label class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Idade:</span>
</div>
<input type="text" class="form-control" name="idade_filho" placeholder="Idade do filho" aria-label="idade_filho" aria-describedby="idade_filho">
</label>
</div>
<div class="filho_btn_group">
<a href="#" class="btn btn-success mb-2 btn_adicionar">Adicionar</a>
<button class="btn btn-danger mb-2 btn_excluir">Excluir</button>
</div>
</div>
</div>
</div>
</form>
</div>
<?php
$nome = isset($_GET['nome']) ? $_GET['nome'] : "";
$idade = isset($_GET['idade']) ? $_GET['idade'] : "";
$nome_filho = isset($_GET['nome_filho']) ? $_GET['nome_filho'] : "";
$idade_filho = isset($_GET['idade_filho']) ? $_GET['idade_filho'] : "";
if(!isset($_SESSION['dados'])) {
$_SESSION['dados'] = array(); // se não foi criado ainda a variável DADOS, cria e define como um array
}
array_push($_SESSION['dados'], array(
'nome' => $nome,
'idade' => $idade,
'nome_filho' => $nome_filho,
'idade_filho' => $idade_filho
)); // adiciona os dados recebidos no array utilizando a função array_push passando um novo array com esse dados
?>
<div class="row mt-3">
<div class="col-md-12">
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">Nome</th>
<th scope="col">Idade</th>
<th scope="col">Filhos</th>
</tr>
</thead>
<tbody>
<?php
foreach ($_SESSION['dados'] as $value):
if(isset($value["radioOptions"]) && $value["radioOptions"] == 0){
$idade_filho = "Não possui filho";
}else{
$idade_filho = isset($value["nome_filho"]) ? $value["nome_filho"]." ".$value["idade_filho"] :"";
}
?>
<tr>
<td><?php if(isset($value["nome"])){ echo $value["nome"]; } ?></td>
<td><?php if(isset($value["idade"])){ echo $value["idade"]; } ?></td>
<td>
<?php if(isset($idade_filho)){ echo $idade_filho; } ?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
</div>
</div>
<!-- JavaScript (Opcional) -->
<!-- jQuery primeiro, depois Popper.js, depois Bootstrap JS -->
<script src="js/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$("#radio_nao").click(function(){
$(".filhos_group").css("display","none");
});
$("#radio_sim").click(function(){
$(".filhos_group").css("display","flex");
});
$(".btn_adicionar").click(function(){
$(".filhos_group_content").append('<div class="filhos_group mb-2"><div class="filho_input_group"><label class="input-group mb-3"><div class="input-group-prepend"><span class="input-group-text">Nome:</span></div><input type="text" class="form-control" name="nome_filho" id="nome_filho" placeholder="Nome do filho" aria-label="nome_filho" aria-describedby="nome_filho"></label><label class="input-group mb-3"><div class="input-group-prepend"><label class="input-group-text" for="idade_filho">Idade:</label></div><input type="text" class="form-control" name="idade_filho" id="idade_filho" placeholder="Idade do filho" aria-label="idade_filho" aria-describedby="idade_filho"></label></div><div class="filho_btn_group"><a href="#" class="btn btn-success mb-2 btn_adicionar">Adicionar</a><button class="btn btn-danger mb-2 btn_excluir">Excluir</button></div></div>');
});
$(".btn_excluir").click(function(){
$(".filhos_group").remove();
});
});
</script>
</body>.
</html>