Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/11/2008, 08:45
markitus_11
 
Fecha de Ingreso: noviembre-2008
Mensajes: 100
Antigüedad: 15 años, 5 meses
Puntos: 1
Respuesta: Con esto ya termino, scripts formulario

Ok, ya presenté la duda en javascript

Bueno, cambie un poco la cosa este es el actual codigo:

Código:
<script language="javascript">
function jsRegistrar()
{
	var Nom = document.getElementById('Nom').value;
	var Cognoms = document.getElementById('Cognoms').value;
	var Contrasenya= document.getElementById('Contrasenya').value;
	var Email= document.getElementById('Email').value;
        if(Nom == ""){
              alert("Debe ingresar el usuario");
              document.getElementById('Nom').focus();
              return;
        }
        if(Cognoms == ""){
              alert("Debe ingresar el usuario");
              document.getElementById('Cognoms').focus();
              return;
        }
        if(Contrasenya== ""){
              alert("Debe ingresar el password");
              document.getElementById('Contrasenya').focus();
              return;
        }
        if(Email== ""){
              alert("Debe ingresar el email");
              document.getElementById('Email').focus();
              return;
        }
</script>


<script type="text/javascript">
function verify_passwords(password1, password2)
{
	// do various checks, this will save people noticing mistakes on next page
	if (password1.value == '' || password2.value == '')
	{
		alert('Escriu les contrasenyes correctament.');
		return false;
	}
	else if (password1.value != password2.value)
	{
		alert('Las contrasenyes no concorden.');
		return false;
	}
	else
	{
		

		var junk_output;

		md5hash(password1, document.forms.register.Contrasenya_md5, junk_output, 0);
		md5hash(password2, document.forms.register.Contrasenyaconfirmacio_md5, junk_output, 0);

		

		return true;
	}
	return false;
}
</script>

<?
if($registrar) {

$host = "localhost";
$user = "ampasant_basquet";
$pass = "50202050";
$db = "ampasant_basquet";

$conectar = mysql_connect($host,$user,$pass);
mysql_select_db($db,$conectar);


$Nom = $_POST['Nom'];
$Email = $_POST['Email'];



$resp = mysql_query("select * from usuarios where Email='$Email'") or die (mysql_error());
$existe = mysql_num_rows($resp);
if($existe == "0") {
mysql_query("insert into usuarios (Nom,Cognoms,Contrasenya,Email) values ('$Nom','$Cognoms','$Contrasenya','$Email')");
echo "Has estat registrat correctament.";
}
else {
echo "Aquest email ja es troba registrat.";
mysql_close($conectar); }
}
else {
?>
<form action="registrar.php" name="Formulari" method="post" onsubmit="return verify_passwords(Contrasenya, Contrasenyaconfirmacio);">

<table class="tborder" cellpadding="6" cellspacing="1" border="0" width="100%" align="center">

<tr>
	<td class="tcat">Registrar-se a la web de l´AMPA</td>
</tr>
<tr>
	<td class="panelsurround" align="center">
	<div class="panel">
		<div style="width:640px" align="left">

			<div class="smallfont" style="margin-bottom:3px">
				Si et registres, rebràs les ultimes noticies i informacions directament al teu correu
			</div>

			<div class="smallfont" style="margin-bottom:3px">
				<strong>Nom</strong>:<br />
				<input type="text" class="bginput" name="Nom" size="25" maxlength="" value="" id="Nom" style="width: 212px" /><span id="Nom"></span>
			</div> 
                        <div class="smallfont" style="margin-bottom:3px">
				<strong>Cognoms</strong>:<br />
				<input type="text" class="bginput" name="Cognoms" size="25" maxlength="" value="" id="Cognoms" style="width: 212px"/><span id="Cognoms"></span>
			</div>
<fieldset class="fieldset">
				<legend>Contrasenya</legend>

				<table cellpadding="0" cellspacing="3" border="0" width="400">
				<tr>
					<td colspan="2">Introduix la contrasenya per a la teva conta</td>
				</tr>
				<tr>
					<td>
						Contrasenya:<br />
						<input type="password" class="bginput" name="Contrasenya" size="25" maxlength="50" value="" onblur="varfield(1);" id="password_1"/>

					</td>
					<td>
						Confirmar Contrasenya:<br />
						<input type="password" class="bginput" name="Contrasenyaconfirmacio" size="25" maxlength="50" value="" onblur="varfield(2);" id="password_2"/>
						</td>
					</tr>
					<tr>
						<td colspan="2">

							<span id="password_1_status"></span>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<span id="password_2_status"></span>
					</td>
				</tr>
				</table>

			</fieldset>
			<fieldset class="fieldset">
				<legend>Direcció de Correo Electrònic</legend>
				<table cellpadding="0" cellspacing="3" border="0" width="400">
				<tr>
					<td colspan="2">Escriu una direcció de correu vàlida.</td>
				</tr>

				<tr>
					<td>
						Direcció de Correo Electrònic:<br />
						<input type="text" class="bginput" name="Email" size="25" maxlength="50" value="" dir="ltr" id="Email"/>
					</td>
					<td>
						Confirmar Direcció de Correo Electrònic:<br />
						<input type="text" class="bginput" name="Emailconfirm" size="25" maxlength="50" value="" dir="ltr" id="email_2"/>

						</td>
					</tr>
					<tr>
						<td colspan="2">
							<span id="Email_status"></span>
						</td>
					</tr>
					<tr>
						<td colspan="2">

							<span id="email_2_status"></span>
					</td>
				</tr>

<input type="submit" name="registrar" value="Registrar">
</form>
<?
}
?>

AHora lo que mando a comprobar es el email

Pero ahora tengo otra duda y es:

Como puedo hacer validar Nom y Cognoms juntos y si no coinciden los dos campos permitir el registro?

Es decir si hay un tal Pepe Mejillon y un tal Pepe Arbusto, no le impida el registro, que solo lo impida si Pepe mejillon se quiere registrar dos veces con el mismo nombre y apellidos

Última edición por markitus_11; 29/11/2008 a las 09:15