Cita:
Iniciado por Alexis88 si
Cita:
Iniciado por mauricio1020 si
Hey amigos si he leido todo paso a paso pero soy un poco lento y todo es nuevo es para mi , pero bueno he armado todo de esta forma, no se pero igual me deja pasar algunos datos repetidos y aveces no.
index.php
Código PHP:
<html>
<head>
<title></title>
</head>
<link rel="stylesheet" type="text/css" href="Codigo.CSS">
<style type="text/css"> </style>
<body>
<form id = "datos" action = "registrar.php" method = "post">
<label for = "correo">Ingrese su correo electrónico para suscribirse a nuestras noticias:</label>
<input type = "email" name = "correo" id = "correo" required />
<span id = "mensaje"></span>
<input type = "submit" value = "Suscribirse" />
</form>
</body>
<script type="text/javascript" src="Codigo.js">
</script>
<script>
document.addEventListener("DOMContentLoaded", function(){
/* Aquí va el código */ }, false);
</script>
</html>
Codigo.js
Código Javascript
:
Ver originalvar form = document.querySelector("#datos"),
input = document.querySelector("#correo"),
span = document.querySelector("#mensaje"),
ajax, envio;
input.addEventListener("blur", function(){
ajax = new XMLHttpRequest();
ajax.open("GET", "comprobar.php?correo=" + this.value, true);
ajax.send();
ajax.addEventListener("load", function(){
if (this.status == 200){
if (this.responseText == "yes"){
span.innerHTML = "El correo electrónico ingresado ya está registrado. Ingrese otro.";
span.className = "invalid";
envio = false;
}
else{
span.innerHTML = "Continúe con el ingreso de datos.";
span.className = "valid";
envio = true;
}
}
}, false);
}, false);
form.addEventListener("submit", function(event){
event.preventDefault();
if (envio){
this.submit();
}
else{
alert("Debe de ingresar otro correo electrónico");
input.value = "";
input.focus();
}
}, false);
Codigo.css
Código CSS:
Ver original.valid{
background: green;
}
.invalid{
background: red;
}
.valid, .invalid{
color: white;
}
comprobar.php
Código PHP:
$conexion = mysqli_connect('localhost', 'root', '', 'dbjeison');
if (!$conexion) exit(mysqli_connect_error());
$correo = mysqli_real_escape_string($conexion, strip_tags(trim($_POST['correo'])));
$consulta = "SELECT correo FROM usuarios WHERE correo = '$correo'";
$resultados = mysqli_query($conexion, $consulta) or exit(mysqli_error());
echo mysqli_num_rows($resultados) ? 'yes' : 'no';
registrar.php
Código PHP:
Ver original<html>
<body>
hola Pasar a registrar
</body>
</html>
Gracias por la paciencia y por enseñarme!