-
Avendo creato questo formmail, come faccio a fare in modo che l'utente sia obbligato a riempire tutti i campi o magari quelli principali tipo nome,cognome ,email ?
<%
theSchema="http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig=server.CreateObject("CDO.Configuration")
cdoConfig.Fields.Item(theSchema & "sendusing")=2
cdoConfig.Fields.Item(theSchema & "smtpserver")="localhost"
cdoConfig.Fields.Updateset cdoMessage=Server.CreateObject("CDO.Message")
cdoMessage.Configuration=cdoConfigcdoMessage.From=Request.Form("email")
cdoMessage.To="[email protected]"
cdoMessage.Subject=Request.Form("subject")
cdomessage.HtmlBody="Nome:" & request.form("nome") & "<br/>Cognome:" & Request.form("cognome") & "<br/>Citta:" & request.form("citta") & "<br/>Email:" & request.Form("email") & "<br/>Commenti:" & request.Form("commenti")
cdoMessage.SendSet cdoMessage=Nothing
Set cdoConfig=Nothing
%> -
Direi che puoi fare dei semplici controlli sulle stringhe e vedere se effettivamente contengono qualche valore, ad esempio:
<% If Trim(Request.Form("email")) = "" Or Trim(Request.Form("subject")) Or Trim(Request.Form("Nome")) = "" Or Trim(Request.Form("cognome")) Or Trim(Request.Form("citta")) = "" Or Trim( Request.Form("commenti")) Then Response.write "Attenzione tutti i campi sono obbligatori" Else theSchema="http://schemas.microsoft.com/cdo/configuration/" Set cdoConfig=server.CreateObject("CDO.Configuration") cdoConfig.Fields.Item(theSchema & "sendusing")=2 cdoConfig.Fields.Item(theSchema & "smtpserver")="localhost" cdoConfig.Fields.Update set cdoMessage=Server.CreateObject("CDO.Message") cdoMessage.Configuration=cdoConfig cdoMessage.From=Request.Form("email") cdoMessage.To="[email protected]" cdoMessage.Subject=Request.Form("subject") cdomessage.HtmlBody="Nome:" & request.form("nome") & "<br/>Cognome:" & Request.form("cognome") & "<br/>Citta:" & request.form("citta") & "<br/>Email:" & request.Form("email") & "<br/>Commenti:" & request.Form("commenti") cdoMessage.Send Set cdoMessage=Nothing Set cdoConfig=Nothing End If %>Ovviamente devi giocare te con i campi e decidere quali rendere obbligatori, potresti anche metterci un controllo tramite RE per verificare che l'utente inserisca una mail corretta.
Ciao

-
Io consiglio sempre di abbinare al controllo lato server anche un controllo in Javascript per evitare all'utente di far ricaricare la pagina nel caso di errori. A volte connessioni/pc troppo lente/i fanno si che l'utente si spazientisca e magari se ne va al primo errore.
Se il client non supportasse js allora interverrebbe il controllo asp

Ciao.
-
-
Mi correggo......non avevo verificato sul campo.....!!!
La verifica funziona, il problema è che la scritta "Attenzione i campi...sono obbligatori" appare in alto e non dove vi è il form e la pagina dove si ringrazia l'utente per aver compilato il form appare ugualmente anche se si invia con i campi vuoti !
p.s
la pag dei ringraziamenti è la stessa dove vi è il form cioè questa<%
If Trim(Request.Form("email")) = "" Or Trim(Request.Form("subject")) Or Trim(Request.Form("Nome")) = "" Or Trim(Request.Form("cognome")) Or Trim(Request.Form("citta")) = "" Or Trim( Request.Form("commenti")) Then
Response.write "Attenzione tutti i campi sono obbligatori"Else
theSchema="http://schemas.microsoft.com/cdo/configuration/" Set cdoConfig=server.CreateObject("CDO.Configuration") cdoConfig.Fields.Item(theSchema & "sendusing")=2 cdoConfig.Fields.Item(theSchema & "smtpserver")="localhost" cdoConfig.Fields.Update set cdoMessage=Server.CreateObject("CDO.Message") cdoMessage.Configuration=cdoConfig cdoMessage.From=Request.Form("email") cdoMessage.To="[email protected]" cdoMessage.Subject=Request.Form("subject") cdomessage.HtmlBody="Nome:" & request.form("nome") & "<br/>Cognome:" & Request.form("cognome") & "<br/>Citta:" & request.form("citta") & "<br/>Email:" & request.Form("email") & "<br/>Commenti:" & request.Form("commenti") cdoMessage.Send Set cdoMessage=Nothing Set cdoConfig=NothingEnd If
%> -
se posti un po' più di codice (non tutta la pagina :D) guardiamo dove sta il problema.
Ciao

-
questo è il file invimail.asp
<%
If Trim(Request.Form("email")) = "" Or Trim(Request.Form("Nome")) = "" Or Trim(Request.Form("cognome"))= "" Then
Response.write "Attenzione i campi nome, cognome ed email sono obbligatori"
Else
theSchema="http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig=server.CreateObject("CDO.Configuration")
cdoConfig.Fields.Item(theSchema & "sendusing")=2
cdoConfig.Fields.Item(theSchema & "smtpserver")="localhost"
cdoConfig.Fields.Updateset cdoMessage=Server.CreateObject("CDO.Message") cdoMessage.Configuration=cdoConfig cdoMessage.From=Request.Form("email") cdoMessage.To="[email protected]" cdoMessage.Subject=Request.Form("subject") cdomessage.HtmlBody="Nome:" & request.form("nome") & "<br/>Cognome:" & Request.form("cognome") & "<br/>Citta:" & request.form("citta") & "<br/>Email:" & request.Form("email") & "<br/>Commenti:" & request.Form("commenti") cdoMessage.Send Set cdoMessage=Nothing Set cdoConfig=NothingEnd If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento senza titolo</title>
<style type="text/css">..............................ecc.ecc.ecc.ancora sotto......
</head>
<body>
RINGRAZIANDOLA PER L'ATTENZIONE LE RISPONDEREMO IL PIU' PRESTO POSSIBILE</span> ..................................ecc.ecc.ecc.
</table>
</body>
</html>Naturalmente la scritta "RINGRAZIANDOLA PER L'ATTENZIONE.....DOVREBBE APPARIRE SOLO QUANDO VIENE INVIATA L'IMAIL, MENTRE SE SE VI E' UN CAMPO VUOTO DOVREBBE APPARIRE L'AVVISO DI ATTENZIONE"
-
Ciao, per postare il codice usa il tag [ CODE ] [ /CODE ], almeno è più leggibile

Ma veniamo allo script, direi che così dovrebbe funzionare:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Documento senza titolo</title> <style type="text/css">..............................ecc.ecc.ecc. </head> <body> <% If Trim(Request.Form("email")) = "" Or Trim(Request.Form("Nome")) = "" Or Trim(Request.Form("cognome"))= "" Then Response.write "Attenzione i campi nome, cognome ed email sono obbligatori" Else theSchema="http://schemas.microsoft.com/cdo/configuration/" Set cdoConfig=server.CreateObject("CDO.Configuration") cdoConfig.Fields.Item(theSchema & "sendusing")=2 cdoConfig.Fields.Item(theSchema & "smtpserver")="localhost" cdoConfig.Fields.Update set cdoMessage=Server.CreateObject("CDO.Message") cdoMessage.Configuration=cdoConfig cdoMessage.From=Request.Form("email") cdoMessage.To="[email protected]" cdoMessage.Subject=Request.Form("subject") cdomessage.HtmlBody="Nome:" & request.form("nome") & "<br/>Cognome:" & Request.form("cognome") & "<br/>Citta:" & request.form("citta") & "<br/>Email:" & request.Form("email") & "<br/>Commenti:" & request.Form("commenti") cdoMessage.Send Set cdoMessage=Nothing Set cdoConfig=Nothing %> RINGRAZIANDOLA PER L'ATTENZIONE LE RISPONDEREMO IL PIU' PRESTO POSSIBILE</span> ..................................ecc.ecc.ecc. <% End If %> </table> </body> </html>Ciao


-
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi