Ejercicio 21
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Cuestionario</title>
</head>
<body>
<h2>Cuestionario</h2>
<form action="Tratamiento.php" method="post">
<label>Nombre:</label>
<input type="text" name="nombre"><br><br>
<label>Edad:</label>
<input type="number" name="edad" min="0" max="120"><br><br>
<label>Color favorito:</label>
<select name="color" required>
<option value="Rojo">Rojo</option>
<option value="Azul">Azul</option>
<option value="Verde">Verde</option>
<option value="Amarillo">Amarillo</option>
</select><br><br>
<input type="submit" value="Enviar">
</form>
</body>
</html>
Tratamiento
<?php
/* @author Jesús Temprano Gallego
* @since 20/10/2025
*/
// Obtenemos los valores del formulario usando $_REQUEST (funciona con GET o POST)
$nombre = $_REQUEST['nombre'] ?? '';
$edad = $_REQUEST['edad'] ?? '';
$color = $_REQUEST['color'] ?? '';
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Resultados</title>
</head>
<body>
<h2>Resultados del Cuestionario</h2>
<!-- Mostramos los datos recibidos del formulario -->
<p><strong>Nombre:</strong> <?php echo $nombre; ?></p>
<p><strong>Edad:</strong> <?php echo $edad; ?></p>
<p><strong>Color favorito:</strong> <?php echo $color; ?></p>
</body>
</html>