Validar dato cargado
Publicado por Javier (12 intervenciones) el 21/04/2020 00:01:20
Buenas tardes.
Tengo un formulario que me carga los datos en una tabla de la base de datos.
La validación la estoy realizando con JavaScript, y no con PHP, para no estar mandando datos cada vez que quiero validar. Esta validación la realicé con una función que la llamé ValidaDatos(). Esta misma la invoco desde el formulario desde onsubmit="return ValidaDatos()"
La cuestión es que necesito validar el nombre de usuario con los ya cargados en la tabla. Es decir que si el nombre de usuario ya fue cargado me lo valide en la función ValidaDatos().
Desde ya les agradezco.
Les copio el código
Tengo un formulario que me carga los datos en una tabla de la base de datos.
La validación la estoy realizando con JavaScript, y no con PHP, para no estar mandando datos cada vez que quiero validar. Esta validación la realicé con una función que la llamé ValidaDatos(). Esta misma la invoco desde el formulario desde onsubmit="return ValidaDatos()"
La cuestión es que necesito validar el nombre de usuario con los ya cargados en la tabla. Es decir que si el nombre de usuario ya fue cargado me lo valide en la función ValidaDatos().
Desde ya les agradezco.
Les copio el código
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
#Verificamos que esté abierta la sesión
session_start();
if (empty($_SESSION["usuario"])) {
# Lo redireccionamos al formulario de inicio de sesión
header("Location: Index_Adm.php");
# Y salimos del script
exit();
}
?>
<!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">
<head>
<title>CAFIRA - Alta de Repositor</title>
<link href= "https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" />
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
function ValidaDatos(){
var Error=0;
var Clave= document.FrmAltaRepo.LbClave.value;
var ConfClave= document.FrmAltaRepo.LbConfClave.value;
var Mail= document.FrmAltaRepo.LbMail.value;
if (document.FrmAltaRepo.LbNombre.value==null || document.FrmAltaRepo.LbNombre.value=="" ||
document.FrmAltaRepo.LbEmpresa.value==null || document.FrmAltaRepo.LbEmpresa.value=="" ||
document.FrmAltaRepo.LbDomicilio.value==null || document.FrmAltaRepo.LbDomicilio.value=="" ||
document.FrmAltaRepo.LbCP.value==null || document.FrmAltaRepo.LbCP.value=="" ||
document.FrmAltaRepo.LbLocalidad.value==null || document.FrmAltaRepo.LbLocalidad.value=="" ||
document.FrmAltaRepo.LbProvincia.value==null || document.FrmAltaRepo.LbProvincia.value=="" ||
document.FrmAltaRepo.LbTelefono.value==null || document.FrmAltaRepo.LbTelefono.value=="" ||
document.FrmAltaRepo.LbMail.value==null || document.FrmAltaRepo.LbMail.value=="" ||
document.FrmAltaRepo.LbUsuario.value==null || document.FrmAltaRepo.LbUsuario.value=="" ||
document.FrmAltaRepo.LbClave.value==null || document.FrmAltaRepo.LbClave.value=="" ||
document.FrmAltaRepo.LbConfClave.value==null || document.FrmAltaRepo.LbConfClave.value=="") {
alert("Por favor ingrese los datos necesarios");
return false;
} else if(Clave !== ConfClave){
alert ("La clave ingresada no coincide con la confirmada");
return false;
}
if (Error==1) {
alert("Por favor ingrese los datos necesarios");
return false;
} else if (Error==2) {
alert ("La clave ingresada no coincide con la confirmada");
return false;
} else if (Error==3) {
alert ("El usuario ya se encuentra registrado");
return false;
}
}
</SCRIPT>
</head>
<body bgcolor="#FFFFFF" leftmargin="12" topmargin="12" marginwidth="12" marginheight="12">
<p><h3 align="center">Alta de Repositor</h3> </p>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="0">
<FORM name="FrmAltaRepo" action="Inserta_Repositor.php" method="POST" onsubmit="return ValidaDatos()">
<tr>
<td width="180" align="right" class="verdana10negro" ><strong>Nombre
y Apellido</strong></td>
<td><input name="LbNombre" value="<?php echo isset($_POST['LbNombre']) ? $_POST['LbNombre'] : ''; ?>" type="text" id="nombre" size="33" >
<strong>*</strong> </td>
</tr>
<tr>
<td width="120" align="right" class="verdana10negro" ><strong>Empresa</strong></td>
<td> <input name="LbEmpresa" value="<?php echo isset($_POST['LbEmpresa']) ? $_POST['LbEmpresa'] : ''; ?>" type="text" id="empresa" size="33" >
* </td>
</tr>
<tr>
<td align="right" class="verdana10negro"><strong>Domicilio</strong></td>
<td > <input name="LbDomicilio" value="<?php echo isset($_POST['LbDomicilio']) ? $_POST['LbDomicilio'] : ''; ?>" type="text" id="domicilio" size="33" >
* </td>
</tr>
<tr>
<td align="right" class="verdana10negro"><strong>Cod.
Post.</strong></td>
<td > <input name="LbCP" type="text" id="cp" size="9" onKeypress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;" value="<?php echo isset($_POST['LbCP']) ? $_POST['LbCP'] : ''; ?>">
* </td>
</tr>
<tr>
<td align="right" class="verdana10negro"><strong>Localidad</strong></td>
<td > <input name="LbLocalidad" value="<?php echo isset($_POST['LbLocalidad']) ? $_POST['LbLocalidad'] : ''; ?>" type="text" id="localidad" size="33" >
*</td>
</tr>
<tr>
<td align="right" class="verdana10negro"><strong>Provincia</strong></td>
<td > <input name="LbProvincia" value="<?php echo isset($_POST['LbProvincia']) ? $_POST['LbProvincia'] : ''; ?>" type="text" id="provincia" size="33" >
* </td>
</tr>
<tr>
<td align="right" class="verdana10negro"><strong>Teléfono</strong></td>
<td><input name="LbTelefono" value="<?php echo isset($_POST['LbTelefono']) ? $_POST['LbTelefono'] : ''; ?>" type="text" id="telefono" size="20" onKeypress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;">
*</td>
</tr>
<tr>
<td align="right" class="verdana10negro"><strong>E-Mail</strong></td>
<td ><input name="LbMail" value="<?php echo isset($_POST['LbMail']) ? $_POST['LbMail'] : ''; ?>" type="text" id="mail" size="33">
*</td>
</tr>
<tr>
<td align="center" colspan="2"><strong></strong></td>
</tr>
<tr>
<td align="right" class="verdana10negro"><strong>Usuario</strong></td>
<td ><input name="LbUsuario" value="<?php echo isset($_POST['LbUsuario']) ? $_POST['LbUsuario'] : ''; ?>" type="text" id="usuario" size="33" />
* </td>
</tr>
<tr>
<td align="right" class="verdana10negro"><strong>Contraseña</strong></td>
<td ><input name="LbClave" value="<?php echo isset($_POST['LbClave']) ? $_POST['LbClave'] : ''; ?>" type="password" id="clave" size="33" />
* </td>
</tr>
<tr>
<td align="right" class="verdana10negro"><strong>Conf. Contraseña</strong></td>
<td ><input name="LbConfClave" value="<?php echo isset($_POST['LbConfClave']) ? $_POST['LbConfClave'] : ''; ?>" type="password" id="clave" size="33" />
* </td>
</tr>
<tr>
<td align="center" colspan="2"><strong></strong></td>
</tr>
<tr>
<td colspan="2" align="center" class="verdana10negro">
<input name="BtGrabar" type="submit" id="grabar" value="Grabar" class="boton" >
<input name="Btcancelar" type="reset" id="cancelar" value="Cancelar" class="boton">
</td>
</tr>
</FORM>
</table>
</body>
</html>
Valora esta pregunta


0