Originariamente inviato da bstefano79
potresti usare javascript per controllare prima di fare il submit della form
Ciao,
grazie per la risp 
Intendi fare dei controlli ed eventualmente segnalare l'errore con un alert?
Perchè attualmente il mio form, in caso di errore, attiva delle scritte rosse per dare risalto all'errore.
Intanto ti incollo qui il codice php
Codice PHP:
FUNCTION do_register()
{
IF($_POST["username"]!=NULL AND
$_POST["password"]!=NULL AND
$_POST["rip_pass"]!=NULL AND
$_POST["mail"] !=NULL AND
$_POST["rip_mail"]!=NULL AND
$_POST["name"] !=NULL AND
$_POST["surname"] !=NULL AND
$_POST["street"] !=NULL AND
$_POST["city"] !=NULL AND
$_POST["cap"] !=NULL AND
$_POST["land"] !=NULL AND
$_POST["tel"] !=NULL )
{
//Ha inserito tutti i campi, procedo con la registrazione.
IF($_POST["password"] != $_POST["rip_pass"])
{
//Le due password inserite sono diverse
header("Location: index.php?view=register&result=3");
EXIT;
}
IF($_POST["mail"] != $_POST["rip_mail"])
{
//Le due email sono diverse
header("Location: index.php?view=register&result=4");
EXIT;
}
$db = DO_CONNECTION();
$query = "SELECT *
FROM os_customer
WHERE os_customer.username='$_POST[username]'";
$result = mysql_query($query, $db);
IF($record = mysql_fetch_array($result))
{
//Username già esistente.
mysql_close($db);
header("Location: index.php?view=register&result=5");
EXIT;
}
$password = md5($_POST["password"]);
$query = "INSERT INTO os_customer (username,
pass,
name,
surname,
street,
city,
cap,
land,
tel,
mail)
VALUES('$_POST[username]',
'$password',
'$_POST[name]',
'$_POST[surname]',
'$_POST[street]',
'$_POST[city]',
'$_POST[cap]',
'$_POST[land]',
'$_POST[tel]',
'$_POST[mail]');";
IF($result = mysql_query($query, $db))
{
//Registrazione effettuata con successo
mysql_close($db);
header("Location: index.php?view=register&result=1");
EXIT;
}
ELSE
{
//Errore in fase di registrazione - questo non dovrebbe mai accadere
mysql_close($db);
header("Location: index.php?view=register&result=6");
EXIT;
}
}
ELSE
{
//Non ha inserito tutti i campi obbligatori
header("Location: index.php?view=register&result=2");
EXIT;
}
}
Codice PHP:
FUNCTION show_register($db,$template)
{
IF(!ISSET($_GET["result"]) OR
$_GET["result"] != "1")
{
//Form utente per la registrazione
$tmp_temp = implode("",file("template/register.html"));
$template = preg_replace("//", $tmp_temp,$template);
//Qui devo riproporre i dati inseriti precedentemente nella form
IF(ISSET($_GET["result"]))
{
SWITCH($_GET["result"])
{
// 2 = Campi obbligatori
// 3 = Le due password inserite sono diverse
// 4 = Le due email inserite sono diverse
// 5 = Username già esistente.
// 6 = Errore interno!!!!!
CASE "2":
$template = preg_replace("//","",$template);
$template = preg_replace("//","*",$template);
BREAK;
CASE "3":
$template = preg_replace("//","",$template);
BREAK;
CASE "4":
$template = preg_replace("//","",$template);
BREAK;
CASE "5":
$template = preg_replace("//","",$template);
BREAK;
CASE "6":
$template = preg_replace("//","",$template);
BREAK;
}
}
}
ELSE
{
//Registrazione effettuata con successo
$tmp_temp = implode("",file("template/register_ok.html"));
$template = preg_replace("//", $tmp_temp,$template);
}
RETURN $template;
}
Questo è il template dove definisco il form
Codice PHP:
<form name="register" action="index.php?ucomm=do_register" method="POST">
<table class="register" align="center">
<tr>
<td colspan="2"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="text" name="username" value=""><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="password" name="password"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="password" name="rip_pass"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="text" name="mail"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="text" name="rip_mail"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="text" name="name"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="text" name="surname"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="text" name="street"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="text" name="city"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="text" name="cap"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="text" name="land"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td align="right">[b][/b]</td>
<td><input type="text" name="tel"><font color="RED">[b][/b]</font></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" class="register_button" value=""></td>
</tr>
</table>
</form>