Salve a tutti,
devo inserire un form nel mio sito; attualmente è composto di un file html con il form, e un file php col "motore" e il controllo dei campi.
Ecco il codice dell'html:
form method="post" action=invio.php>
<table width="75%" border="0">
<tr>
<td width="9%">Nome*</td>
<td width="1%"> </td>
<td width="90%">
<input name="nome" type="text" size="50" maxlength="40" />
</td>
</tr>
<tr>
<td width="9%">Telefono*</td>
<td width="1%"> </td>
<td width="90%">
<input name="tel" type="text" size="50" maxlength="40" />
</td>
</tr>
<tr>
<td width="9%">Indirizzo</td>
<td width="1%"> </td>
<td width="90%">
<input type="text" name="indirizzo" size="50">
</td>
</tr>
<tr>
<td width="9%">Città</td>
<td width="1%"> </td>
<td width="90%">
<input name="città" type="text" size="50" maxlength="40" />
</td>
</tr>
<tr>
<td width="9%">Email*</td>
<td width="1%"> </td>
<td width="90%">
<input name="email" type="text" size="50" maxlength="40" />
</td>
</tr>
<tr>
<td width="9%">Oggetto*</td>
<td width="1%"> </td>
<td width="90%">
<input name="oggetto" type="text" size="50" maxlength="40" />
</td>
</tr>
<tr>
<td width="9%" height="27">
<div align="left">
<p>Messaggio*</p>
<p> </p>
<p> </p>
</div>
</td>
<td width="1%" height="27"> </td>
<td width="90%" height="27">
<textarea name="msg" cols="38" rows="6"></textarea>
</td>
</tr>
<tr>
<td width="9%" height="27"> </td>
<td width="1%" height="27"> </td>
<td width="90%" height="27">
<input type="reset" value="Reset" name="reset" />
<input type="submit" value="Invia" name="submit" />
</td>
</tr>
</table>
</form>
<p>* = campi obbligatori</p>
```e il codice php:
<?php
$mail = "[email protected]";
$nome = ltrim(rtrim(strip_tags(stripslashes($_POST['nome']))));
$tel = ltrim(rtrim(strip_tags(stripslashes($_POST['tel']))));
$indirizzo = ltrim(rtrim(strip_tags(stripslashes($_POST['indirizzo']))));
$città = ltrim(rtrim(strip_tags(stripslashes($_POST['città']))));
$email = ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));
$oggetto = ltrim(rtrim(strip_tags(stripslashes($_POST['oggetto']))));
$msg = ltrim(rtrim(strip_tags($_POST['msg'])));
$ip = getenv("REMOTE_ADDR");
$msgformat = "$nome,$email ($ip)\n$tel\n$indirizzo\n$cittàn\n$msg";
// VALIDATION
if(empty($nome) || empty($tel) || empty($email) || empty($oggetto) || empty($msg)) {
echo "<h3>Compilare i campi obbligatori</h3>";
}
elseif(!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $email)) {
echo "<h3>Indirizzo e-mail non valido</h3>";
}
else {
mail($mail, $oggetto, $msgformat, "From: $nome <$email>");
echo "<h3>L'email è stata inviata</h3><p>Vi risponderemo il prima possibile</p>"; }
?>
* Vorrei fare in modo che una volta inviato con successo il form, dopo tipo 5 secondi mi riporti ad un'altra pagina;
* Questa, la più importante: attualmente se non viene compilato un campo obbligatorio, rimanda solamente un messaggio di errore. Vorrei invece che nel caso non venisse compilato un campo obbligatorio (ma gli altri si) non visualizzasse solamente l'errore ma l'errore e sotto il form, coi campi compilati, e quelli da compilare evidenziati (in rosso magari).
Spero di essere stato chiaro, vi ringrazio anticipatamente per l'eventuali risposte