Ciao a tutti,
sto modificando questa estensione (link:
http://extensions.joomla.org/extensions/contacts-and-feedback/contact-forms/19835) per introdurre un controllo sui campi inseriti.
Purtroppo non ne so molto di javascript e al momento sono fermo qua:
<script type="text/javascript">
[...]
$('amCallMeBackForm').getElements('form').addEvent('submit', function(e) {
new Event(e).stop();
new Request({
method: "post",
data: this,
onRequest: function() {
$('amCallMeBackForm').empty().addClass('amCallMeBackWait');
$('callback').setStyle('background', 'url(\'[url]http://www.miosito.it/modules/mod_amcallmeback/assets/sfondo_callback.png\[/url]') no-repeat transparent');
$('callback').setStyle('height', '73px');
},
onComplete: function(send) {
$('amCallMeBackForm').removeClass('amCallMeBackWait');
$('amCallMeBackForm').addClass('amCallMeBackSent');
// $('amCallMeBackForm').set('html',send.responseText);
$('amCallMeBackForm').set('html', 'Abbiamo riscontrato un errore. Controlla di aver inserito tutti i dati.');
}
}).send();
jQuery(document).ready(function() {
jQuery("#callback").delay(3000).slideUp("slow");
});
});</script>
Cosa succede? In pratica questa parte di codice è quella che va a chiamare il file helper.php. La riga commentata (
send.responseText) è quella che ho tentato di inserire per ottenere la risposta dal file php e quindi gestire quale messaggio mostrare dopo aver inviato il form.
Tuttavia una volta cliccato il submit, sia che io abbia compilato, sia che non lo abbia fatto, non viene restituito nessun testo.
Ecco com'è composto il file helper.php:
<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.mail.helper');
class modAmCallMeBackHelper
{
function send($params) {
// Check for request forgeries
JRequest::checkToken() or die( 'Invalid Token' );
// get data
$name = JRequest::getVar('name', '');
$rif = JRequest::getVar('rif', '');
$phone = JRequest::getVar('phone', '');
$uri = JRequest::getVar('uri', '');
if ($name == '' || $rif == '' || $phone == '' || $name == 'Azienda' || $rif == 'Riferimento' || $phone == 'Telefono') {
return 'Error sending email';
}
// get module params
$subject = $params->get('mail_subject');
$reciptient = explode(',', $params->get('receipt_email'));
$app = JFactory::getApplication();
$sender = array($app->getCfg('mailfrom'), $app->getCfg('fromname'));
// make email
$Body = '<strong>Azienda:</strong> '.$name."[br /]";
$Body .= '<strong>Riferimento:</strong> '.$rif."[br /]";
$Body .= '<strong>Numero di telefono:</strong> '.$phone."[br /]";
$Body .= '<strong>Pagina da cui è stato richiesto il contatto:</strong> <a href='.$uri.'>'.$uri."";
$mailer =& JFactory::getMailer();
$mailer->setSender($sender);
$mailer->addRecipient($reciptient);
$mailer->setSubject($subject);
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($Body);
$send =& $mailer->Send();
if ($send != true) {
return 'Error sending email';
} else {
return 'Request is sent';
}
}
}
Arrivando ad un dunque, come posso far partire dall'helper.php una risposta che mi venga visualizzata nella prima porzione di codice (e quindi poi stampata a schermo)?
Spero di essere stato sufficientemente chiaro,
Grazie in anticipo!!