162 lines
5.4 KiB
PHP
162 lines
5.4 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Ejercicio 5 PHP</title>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<!-- 1.Realiza un formulario con los siguientes datos: nombre, telefono, email y mensaje.
|
|
Cuando se pulse en enviar debe mostrar la siguiente plantilla. -->
|
|
|
|
<h2>Formulario de contacto</h2>
|
|
<form action="" method="post">
|
|
<label for="nombre">Nombre:</label>
|
|
<input type="text" id="nombre" name="nombre">
|
|
<br>
|
|
<label for="telefono">Teléfono:</label>
|
|
<input type="tel" id="telefono" name="telefono">
|
|
<br>
|
|
<label for="email">Email:</label>
|
|
<input type="email" id="email" name="email">
|
|
<br>
|
|
<label for="mensaje">Mensaje:</label>
|
|
<br>
|
|
<textarea id="mensaje" name="mensaje" rows="5" cols="30"></textarea>
|
|
<br>
|
|
<input type="submit" value="Enviar">
|
|
<br>
|
|
<br>
|
|
</form>
|
|
|
|
<?php
|
|
// Verificamos si el formulario fue enviado
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
if (isset($_POST["nombre"]) && isset($_POST["email"]) && isset($_POST["telefono"]) && isset($_POST["mensaje"])) {
|
|
echo "Hola {$_POST["nombre"]}! <br>Te voy a enviar span a {$_POST["email"]} y te llamare de madrugada al {$_POST["telefono"]} <br>";
|
|
echo "Para decirte: <br>";
|
|
echo $_POST["mensaje"];
|
|
echo '<br>';
|
|
echo "Enviado desde un Iphone";
|
|
}
|
|
}
|
|
?>
|
|
|
|
|
|
<!-- 2. ¿Quién saca al perro?
|
|
Escribe en un textarea una lista de nombres.
|
|
Cuando pulses un botón debes mostrar un nombre aleatorio. (Será el encargado de sacar al perro)
|
|
Muestra la respuesta con la siguiente plantilla: nombre sacará el perro a pasear. -->
|
|
|
|
<form action="" method="post">
|
|
<label for="listaPerro">Lista de nombres:</label>
|
|
<br>
|
|
<textarea id="listaPerro" name="listaPerro" rows="5" cols="30"></textarea>
|
|
<br>
|
|
<input type="submit" value="Enviar">
|
|
<br>
|
|
<br>
|
|
</form>
|
|
<?php
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
|
|
if (isset($_POST["listaPerro"])) {
|
|
$nombres = $_POST['listaPerro'];
|
|
$listaNombres = explode("\n", $nombres);
|
|
$indiceAleatorio = rand(0, count($listaNombres) - 1);
|
|
$nombreElegido = $listaNombres[$indiceAleatorio];
|
|
echo $nombreElegido;
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!-- 3.Adivinanza: -->
|
|
<form action="" method="post">
|
|
<label for="respuesta">Adivinanza: <br>
|
|
“Esta cosa se devora a todas las cosas; <br>
|
|
Pájaros, bestias, árboles, flores;<br>
|
|
Carcome el hierro, muerde el acero;<br>
|
|
Muele duras piedras y las reduce a harina;<br>
|
|
Mata al rey, arruina la ciudad,<br>
|
|
Y derriba a la montaña.” <br></label>
|
|
<input type="text" name="respuesta" id="respuesta">
|
|
<br>
|
|
<input type="submit" value="Comprobar respuesta">
|
|
</form>
|
|
|
|
<?php
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
if (isset($_POST["respuesta"])) {
|
|
$resp = $_POST["respuesta"];
|
|
if ($resp === "Tiempo") {
|
|
echo "Enhorabuena!!! Acertaste";
|
|
} else {
|
|
echo "Lo siento, la respuesta no es correcta";
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<br>
|
|
<br>
|
|
<!-- 4.Calculadora de IVA
|
|
Debemos crear una calculadora de IVA, el usuario introduce el precio en un input y le damos el precio con IVA. -->
|
|
<form action="" method="post">
|
|
<label for="precio">Introduce el precio:</label>
|
|
<input type="text" name="precio" id="precio">
|
|
<input type="submit" value="Calcula el precio con iva">
|
|
</form>
|
|
<?php
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
if (isset($_POST["precio"])) {
|
|
$pvpSin = round(floatval($_POST["precio"]),2);
|
|
$pvpCon = $pvpSin * 1.21;
|
|
echo "El precio con IVA es $pvpCon";
|
|
}
|
|
}
|
|
?>
|
|
|
|
|
|
|
|
<!-- 5.Listado de películas
|
|
Crea 5 inputs y un botón de submit.
|
|
Rellena cada campo de los inputs con el nombre de una película.
|
|
Cuando se pulse debe guardar el contenido.
|
|
Imprime el resultado en una tabla en cada fila la posición de la pelicula y el nombre en distintas celdas -->
|
|
|
|
<form action="" method="post">
|
|
<br>
|
|
<br>
|
|
<label for="nombrePelicula[]">Introduce nombres de pelicula</label> <br>
|
|
<input type="text" name="nombrePelicula[]" id="nombre1"><br>
|
|
<input type="text" name="nombrePelicula[]" id="nombre2"><br>
|
|
<input type="text" name="nombrePelicula[]" id="nombre3"><br>
|
|
<input type="text" name="nombrePelicula[]" id="nombre4"><br>
|
|
<input type="text" name="nombrePelicula[]" id="nombre5"><br>
|
|
<input type="submit" value="Enviar"><br>
|
|
</form>
|
|
<?php
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
if (isset($_POST["nombrePelicula"])) {
|
|
$peliculas = $_POST["nombrePelicula"];
|
|
echo "<table border='2'>";
|
|
echo "<tr><td>Posicion</td><td>Nombre pelicula</td></tr>";
|
|
foreach ($peliculas as $index => $pelicula) {
|
|
$index=$index+1;
|
|
echo "<tr>";
|
|
echo "<td>$index</td>";
|
|
echo "<td>$pelicula</td>";
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|