Ragazzi salve a tutti, sto cercando di implementare un form di registrazione ad un sito che abbia anche il controllo di sicurezza captcha.
Tutto funziona alla grande, solo che si ignora il controllo proprio su quest'ultimo.
Vi posto il codice.. Se avere suggerimenti da darmi ve ne sarei molto grata. Grazie![]()
<!DOCTYPE html>
<html>
<head>
<title>Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
<script language="javascript">
function Modulo() {
// Variabili associate ai campi del modulo
var nome = document.modulo.full_name.value;
var indirizzo = document.modulo.address.value;
var nazione = document.modulo.country.value;
var telefono = document.modulo.tel.value;
var fax = document.modulo.fax.value;
var website = document.modulo.web.value;
var user = document.modulo.user_name.value;
var email = document.modulo.usr_email.value;
var pass = document.modulo.pwd.value;
var pass2 = document.modulo.pwd2.value;
var codice = document.modulo.codice.value;
// Resettiamo il colore di sfondo dei moduli
document.modulo.full_name.style.backgroundColor="" ;
document.modulo.address.style.backgroundColor="";
document.modulo.country.style.backgroundColor="";
document.modulo.tel.style.backgroundColor="";
document.modulo.fax.style.backgroundColor="";
document.modulo.web.style.backgroundColor="";
document.modulo.user_name.style.backgroundColor="" ;
document.modulo.usr_email.style.backgroundColor="" ;
document.modulo.pwd.style.backgroundColor="";
document.modulo.pwd2.style.backgroundColor="";
// Espressione regolare dell'email
var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
//Effettua il controllo sul campo FULL_NAME
if ((nome == "") || (nome == "undefined")) {
alert("Il campo Nome è obbligatorio.");
document.modulo.full_name.focus();
document.modulo.full_name.style.backgroundColor="r ed";
return false;
}
//Effettua il controllo sul campo ADDRESS
else if ((indirizzo == "") || (indirizzo == "undefined")) {
alert("Il campo Indirizzo è obbligatorio.");
document.modulo.address.focus();
document.modulo.address.style.backgroundColor="red ";
return false;
}
//Effettua il controllo sul campo COUNTRY
else if ((nazione == "") || (nazione == "undefined")) {
alert("Il campo Nazione è obbligatorio.");
document.modulo.tel.focus();
document.modulo.tel.style.backgroundColor="red";
return false;
}
//Effettua il controllo sul campo TEL
else if ((telefono == "") || (telefono == "undefined")) {
alert("Il campo Telefono è obbligatorio.");
document.modulo.country.focus();
document.modulo.country.style.backgroundColor="red ";
return false;
}
else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
alert("Inserire un indirizzo email corretto.");
document.modulo.usr_email.select();
document.modulo.email.style.backgroundColor="red";
return false;
}
else if ((codice != document.getElementById("captcha").innerText) || (codice=="") || (codice=="undefined")){
alert("Il codice di sicurezza è errato!");
document.modulo.codice.select();
document.modulo.codice.style.backgroundColor="red" ;
return false;
}
//INVIA IL MODULO
else {
document.modulo.action = "avvenuto.php ";
document.modulo.submit();
}
}
$(document).ready(function(){
$.validator.addMethod("username", function(value, element) {
return this.optional(element) || /^[a-z0-9\_]+$/i.test(value);
}, "Username must contain only letters, numbers, or underscore.");
$("#regForm").validate();
});
function CAPTCHA()
{
var car, min, max, dif, lun, inc;
car = "abcdefghijklmnopqrstuvwxyz";
car += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
car += "1234567890";
min = 5;
max = 5;
dif = max - min;
lun = Math.round((Math.random() * dif) + min);
inc = 0;
cod = "";
while (inc < lun)
{
cod += car.charAt(Math.round(Math.random() * car.length));
inc++;
}
return cod;
}
</script>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<h1>Semantic Multimedia Retrieval</h1>
</header>
<div id="container">
<aside>
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="main2">
<tr>
<td colspan="3"></td>
</tr>
<tr>
<td width="160" valign="top">
</p>
</p>
</p>
</p>
</p></td>
<td width="732" valign="top">
<form action="avvenuto.php" method="post" name="regForm" id="regForm" >
<table width="95%" border="0" cellpadding="3" cellspacing="3" class="forms">
<tr>
<td colspan="2">Your Name / Company Name<span class="required"><font color="#CC0000">*</font></span>
<input name="full_name" type="text" id="full_name" size="40" class="required"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2">Contact Address (with ZIP)<span class="required"><font color="#CC0000">*</font></span>
<textarea name="address" cols="40" rows="4" id="address" class="required"></textarea>
<span class="example">VALID CONTACT DETAILS</span> </td>
</tr>
<tr>
<td>Country <font color="#CC0000">*</font></span></td>
<td><select name="country" class="required" id="select8">
<option value="" selected></option>
<option value="Afghanistan">Afghanistan</option>
<option value="Yugoslavia">Yugoslavia</option>
</select></td>
</tr>
<tr>
<td>Phone<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="tel" type="text" id="tel" class="required"></td>
</tr>
<tr>
<td>Fax </td>
<td><input name="fax" type="text" id="fax">
</td>
</tr>
<tr>
<td>Website </td>
<td><input name="web" type="text" id="web" class="optional defaultInvalid url">
<span class="example">http://www.example.com</span></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><h4>Login Details</h4></td>
</tr>
<tr>
<td>Username<span class="required"><font color="#CC0000">*</font></span></td>
<td><input name="user_name" type="text" id="user_name" class="required username" minlength="5" >
<input name="btnAvailable" type="button" id="btnAvailable"
onclick='$("#checkid").html("Please wait..."); $.get("checkuser.php",{ cmd: "check", user: $("#user_name").val() } ,function(data){ $("#checkid").html(data); });'
value="Check Availability">
<span style="color:red; font: bold 12px verdana; " id="checkid" ></span>
</td>
</tr>
<tr>
<td>Your Email<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="usr_email" type="text" id="usr_email3" class="required email">
<span class="example">** Valid email please..</span></td>
</tr>
<tr>
<td>Password<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="pwd" type="password" class="required password" minlength="5" id="pwd">
<span class="example">** 5 chars minimum..</span></td>
</tr>
<tr>
<td>Retype Password<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="pwd2" id="pwd2" class="required password" type="password" minlength="5" equalto="#pwd"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>
Copia il codice di sicurezza:
<span id="captcha">
<script type="text/javascript" language="JavaScript">
document.getElementById("captcha").innerText = CAPTCHA();
</script>
</span>
<input type="text" name="codice" size="50">
</td>
</tr>
</table>
<p align="center">
<input name="doRegister" type="submit" id="doRegister" value="Register">
</p>
</form>
</td>
<td width="196" valign="top"></td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
</table>
</aside>
</div>
</body>
</html>