web/aleatoire.php

64 lines
1.7 KiB
PHP
Executable File

<?php include "inc/debut.php";
head("aleatoire.php"); ?>
<h1>
Générateur Aléatoire
</h1>
<?php if (!isset($_GET['etape'])) { ?>
<form method="post" action="aleatoire.php?etape=deux">
Bienvenue dans ce programme de choix aléatoire.<br>
Il permet de tirer au sort une possibilité parmis plusieurs.<br>
1) Choisissez parmi combien de possibilités vous voulez tirer au sort.<br>
2) Donner un nom à chaque possibilité.<br>
3) Le programme vous donnera aléatoirement un des noms.<br>
<input type="number" name="nombreDeChoix" step="1" value="3" min="2" max="100" required>
<br>
<input type="submit" value="Suivant >" class="button special big icon"/>
</form>
<?php
} else if (isset($_GET['etape']) AND $_GET['etape'] == "deux") { ?>
<form method="post" action="aleatoire.php?etape=trois">
<?php $i = 0;
while ($i < $_POST['nombreDeChoix']) {
$valeur[$i] = $i; ?>
Choix <?php echo $i + 1; ?> : <input type="text" name="<?php echo $valeur[$i]; ?>" required>
<br>
<?php
$i++;
}
?>
<input type="hidden" name="nombreDeChoixPasse" value="<?php echo htmlspecialchars($_POST['nombreDeChoix']); ?>" />
<input type="submit" value="Générer" class="button special big"/>
</form>
<?php } else if (isset($_GET['etape']) AND $_GET['etape'] == "trois") {
$choisi = mt_rand(0, $_POST['nombreDeChoixPasse']); ?>
La valeur choisie aléatoirement est <?php echo htmlspecialchars($_POST[$choisi]); ?>, numéro <?php echo htmlspecialchars($choisi); ?>
<?php } else { ?>
Erreur
<?php } ?>
<?php include "inc/footer.php"; ?>