posto il codice per maggiore chiarezza:
Codice PHP:
<?php
$ok=0;
if (count($_POST)>0) { //se il post è settato, faccio i controlli sui campi
foreach($_POST as $key => $value) {
if ($value=='') {
print "<span class=\"errore\">Non hai compilato il campo ".ucfirst($key)."!</span>\n";
$ok=0;
} else {
$value = addslashes(stripslashes(trim($value)));
$value = str_replace("<", "<", $value);
$value = str_replace(">", ">", $value);
$ok=1;
}
}
if (count($_POST['gara'])>0) {
$gara = implode(', ',$_POST['gara']);
$ok=1;
} else {
print "<span class=\"errore\">Non hai compilato il campo Gara!</span>\n";
$ok=0;
}
if (count($_POST['metodo_spedizione'])>0) {
$metodo_spedizione = implode(', ',$_POST['metodo_spedizione']);
$ok=1;
} else {
print "<span class=\"errore\">Non hai compilato il campo Metodo di Spedizione!</span>\n";
$ok=0;
}
if (count($_POST['tipo_materiale'])>0) {
$tipo_materiale = implode(', ',$_POST['tipo_materiale']);
$ok=1;
} else {
print "<span class=\"errore\">Non hai compilato il campo Tipo di Materiale!</span>\n";
$ok=0;
}
if (count($_POST['privacy'])>0) {
$ok=1;
} else {
print "<span class=\"orange\">Devi acconsentire al trattamento dei dati personali per inviare il modulo!</span>
\n";
$ok=0;
}
if ($ok==1) { //stampo il riepilogo
print "<h2>Riepilogo modulo d'ordine</h2>\n";
print "<div class=\"left\">\n\t<span class=\"orange\">Nome:</span> ".$_POST['nome']."
\n\t<span class=\"orange\">Indirizzo:</span> ".$_POST['indirizzo']."
\n\t<span class=\"orange\">C.A.P.</span> ".$_POST['cap']."
\n\t<span class=\"orange\">E-mail:</span> ".$_POST['email']."
\n</div>\n";
print "<div class=\"right\">\n\t<span class=\"orange\">Cognome:</span> ".$_POST['cognome']."
\n\t<span class=\"orange\">Città:</span> ".$_POST['citta']."
\n\t<span class=\"orange\">Provincia:</span> ".$_POST['provincia']."
\n\t<span class=\"orange\">Telefono/Cellulare:</span> ".$_POST['telefono']."
\n</div>\n";
print " <div class=\"spacer\"></div>\n";
print "</div>\n";
print "<span class=\"orange\">Materiale richiesto: </span>".$tipo_materiale."
\n";
print "<span class=\"orange\">Relativa alla/e gara/e: </span>".$gara."
\n";
print "<span class=\"orange\">Metodo di spedizione: </span>".$metodo_spedizione."
\n";
print "<form action=\"home.php?lang=ita&nav=0603&invia=1\" method=\"post\">\n\t<div id=\"submit\">\n\t<button type=\"submit\" name=\"mod\" value=\"no\"><img src=\"img/eng/p_form_back.gif\" alt=\"\" border=\"0\" /></button>\n<button type=\"submit\" name=\"mod\" value=\"ok\"><img src=\"img/eng/p_form_ok.gif\" alt=\"\" border=\"0\" /></button>\n\t</div>\n<input type=\"hidden\" name=\"nome\" value=\"".$_POST['nome']."\"><input type=\"hidden\" name=\"nome\" value=\"".$_POST['nome']."\"><input type=\"hidden\" name=\"indirizzo\" value=\"".$_POST['indirizzo']."\"><input type=\"hidden\" name=\"cap\" value=\"".$_POST['cap']."\"><input type=\"hidden\" name=\"email\" value=\"".$_POST['email']."\"><input type=\"hidden\" name=\"cognome\" value=\"".$_POST['cognome']."\"><input type=\"hidden\" name=\"citta\" value=\"".$_POST['citta']."\"><input type=\"hidden\" name=\"provincia\" value=\"".$_POST['provincia']."\"><input type=\"hidden\" name=\"telefono\" value=\"".$_POST['telefono']."\"><input type=\"hidden\" name=\"tipo_materiale\" value=\"".$_POST['tipo_materiale']."\"><input type=\"hidden\" name=\"gara\" value=\"".$_POST['gara']."\"><input type=\"hidden\" name=\"metodo_spedizione\" value=\"".$_POST['metodo_spedizione']."\"></form>\n<div class=\"spacer\"></div>\n";
if ((isset($_GET['invia'])) && ($_GET['invia']==1)) {
$email_destinatario = "xxxxx@xxxxxx.it";
$oggetto = "Richiesta materiale";
$corpo = "Richiesta materiale\n\nNome: ".$_POST['nome']."\nCognome: ".$_POST['cognome']."\nIndirizzo: ".$_POST['indirizzo']." - ".$_POST['cap']." ".$_POST['citta']." ".$_POST['provincia']."\nTipo di materiale desiderato: ".$tipo_materiale."\nRelativo alla/e gara/e: ".$gara."\nMetodo di spedizione:".$metodo_spedizione."\nRECAPITI:\n\nTelefono: ".$_POST['telefono']."\nEmail: ".$_POST['email']."\n\n";
if (mail ($email_destinatario, $oggetto, $corpo, "From: $email")) {
echo "<p class=\"bold\">Il modulo è stato inviato correttamente.
Grazie per il tuo interesse!</p>";
} else {
echo "<span class=\"errore\">Si è verificato un errore nell'invio del modulo.
Per favore prova di nuovo!</span>";
$ok=0;
}
}
}
}
if ($ok==0) {
?>
<form action="home.php?lang=ita&nav=0603" method="post">
<input type="hidden" name="required" id="required"
value="nome,indirizzo,cap,email,cognome,citta,provincia,tel,tipo_materiale,gara,metodo_spedizione,privacy" />
....
</form>
<?php
}
?>