Questo è un metodo ed è inviare i dati solo dopo averli verificati via client
mancano un'altra volta i tag
ok allora cambia il codice così
<ti ho aggiunto dei commenti fra questi tag in ogni punto che ho modificato
Codice PHP:
<form method="POST" name="reg" name="modulo">
<table border="0" width="401" id="table1">
<tr>
<td colspan="2"><font color="#800000">Dati personali:</font><hr>
</td>
</tr>
<tr>
<td width="44%"><font color="#000080">Nome:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t1" size="20" onChange="conferma(this)" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"><font color="#000080">Cognome:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t2" size="20" onChange="conferma(this)" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"><font color="#000080">Data di nascita:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t13" onChange="confermadata(this)" size="20" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"><font color="#000080">Luogo di nascita:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t14" onChange="conferma(this)" size="20" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%" height="22"><font color="#000080">Sesso:</font></td>
<td height="22" width="54%">
<select size="1" name="D1" style="width: 45; height: 15; background-color: #D3DEF1">
<option selected value="Maschio">M</option>
<option value="Femmina">F</option>
</select></td>
</tr>
<tr>
<td width="44%"><font color="#000080">Indirizzo:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t4" onChange="conferma(this)" size="20" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"><font color="#000080">C.A.P:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t5" onChange="conferma(this)" size="20" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"><font color="#000080">Località:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t6" onChange="conferma(this)" size="20" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"><font color="#000080">Provincia:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t60" onChange="conferma(this)" size="20" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width='205'>Stato:</td>
<td>
<input type="text" name="t7" onChange="conferma(this)" size="20" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"><font color="#000080">Codice fiscale:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t9" onChange="conferma(this)" size="20" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"> </td>
<td width="54%"> </td>
</tr>
<tr>
<td colspan="2"><font color="#800000">Contatti: </font><hr></td>
</tr>
<tr>
<td width="44%"><font color="#000080">Telefono:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t12" onChange="confermatel(this)" size="20" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"><font color="#000080">E-mail:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t8" onChange="confemail(this)" size="20" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><font color="#800000">Dati per il login:</font><hr>
</td>
</tr>
<tr>
<td width="44%"><font color="#000080">Username:</font></td>
<td width="54%"><font size="1">
<input type="text" name="t10" size="20" onChange="userleng()" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"><font color="#000080">Password:</font></td>
<td width="54%"><font size="1">
<input type="password" name="t11" size="20" onChange="verpassword()" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
<tr>
<td width="44%"><font color="#000080">Conferma password:</font></td>
<td width="54%"><font size="1">
<input type="password" name="conf" size="20" onChange="confpassword()" style="font-size: 10pt; width: 155; height: 18; color: #800000; border: 1px solid #88AEF7; background-color: #D3DEF1"></font></td>
</tr>
</table>
<center><input value="Registrati" type="button" onClick="Modulo()">
>
</form></center>
passiamo al javascript
Codice PHP:
function conferma(oggetto){
stringa=oggetto.value;
escluse = /^[a-zA-Z0-9_\.\-\à\è\é\ì\ù\ò'\ ]+$/;
if (!escluse.test(stringa)){alert(' E\' stato inserito un carattere non valido.Assicurarsi che tutti i caratteri siano lettere o numeri');
oggetto.value="";
return false;
}
return true;
}
function confermatel(oggetto){
stringa=oggetto.value;
escluse = /^[0-9_\+]+$/;
if (!escluse.test(stringa)){alert(' E' stato inserito un carattere non valido.Assicurarsi che tutti i caratteri siano numeri');
oggetto.value="";
return false;
}
return true;
}
function confermadata(oggetto){
stringa=oggetto.value;
escluse = /^[0-9_\-\\\/]+$/;
if (!escluse.test(stringa)){alert(' E' stato inserito un carattere non valido.Assicurarsi che tutti i caratteri siano numeri separati da / una barra ');
oggetto.value="";
return false;
}
return true;
}
function confermacap(oggetto){
stringa=oggetto.value;
escluse = /^[0-9_\-\\\/]+$/;
if (!escluse.test(stringa)){alert(' E' stato inserito un carattere non valido.Assicurarsi che tutti i caratteri siano numeri ');
oggetto.value="";
return false;
}
return true;
}
function confemail(oggetto){
stringa=oggetto.value;
escluse = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
if (!escluse.test(stringa)){alert(' L'indirizzo e-mail inserito non è corretto');
oggetto.value="";
return false;
}
return true;
}
function verpassword(){
conferma(document.forms[2].t11);
if((document.forms[2].t11.value.length<'5')||(document.forms[2].t11.value.length>'12')){alert("la password deve avere un minimo di 5 caratteri e un massimo di 12");
document.forms[2].t11.value="";
document.forms[2].conf.value="";
return false;
}
return true;
}
function confpassword(){
conferma(document.forms[2].conf);
if(document.forms[2].conf.value.length=='0')
{
document.forms[2].t10.value="";
document.forms[2].conf.value="";
return false;
}
else
{
if(document.forms[2].t11.value!=document.forms[2].conf.value)
{
alert('Le password non sono uguali');
document.forms[2].t11.value="";
document.forms[2].conf.value="";
return false;
}
}
return true;
}
function userleng(){
conferma(document.forms[2].t10);
if((document.forms[2].t10.value.length<'4')||(document.forms[2].t10.value.length>'12')){
alert("la username deve avere un minimo di 4 caratteri e un massimo di 12");
//history.go(0);
document.forms[2].t10.value="";
return false;
}
return true;
}
function noleng(oggetto){
if(oggetto.find.value==""){ }
}
function modulo()
{
var nome = document.modulo.t1.value;
if(!conferma(nome))
{
document.modulo.t1.focus();
return false;
}
var cognome = document.modulo.t2.value;
if(!conferma(cognome))
{
document.modulo.t2.focus();
return false;
}
var data = document.modulo.t13.value;
if(!confermadata(data))
{
document.modulo.t13.focus();
return false;
}
var nascita = document.modulo.t14.value;
if(!conferma(nascita))
{
document.modulo.t14.focus();
return false;
}
var indirizzo = document.modulo.t4.value;
if(!conferma(indirizzo))
{
document.modulo.t4.focus();
return false;
}
var cap = document.modulo.t5.value;
if(!conferma(cap))
{
document.modulo.t5.focus();
return false;
}
var localita = document.modulo.t6.value;
if(!conferma(localita))
{
document.modulo.t6.focus();
return false;
}
var provincia = document.modulo.t60.value;
if(!conferma(provincia))
{
document.modulo.t60.focus();
return false;
}
var stato = document.modulo.t7.value;
if(!conferma(stato))
{
document.modulo.t7.focus();
return false;
}
var cf = document.modulo.t9.value;
if(!conferma(cf))
{
document.modulo.t9.focus();
return false;
}
var telefono = document.modulo.t12.value;
if(!confermatel(telefono))
{
document.modulo.t12.focus();
return false;
}
var email = document.modulo.t8.value;
if(!confermail(email))
{
document.modulo.t8.focus();
return false;
}
if(!userleng())
{
document.modulo.t10.focus();
return false;
}
if(!verpassword())
{
document.modulo.t11.focus();
return false;
}
if(!confpassword())
{
document.modulo.conf.focus();
return false;
}
document.modulo.action = "paginacondatigiaverificati.php";
document.modulo.submit();
return true;
}