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
| <?php
// Initialisation de $users
// Contient les utilisateurs précédemment soumis
if (isset($_POST['users'])) {
$users = $_POST['users'];
} else {
$users = [];
}
// Traitement du formulaire
if (isset($_POST['nom'], $_POST['prenom'], $_POST['mail'], $_POST['mdp'])) {
// Ajoute l'utilisateur soumis au tableau des utilisateurs
$users[] = [
'nom' => $_POST['nom'], 'prenom' => $_POST['prenom'],
'mail' => $_POST['mail'], 'mdp' => $_POST['mdp'],
];
}
?>
<form method="post">
<input type="text" name="nom" placeholder="Nom">
<input type="text" name="prenom" placeholder="Prénom">
<input type="email" name="mail" placeholder="E-mail">
<input type="password" name="mdp" placeholder="Mot de passe">
<button type="submit">Envoyer</button>
<?php foreach ($users as $i => $user): ?>
<input type="hidden" name="users[<?= $i ?>][nom]" value="<?= htmlspecialchars($user['nom']) ?>">
<input type="hidden" name="users[<?= $i ?>][prenom]" value="<?= htmlspecialchars($user['prenom']) ?>">
<input type="hidden" name="users[<?= $i ?>][mail]" value="<?= htmlspecialchars($user['mail']) ?>">
<input type="hidden" name="users[<?= $i ?>][mdp]" value="<?= htmlspecialchars($user['mdp']) ?>">
<?php endforeach ?>
<p>Table des utilisateurs</p>
<?php if (empty($users)): ?>
<p>Pas encore d'utilisateurs soumis !</p>
<?php else: ?>
<table>
<?php foreach ($users as $i => $user): ?>
<tr>
<td><?= $i ?></td>
<td><?= htmlspecialchars($user['nom']) ?></td>
<td><?= htmlspecialchars($user['prennom']) ?></td>
<td><?= htmlspecialchars($user['mail']) ?></td>
<td><?= htmlspecialchars($user['mdp']) ?></td>
</tr>
<?php endforeach ?>
</table>
<?php endif ?>
</form> |
Partager