io l'avrei strutturata diversamente...
premesso che ho lpagina del form che punta a check.php
Codice PHP:
if (isset $_POST['invia'])
{
foreach($_POST as $key=>$val)
{
if (empty($_POST[$key]))
{
form("ERRORE: COMPILARE TUTTI I CAMPI",$_POST);
die();
}
}
}
else
{
form("COMPILARE I CAMPI");
}
function form($message,$_POST="")
{
if (isset($_POST) && !empty($_POST))
{
echo "
[b]$message[/b]
\n";
echo '<form name="form" method="post" action="pagina.php">';
if (isset($_POST) && !empty($_POST))
{
foreach ($_POST as $key=>$val)
{
echo "<input type=\"text\" name=\"$key\" value=\"$val\">\n";
}
echo '<input type="submit" name="invia" value="invia">\n</form>\n';
}
else
{
echo '
<form name="form" method="post" action="pagina.php">
nick:<input type="text" name="nick">
e-mail:<input type="text" name="nick">
<input type="submit" name="invia" value="invia">
</form>\n';
}
}
}
questo per il controllo dei campi con ritorno + error message e ricompilazione campi