allora,
includes/contatti/metatags.php, in questo file ho inserito l'fw MooTools e l'evento per la richiesta ajax
Codice PHP:
<?php
echo '<i vari metatag />
....
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="css/common.css?'.time().'" type="text/css" />
<!--[if lte IE 6]>
<style type="text/css">
@import url("css/pngfix.css");
</style>
<![endif]-->
<!--[if IE]>
<style type="text/css">
@import url("css/iefix.css");
</style>
<![endif]-->
<script type="text/javascript" language="javascript" src="js/mootools.v1.1.js"></script>
<script type="text/javascript" language="javascript" src="js/common.js"></script>
<script type="text/javascript" language="javascript" src="js/tabcontent.js"></script>
<script type="text/javascript" language="javascript" src="js/ajaxreq.js"></script>';
?>
js/ajaxreq.js
Codice PHP:
$('csend').addEvent('submit', function(e) {
/**
* Prevent the submit event
*/
new Event(e).stop();
/**
* This empties the log and shows the spinning indicator
*/
var log = $('log_res').empty().addClass('ajax-loading');
/**
* send takes care of encoding and returns the Ajax instance.
* onComplete removes the spinner from the log.
*/
this.send({
update: log,
onComplete: function() {
log.removeClass('ajax-loading');
}
});
});
questo è il form html (includes/contatti/corposx.php)
Codice PHP:
<div id="contform" align="center">
<div id="log">
<div id="log_res">
</div>
</div>
<form action="includes/contatti/form.php" id="csend" method="post">
<div id="cname" onmouseover="this.style.background='#7caa69'; this.style.color='#ffffff'" onmouseout="this.style.background=''; this.style.color='#333333'">
* Nome:
<input type="text" name="cname" />
</div>
<div id="cmail" onmouseover="this.style.background='#7caa69'; this.style.color='#ffffff'" onmouseout="this.style.background=''; this.style.color='#333333'">
* E-mail:
<input type="text" name="cmail" />
</div>
<div id="ctext" onmouseover="this.style.background='#7caa69'; this.style.color='#ffffff'" onmouseout="this.style.background=''; this.style.color='#333333'">
* Testo:
<textarea name="ctext" rows="8" cols="28"></textarea>
</div>
<button type="reset" name="creset" title="Cancella">[img]img/contatti/cancel.gif[/img]</button> <button type="submit" name="csend" title="Invia">[img]img/contatti/next.gif[/img]</button>
</form>
</div>
includes/contatti/form.php (senza usare ajax confermo il suo funzionamento.)
Codice PHP:
<?php
$nameErr = FALSE;
$mailErr = FALSE;
$textErr = FALSE;
$err = FALSE;
$msg = '';
if(isset($_POST['csend'])) {
$name = cleanInputForm($_POST['cname']);
$mail = cleanInputForm($_POST['cmail']);
$text = cleanInputForm($_POST['ctext']);
$msgErr = array();
if(my_is_numeric($name)) {
$err = true;
$nameErr = true;
$msgErr[] = 'Il campo "Nome" non può essere un numero';
}
if(isEmptyString($name)) {
$err = true;
$nameErr = true;
$msgErr[] = 'Il campo "Nome" non può essere vuoto';
}
if(strlen($name)<2) {
$err = true;
$nameErr = true;
$msgErr[] = 'Il campo "Nome" non può essere inferiore ai 2 caratteri';
}
if(contieneBadwords($name)) {
$err = true;
$nameErr = true;
$msgErr[] = 'Il campo "Nome" non può contenere vocaboli volgari e parolacce';
}
if(stringaCaratteriUguali($name)) {
$err = true;
$nameErr = true;
$msgErr[] = 'Il campo "Nome" non può essere formato da soli caratteri uguali';
}
if(my_is_numeric($mail)) {
$err = true;
$mailErr = true;
$msgErr[] = 'Il campo "E-mail" non può essere un numero';
}
if(isEmptyString($mail)) {
$err = true;
$mailErr = true;
$msgErr[] = 'Il campo "E-mail" non può essere vuoto';
}
if(strlen($mail)<9) {
$err = true;
$mailErr = true;
$msgErr[] = 'Il campo "E-mail" non può essere inferiore ai 9 caratteri';
}
if(stringaCaratteriUguali($mail)) {
$err = true;
$mailErr = true;
$msgErr[] = 'Il campo "E-mail" non può essere formato da soli caratteri uguali';
}
if(!isValidEmail($mail)) {
$err = true;
$mailErr = true;
$msgErr[] = 'Il campo "E-mail" non può essere scritto in questo modo';
}
if(my_is_numeric($text)) {
$err = true;
$textErr = true;
$msgErr[] = 'Il campo "Testo" non può essere un numero';
}
if(isEmptyString($text)) {
$err = true;
$textErr = true;
$msgErr[] = 'Il campo "Testo" non può essere vuoto';
}
if(strlen($text)<10) {
$err = true;
$textErr = true;
$msgErr[] = 'Il campo "Testo" non può essere inferiore ai 10 caratteri';
}
if(contieneBadwords($text)) {
$err = true;
$textErr = true;
$msgErr[] = 'Il campo "Testo" non può contenere vocaboli volgari e parolacce';
}
if(stringaCaratteriUguali($text)) {
$err = true;
$textErr = true;
$msgErr[] = 'Il campo "Testo" non può essere formato da soli caratteri uguali';
}
if($err) {
$msg = '<span style="color: #cc0000; font-weight: bold">Hai commesso i seguenti errrori nella compilazione del form:
';
foreach($msgErr as $ierr) {
$msg .= $ierr.'
';
}
$msg .= '</span>';
} else {
$msg = 'tutto ok';
}
}
?>
e questo il piccolo css per i div dei risultati.
Codice PHP:
#log {
float: left;
padding: 0.5em;
margin-left: 10px;
width: 290px;
border: 1px solid #d6d6d6;
border-left-color: #e4e4e4;
border-top-color: #e4e4e4;
margin-top: 10px;
}
#log_res {
overflow: auto;
}
#log_res.ajax-loading {
padding: 20px 0;
background: url(../img/contatti/loading.gif) no-repeat center;
}