Buongiorno a tutti, qualcuno può aiutarmi per favore?
Nel form che vedete qui sotto, vorrei aggiungere un controllo del campo checkbox (destinazione) in modo da poter inviare il form compilato ad indirizzi mail diversi in base alla scelta del campo destinazione, purtroppo non ci riesco, qualcuno può aiutarmi?
// ----settiamo il fuoco iniziale e l'inizio e la fine dell'index-focus
Selection.setFocus("nomeCognome");
destinazione="";
nomeCognome = "";
azienda = "";
posizioneAzienda = "";
indirizzo = "";
citta = "";
cap = "";
provincia = "";
telefono = "";
email = "";
messaggio = "";
var mailTo = "mariorossi@tin.it";
nomeCognome.tabIndex = 0;
azienda.tabIndex = 1;
posizioneAzienda.tabIndex = 2;
indirizzo.tabIndex = 3;
citta.tabIndex = 4;
cap.tabIndex = 5;
provincia.tabIndex = 6;
telefono.tabIndex = 7;
email.tabIndex = 8;
messaggio.tabIndex = 9;
// --controlliamo l'inserimento nei campi-------
function controllo() {
now = getTimer();
// ------controllo dell'e-mail---------
email1 = email.lastIndexOf('@');
if (email1>=2) {
m1 = true;
} else {
m1 = false;
}
email2 = email.lastIndexOf('.');
if ((email2-email1)>=2) {
m2 = true;
} else {
m2 = false;
}
email3 = email.substr(email2,
email.length);
if (email3.length>=3) {
m3 = true;
} else {
m3 = false;
}
// ----controllo degli altri campi obbligatori----
if (nomeCognome.length>3) {
valnomeCognome = true;
} else {
valnomeCognome = false;
}
if (citta.length>3) {
valcitta = true;
} else {
valcitta = false;
}
if (azienda.length>2) {
valazienda = true;
} else {
valazienda = false;
}
if (telefono.length>6) {
valtelefono = true;
} else {
valtelefono = false;
}
// ---invio del modulo------
if (m1 & m2 & m3 & valnomeCognome & valcitta & valazienda & valtelefono) {
go.start(0, 1);
email = "" add email;
out = "invio dati...";
gotoAndStop(1);
getURL("feedback.jsp?email=" add email add "&destinazione=" add destinazione add "&nomeCognome=" add nomeCognome add "&azienda=" add azienda add "&posizioneAzienda=" add posizioneAzienda add "&indirizzo=" add indirizzo add "&citta=" add citta add "&cap=" add cap add "&provincia=" add provincia add "&telefono=" add telefono add "&messaggio=" add messaggio add "", "_self", "GET");
}
//getURL("feedback.jsp?email=" add mail add "&destinazione=" add destinazione add "&nomeCognome=" add nomeCognome add "&azienda=" add azienda add "&posizioneAzienda=" add posizioneAzienda add "&indirizzo=" add indirizzo add "&citta=" add citta add "&cap=" add cap add "&provincia=" add provincia add "&telefono=" add telefono add "&messaggio=" add messaggio add "", "_self", "GET");
play();
errore();
alert.start(0, 1 );
}
// -----codici di errore-----
function errore() {
if (!m1|!m2|!m3) {
out = "Inserire un indirizzo email valido";
gotoAndStop(4);
Selection.setFocus("email");
}
if (!valnomeCognome) {
// out="Inserire un Nome e/o un Cognome valido";
gotoAndStop(3);
Selection.setFocus("nomeCognome");
}
if (!valcitta) {
// out="Inserire un nome di citta' valido";
gotoAndStop(2);
Selection.setFocus("citta");
}
if (!valazienda) {
// out="Inserire un nome azienda valido";
gotoAndStop(5);
Selection.setFocus("azienda");
}
if (!valtelefono) {
// out="Inserire un nunero di telefono valido";
gotoAndStop(6);
Selection.setFocus("telefono");
}
}
// ---reset----
function goReset() {
nomeCognome = "";
azienda = "";
posizioneAzienda = "";
indirizzo = "";
citta = "";
cap = "";
provincia = "";
telefono = "";
email = "";
messaggio = "";
}
Nel file feedback.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="javax.mail.*, javax.mail.internet.*, java.util.*, java.io.*, javax.activation.*, javax.servlet.http.*, java.net.*"%>
<%!
public void sendEmail (String to, String subject, String message)
{
try
{
Properties prop = new Properties();
try{
prop.load(new FileInputStream(new File(new URI("file:///C:/Programmi/Tomcat/webapps/ROOT/ /web/Resources/PopAttach.conf"))));
}
catch ( Exception ex ){
ex.printStackTrace();
System.out.println("File di configurazione PopAttach.conf non trovato.");
}
Session ses1 = Session.getDefaultInstance(prop,null);
MimeMessage msg = new MimeMessage(ses1);
msg.setFrom(new InternetAddress(prop.getProperty("mail.from")));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
msg.setSubject(subject);
// Create the message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText(message);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart.setContent(message, "text/html");
msg.setContent(multipart);
Transport.send(msg);
}
catch (javax.mail.MessagingException me)
{
me.printStackTrace();
}
}
%>
<head>
<link href="css/main.css" rel="stylesheet" media="screen">
<title>::: Contact :::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
a {
font-family: Arial, Helvetica, sans-serif;
}
-->
</style></head>
<body>
<table width="900" align="center">
<tr>
<td><div align="center"><width="100" height="51"></div></td>
</tr>
<tr>
</tr>
<tr>
<td class="text10_99"><div align="center">La Vostra richiesta è stata correttamente inoltrata.
Sarete contattati al più presto.
</div></td>
<%
String message= new String();
// message += "<BODY bgColor=\"#e5e5e5\" leftMargin=\"10\" topMargin=\"31\" marginwidth=\"0\" marginheight=\"31\">";
// message += "<CENTER><IMG height=\"23\" alt=\"\" src=\"http://www.humantech.it/img/logo_astra.jpg\" width=\"100\" height=\"51\" border=\"0\">";
// message += "
";
// message += "<font color=\"#666666\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Richiesta Brochure" + "</font></CENTER>";
// message += "
";
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Dati Richiedente:
" + "</font>";
int i = 0;
if (request.getParameter("azienda")!=null)
{
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Azienda: " + request.getParameter("azienda") + "</font>" + "
";
}
if (request.getParameter("nomeCognome")!=null)
{
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Nome e Cognome: " + request.getParameter("nomeCognome") + "</font>" + "
";
}
if (request.getParameter("posizioneAzienda")!=null)
{
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Posizione in azienda: " + request.getParameter("posizioneAzienda") + "</font>" + "
";
}
if (request.getParameter("cap")!=null)
{
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">CAP: " + request.getParameter("cap") + "</font>" + "
";
}
if (request.getParameter("citta")!=null)
{
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Città: " + request.getParameter("citta") + "</font>" + "
";
}
if (request.getParameter("provincia")!=null)
{
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Provincia: " + request.getParameter("provincia") + "</font>" + "
";
}
if (request.getParameter("indirizzo")!=null)
{
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Indirizzo: " + request.getParameter("indirizzo") + "</font>" + "
";
}
if (request.getParameter("telefono")!=null)
{
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Telefono: " + request.getParameter("telefono") + "</font>" + "
";
}
// if (request.getParameter("email")!=null)
// }
if (request.getParameter("email")!=null)
{
out.print("");
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Email:" + request.getParameter("email") + "</font>" + "
";
out.print("");
}
if (request.getParameter("messaggio")!=null)
{
message += "<font color=\"#333333\" size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\">Messaggio:" + request.getParameter("messaggio") + "\n";
}
sendEmail ("mariorossi@tin.it", "Richiesta contatto dal sito ", message);
%>
</tr>
</table>
<table width="900" align="center">
<tr>
<td bgcolor="#FFFFFF" align="center" class="text10_00B"><div align="center"> </div></td>
</tr>
</table>
<div align="center">
<table width="900" height="112">
<tr>
<td height="59" valign="middle"><div align="center">Torna al sito</div></td>
</tr>
</table>
</div>
</body>