Return to Snippet

Revision: 40929
at February 10, 2011 03:41 by danideu


Initial Code
<?php

//variables valores por defecto
$name = "";

	/*Validamos que el nombre no tenga caracteres extraños 
	y que su longitud sea mayor que 4*/
	function validateName($name){
		//NO cumple longitud minima
		if(strlen($name) < 4)
			return false;
		//Si longitud OK pero NOOK solo caracteres de la A a la z
		else if(!preg_match("/^[a-zA-Z]+$/", $name))
			return false;
		// SI longitud, SI caracteres A-z
		else
			return true;
	}

//Si se ha enviado la variable mediante POST, validamos los campos
if(isset($_POST['send'])){
	if(!validateName($_POST['name']))
		$name = "error";
	
	//Validamos si hay error
	if($name != "error")
		$status = 1;
}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="es-ES">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Formulario de registro utilizando PHP y Javascript (jQuery) para validar | COLORATE</title>
	<link rel="stylesheet" href="main.css" type="text/css" media="screen" />
</head>
<body>
<div class="wrapper">	
	<div class="section">
		<?php if(!isset($status)): ?>
			<h1>Formulario de Registro</h1>
			<form id="form1" action="formulario_1.php" method="POST">
				
			<!-- <label for="name">Nombre <span style="color: green"> Mínimo 4 carácteres (permitidos de la A a la Z)</span></label> -->
			<label for="name">Nombre <?php if ($name == "error"): echo "<span style=color:red>"; else: echo "<span style=color:green>"; endif; ?>Mínimo 4 carácteres (permitidos de la A a la Z)</span></label>
			<input type=”text” tabindex="1" name="name" class="text">
			
			<label for="username">Nombre de usuario</label>
			<input type=”text” tabindex="2" name="username" class="text">
			
			<label for="password1">Contraseña</label>
			<input type="password" tabindex="3" name="password1" class="text">
			
			<label for="password2">Repite Contraseña</label>
			<input type="password" tabindex="4" name="password2" class="text">
			
			<label for="email">Email </label>
			<input type=”text” tabindex="5" name="email" class="text">
			<div>
				<input tabindex="6" name="send" type="submit" class="submit" value="Enviar formulario" class="submit"/>
		  </div>
			
			</form>
		<?php else: ?>
			<h1>¡Formulario enviado con éxito!</h1>
			<!--<h1>El e-mail pasado es: <?php echo $email; ?> Y el error es: <?php echo $email1; ?></h1> -->
		<?php endif; ?>
	</div> <!-- Cerramos div section -->
</div> <!-- Cerramos div wrapper -->
</body>
</html>

Initial URL
http://www.colordeu.es/BLOG/registros-de-usuario-en-php-y-mysql-con-validacion-de-campos-y-activacion-por-mail

Initial Description
Pertenece al tutorial publicado por COLORATE --> http://www.colordeu.es/BLOG/registros-de-usuario-en-php-y-mysql-con-validacion-de-campos-y-activacion-por-mail

Initial Title
REGISTRAR USUARIOS EN PHP CON VALIDACION DE DATOS Y ACTIVACIÓN POR MAIL - 1

Initial Tags
php, html

Initial Language
PHP