ciao e innanzitutto grazie per la risposta... andando avanti con tutte le prove mi sono reso conto che il problema è ben diverso.... mi spiego:
ho 2 file:
register.php ( il form )
e check.php (il controllore di validità)
c'è qualcosa di piu che la semplice espressione regolare!!!
ecco i codici:
register.php
Codice PHP:
<?
session_start();
include("root.php");
include ($walk.'service.func.php');
include ($walk.'template/layout_short.php');
include ($walk.'gears/data.php');
include ($walk.'gears/login.php');
head();
?>
<form method="POST" action="check.php" id="corpo,5,1">
<table border="0" style="border-collapse: collapse" width="100%" id="table1">
<tr>
<td align="center" colspan="3" id="intestazione,5,1"><h2>Form di Registrazione</h2></td>
</tr>
<tr>
<td width="116" align="right"></td>
<td></td>
</tr>
<tr>
<td width="116" align="right"></td>
<td></td>
</tr>
<tr>
<td align="center" colspan="3"><? if (isset($message)) echo $message; ?></td>
</tr>
<tr>
<td width="116" align="right"></td>
<td></td>
</tr>
<tr>
<td width="116" align="right"></td>
<td></td>
</tr>
<tr>
<td width="116" align="right">nome :</td>
<td><input type="text" name="nome" size="20" class="input" maxlength="20" <? if (isset($_POST['nome'])) echo " value=\"{$_POST['nome']}\""; ?>><font color="#FF0000">*</font></td>
</tr>
<tr>
<td width="116" align="right">cognome :</td>
<td><input type="text" name="cognome" size="30" class="input" maxlength="30" <? if (isset($_POST['cognome'])) echo " value=\"{$_POST['cognome']}\""; ?>></td>
</tr>
<tr>
<td width="116" align="right">provenienza :</td>
<td><input type="text" name="provenienza" size="40" class="input" maxlength="40" <? if (isset($_POST['provenienza'])) echo " value=\"{$_POST['provenienza']}\""; ?>></td>
</tr>
<tr>
<td width="116" align="right">e-mail :</td>
<td><input type="text" name="email" size="30" class="input" maxlength="30" <? if (isset($_POST['email'])) echo " value=\"{$_POST['email']}\""; ?>><font color="#FF0000">*</font></td>
</tr>
<tr>
<td width="116" align="right"></td>
<td></td>
</tr>
<tr>
<td width="116" align="right">username :</td>
<td><input type="text" name="username" size="12" class="input" maxlength="12" <? if (isset($_POST['username'])) echo " value=\"{$_POST['username']}\""; ?>><font color="#FF0000">*</font></td>
</tr>
<tr>
<td width="116" align="right">password :</td>
<td><input type="text" name="password" size="12" class="input" maxlength="12" ><font color="#FF0000">*</font></td>
</tr>
<tr>
<td width="116" align="right">ridigita password :</td>
<td><input type="text" name="ripassword" size="12" class="input" maxlength="12"><font color="#FF0000">*</font></td>
</tr>
<tr>
<td width="116" align="right"></td>
<td></td>
</tr>
<tr>
<td width="116" align="right" valign="top">
<input type="checkbox" name="privacy" value="si" class="input"></td>
<td valign="top"><textarea rows="5" name="privacy" cols="54" class="input"></textarea></td>
</tr>
<tr>
<td align="center" colspan="2"></td>
</tr>
<tr>
<td width="116" align="right"></td>
<td align="center" bgcolor="#FFFFFF">
<u><font color="#FF0000">TUTTI I CAMPI CONTRASSEGNATI DA UN * SONO OBBLIGATORI</font></u>
</td>
<td width="116" align="right"></td>
</tr>
<tr>
<td align="center" colspan="3"></td>
</tr>
<tr>
<td align="center" colspan="3"><input type="submit" value="registrami" name="invia" class="butt"></td>
</tr>
<tr>
<td align="center" colspan="3"></td>
</tr>
</table>
</form>
<?
foot();
edit ($_SESSION);
?>
e check.php
Codice PHP:
<?
include("root.php");
include($walk."mysql.func.php");
$result=check_form('nome',$empty='y',$special_chars='y');
if ($result[0]==0) $result=check_form('email',$empty='y',$email='y');
if ($result[0]==0) $result=check_form('username',$empty='y',$special_chars='y',$min_length='6');
if ($result[0]==0) $result=check_form('password',$empty='y',$special_chars='y',$min_length='6');
if ($result[0]==0) $result=check_form('ripassword',$empty='y',$special_chars='y',$min_length='6');
if ($result[0]==0)
{
$user_list=colonna('utenti','username');
if (in_array($_POST['username']))
{
$error=1;
$message="<font color=\"#cc0000\">ERRORE... il nome utente è stato già scelto. Prego sceglierne un altro differente.</font>";
}
}
if ($result[0]==0 && isset($_POST['privacy']) && empty($_POST['privacy']))
{
$error=1;
$message="ERRORE... ACCETTARE I TERMINI DI REGISTRAZIONE";
}
if ($result[0]==0)
{
// vai alla registrazione effettiva nel db
}
else
{
$message=$result[1];
include ('register.php');
edit ($_POST);
}
function check_form($campo,$empty='',$min_length='',$max_length='',$email='',$special_chars='')
{
global $_POST;
global $error;
$error=0;
$message="";
if ($empty != "")
{
if (empty($_POST[$campo]) && $_POST[$campo] == "")
{
$error=1;
$message="il campo $campo e' obbligatorio";
$result=array($error,$message);
return $result;
}
}
if ($special_chars != '')
{
if (eregi("[:;,/\\\?\"\'\^]",trim($_POST[$campo])))
{
$error=1;
$message="ERRORE... non sono concessi i caratteri / \\ ; \" e , ";
$result=array($error,$message);
return $result;
}
}
if ($min_length != '')
{
if (strlen(trim($_POST[$campo])) < $min_length)
{
$error=1;
$message = "il campo $campo deve avere almeno $min_length caratteri";
$result=array($error,$message);
return $result;
}
}
if ($max_length != '')
{
if (strlen(trim($_POST[$campo])) > $max_length)
{
$error=1;
$message = "il campo $campo non deve avere piu' di $max_length caratteri";
$result=array($error,$message);
return $result;
}
}
if ($email != '')
{
if(!preg_match( '/^[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}$/',trim($_POST[$campo])))
{
$error=1;
$message="ERRORE... L' indirizzo e-mail deve essere un indirizzo valido";
$result=array($error,$message);
return $result;
}
}
$result=array($error,$message);
return $result;
}
?>
provare per credere!! la funzione non lavora correttamente, mi salta i controlli e non capisco da dove è dovuto.. credo nella dichiarazione delle variabili per la funzione ma nn ne sono sicuro...