Dopo aver compreso la funzionalita’ di filter_var realizziamo un semplice form con validazione dei dati ed invio di una mail di conferma che includera’:
– nome
– email
– Home Page
– Messaggio
Una volta che tutti i dati saranno stati corretti e validati verra’ inviata una mail di conferma all’indirizzo inserito.
Il primo passo e’ la creazione del form:
<form name=”modulo” method=”post”>
Nome: <br/>
<input type=”text” name=”nome” value=”<?php echo $nome; ?>” size=”50″ /><br/><br/>
Email: <br/>
<input type=”text” name=”email” value=”<?php echo $email; ?>” size=”50″/> <br/><br/>
Home Page: <br/>
<input type=”text” name=”url” value=”<?php echo $url; ?>” size=”50″ /> <br/><br/>
Messaggio: <br/>
<textarea name=”msg” rows=”5″ cols=”50″><?php echo $msg; ?></textarea>
<br/>
<input type=”submit” name=”Submit” />
</form>
In testa al form dovra’ essere inserito il seguente codice PHP:
<?php
$errori = “”; // Ci verranno inseriti gli errori da mostrare a video…
isset($_POST[‘nome’]) ? $nome = $_POST[‘nome’] : $nome = “”;
isset($_POST[‘email’]) ? $email = $_POST[‘email’] : $email = “”;
isset($_POST[‘url’]) ? $url = $_POST[‘url’] : $url = “”;
isset($_POST[‘msg’]) ? $msg = $_POST[‘msg’] : $msg = “”;
if (strlen($nome)>0)
$nome = filter_var($nome, FILTER_SANITIZE_STRING);
if ($nome == “”)
$errori .= ‘Inserire un nome valido.<br/><br/>’;
if (strlen($email)>0)
{
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
$errori .= “$email non e’ un indirizzo mail valido<br/><br/>”;
}
if ($email == “”)
$errori .= “Indirizzo mail non valido o non presente<br/><br/>”;
if (strlen($url)>0)
{
$url = filter_var($url, FILTER_SANITIZE_URL);
if (!filter_var($url, FILTER_VALIDATE_URL))
$errori .= “$url non e’ un URL valido<br/><br/>”;
}
if ($url == “”)
$errori .= “URL non presente o non valido<br/><br/>”;
if (strlen($msg)>0)
$msg = filter_var($msg, FILTER_SANITIZE_STRING);
if ($msg == “”)
$errori .= ‘Inserire il messaggio da inviare.<br/><br/>’;
// Controllo gli errori…
if (strlen($errori) > 0)
echo ‘<div style=”color: red”>’ . $errori . ‘<br/></div>’;
else
{
$destinatario = ‘info@freescriptphp.com’; // Da cambiare in base alle esigenze
$subject = ‘Mail dal form’;
$message = ‘From: ‘.$nome.”\n”;
$message .= ‘Email: ‘.$email.”\n”;
$message .= ‘Homepage: ‘.$url.”\n”;
$message .= “Message:\n”.$msg.”\n\n”;
mail($destinatario, $subject, $message);
}
?>
This is the best technique to be followed, I must say that really being here and not using this will really be silly. Will you please reply with more information here? I think you have a good response and it will definitely help a lot. As this forum has really been a good platform for us all, contributing to this will really be healthy for our and your business as well. We all are waiting for a good informative response. Thanks a lot for this, waiting for more.
Thank you on your assist!
Awesome post, are you on facebook?
Great blog here! Also your web site loads up very fast! What host are you using? Can I get your affiliate link to your host? I wish my site loaded up as quickly as yours lol
some really nice and useful info on this internet site , as well I conceive the style holds great features.
*Nice post. I learn something more challenging on different blogs everyday. It will always be stimulating to read content from other writers and practice a little something from their store. I’d prefer to use some with the content on my blog whether you don’t mind. Natually I’ll give you a link on your web blog. Thanks for sharing.
I am pleased to let you know your website has been selected for http://www.interesting-blogs.info . This website is now featuring on our homepage.
Thanks a lots for your listing and have a good day.
Actually we are using the dedicated hosting.
No, I don’t like FB.
Mail sent.
Hey there just wanted to give you a quick heads up. The words in your article seem to be running off the screen in Chrome. I’m not sure if this is a formatting issue or something to do with internet browser compatibility but I thought I’d post to let you know. The layout look great though! Hope you get the issue solved soon. Kudos
Hi Bobbie,
thanks a lots for your check; I have update wordpress and now it seems that everything works fine..is it ok also for you ?
Have a good day,
Leonardo