Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Untitled-3.php #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions 08 GET y POST/font-awesome-4.7.0/scss/Untitled-3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Validar formulario</title>
<style>
body{background-color: #264673; box-sizing: border-box; font-family: Arial;}

form{
background-color: white;
padding: 10px;
margin: 100px auto;
width: 400px;
}

input[type=text], input[type=password]{
padding: 10px;
width: 380px;
}
input[type="submit"]{
border: 0;
background-color: #ED8824;
padding: 10px 20px;
}

.error{
background-color: #FF9185;
font-size: 12px;
padding: 10px;
}
.correcto{
background-color: #A0DEA7;
font-size: 12px;
padding: 10px;
}
</style>
</head>
<body>
<form action="formulario.php" method="POST">
<?php

if(isset($_POST['nombre'])){
$nombre = $_POST['nombre'];
$password = $_POST['password'];
$email = $_POST['email'];

$campos = array();

if($nombre == ""){
array_push($campos, "El campo Nombre no pude estar vacío");
}

if($password == "" || strlen($password) < 6){
array_push($campos, "El campo Password no puede estar vacío, ni tener menos de 6 caracteres.");
}

if($email == "" || strpos($email, "@") === false){
array_push($campos, "Ingresa un correo electrónico válido.");
}

if(count($campos) > 0){
echo "<div class='error'>";
for($i = 0; $i < count($campos); $i++){
echo "<li>".$campos[$i]."</i>";
}
}else{
echo "<div class='correcto'>
Datos correctos";
}
echo "</div>";
}
?>
<p>
Nombre:<br/>
<input type="text" name="nombre">
</p>

<p>
Password:<br/>
<input type="password" name="password">
</p>

<p>
correo electrónico:<br/>
<input type="text" name="email">
</p>

<p><input type="submit" value="enviar datos"></p>
</form>
</body>
</html>