Add user creation form validation

This commit is contained in:
coolneng 2020-06-18 08:12:23 +02:00
parent 77e604d385
commit 095b639794
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
3 changed files with 51 additions and 3 deletions

View File

@ -7,7 +7,7 @@
<link rel="stylesheet" href="../../static/style.css" type="text/css" media="screen" /> <link rel="stylesheet" href="../../static/style.css" type="text/css" media="screen" />
<script src="../../static/jquery-3.5.1.min.js"></script> <script src="../../static/jquery-3.5.1.min.js"></script>
<script src="../ajax.js"></script> <script src="../ajax.js"></script>
<script src="../validate_id.js"></script> <script src="../validate_patient.js"></script>
</head> </head>
<body> <body>
<?php <?php
@ -16,7 +16,7 @@
$pdo = connectDatabase(); $pdo = connectDatabase();
$regions = fetchRegions($pdo); $regions = fetchRegions($pdo);
?> ?>
<form name="create_form" method="post" action="../patient_management.php" onsubmit="return validateDNI();"> <form name="create_form" method="post" action="../patient_management.php" onsubmit="return validatePatient();">
<div class="input-group"> <div class="input-group">
<label>Nombre</label> <label>Nombre</label>
<input type="text" name="nombre" value=""> <input type="text" name="nombre" value="">

View File

@ -5,9 +5,10 @@
<meta name="description" content=""> <meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../../static/style.css" type="text/css" media="screen" /> <link rel="stylesheet" href="../../static/style.css" type="text/css" media="screen" />
<script src="../validate_user.js"></script>
</head> </head>
<body> <body>
<form method="post" action="../user_management.php"> <form name="create_form" method="post" action="../user_management.php" onsubmit="return validateUser();">
<div class="input-group"> <div class="input-group">
<label>Nombre</label> <label>Nombre</label>
<input type="text" name="nombre" value=""> <input type="text" name="nombre" value="">

47
src/validate_user.js Normal file
View File

@ -0,0 +1,47 @@
function validateString(input){
if(input == ""){
return false;
}
return true;
}
function validateEmail(input){
var emailID = input;
atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf(".");
if (atpos < 1 || ( dotpos - atpos < 2 )) {
return false;
}
return true;
}
function validateUser(){
var name = document.forms["create_form"]["nombre"];
var user = document.forms["create_form"]["usuario"];
var password = document.forms["create_form"]["contraseña"];
var email = document.forms["create_form"]["correo"];
if(!validateString(name.value)){
alert("Introduce el nombre");
return false;
}
if(!validateString(user.value)){
alert("Introduce el usuario");
return false;
}
if(!validateString(password.value)){
alert("Introduce la contraseña");
return false;
}
if(!validateEmail(email.value)){
alert("El correo proporcionado es incorrecto");
return false;
}
return true;
}