Ciao a tutti ho fatto un sacco di ricerche senza riuscire a far funzionare un controllo perchè la pagina che inserisce i dati nel database mi da errore quando non viene inserito nessun dato nel form, posto i codici delle pagine in questione, magari qualcuno può darmi una mano.
Questo é lo script per il controllo :
<%@LANGUAGE = VBScript%>
<%
Dim nominativo, Nome, Messaggi
nome = Request.Form("nome")
messaggi = Request.Form("messaggi")
If nome = "" Then
Response.Write "Inserisci il tuo nominativo!"
ElseIf messaggio = "" Then
Response.Write "DEVI INSERIRE IL MESSAGGIO"
Else
With Response
.Write "NOME: " & NOME & "
"
.Write "messaggio: " & MESSAGGIO & "
"
End With
End If
%>
Questa è la pagina del form: messaggi.asp
<html>
<head>
<title>Invia_messaggio</title>
<style type="text/css">
.input {
color: #0098F8;
}
.story2{
width:270px;
border:1px solid #0098f8;
color:#0098f8;
font:bold 11px verdana,helvetica,sans-serif;
letter-spacing: .1em;word-spacing:.2em;
}
</style>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Invia Messaggio</title>
<script type="text/javascript" src="js/mootools-for-textarea.js"> </script>
<script type="text/javascript" src="js/UvumiTextarea-compressed.js"> </script>
<link rel="stylesheet" type="text/css" media="screen" href="css/uvumi-textarea.css" />
<style type="text/css">
body,html{
background-color:#ffffff;
margin:0;
padding:0;
font-family:Trebuchet MS, Helvetica, sans-serif;
}
#main{
margin:1% 1%;
height:350px;
width:460px;
position:relative;
overflow:false;
color:#aaa;
padding:20px;
border:1px solid #0098f8;
background-color:;
#
}
.style1 {
margin-left: 0px;
font-color: #0098F8;
font:bold 15px verdana,helvetica,sans-serif;
}
.style2 {
color: #0c16dc;
font: normal normal normal 15px verdana, helvetica, sans-serif;
}
</style>
<script type="text/javascript">
new UvumiTextarea({
selector:'textarea.withCounter',
maxChar:60
});
new UvumiTextarea({
selector:'textarea.withoutCounter',
maxChar:60
});
</script>
</head>
<body><div id="main" style="left: 0px; top: 0px; height: 301px">
<form method="POST" action="inserisci.asp" style="font: ; width: 438px; height: 277px;" class="style1">
<span class="style2">Nome</span> <input type="text"name="nome" class=input size="23">
</p>
<span class="style2">Messaggio</span>
<textarea id="story2" class="withCounter" onkeyup="test(this)" onchange="test(this)" align="left"
input type="text"name="messaggi" size="20" style="width: 270px; height:68px;"></textarea>
<input type="submit" value="Invia"name="x" style="width: 57px; height: 24px;"> </p>
</form>
</div>
</body>
</html>
Questa è la pagina inserisci.asp
<!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 content="it" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>inserisci</title>
<style type="text/css">
.style1 {
font-family: Verdana;
color: #0098F8;
font-size: small;
}
.style2 {
color: #0098F8;
}
</style>
</head>
<body>
<%
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
filePath = Server.Mappath("badwords_IT.txt")
filePath2 = Server.Mappath("badwords_EN.txt")
if objFileSystem.FileExists(filePath) then
Set objFile = objFileSystem.OpenTextFile(filePath, 1)
'leggo file riga per riga fino alla fine del file
Do While Not objFile.AtEndofStream
words=words&","&objFile.ReadLine
Loop
objFile.Close
Set objFile=Nothing
end if
if objFileSystem.FileExists(filePath2) then
Set objFile = objFileSystem.OpenTextFile(filePath2, 1)
'leggo file riga per riga fino alla fine del file
Do While Not objFile.AtEndofStream
words=words&","&objFile.ReadLine
Loop
objFile.Close
Set objFile=Nothing
end if
Set objFileSystem=Nothing
dim a,b
Function badWords(sText)
stringa = sText
words2=split(words,",")
for k=1 to Ubound(words2)
if words2(k)<>"" and not IsNull(words2(k)) then
l_stringa=0
n=0
asterischi=""
l_stringa=len(words2(k))
for n=1 to l_stringa
asterischi=asterischi&"*"
next
stringa = Replace(stringa, words2(k), asterischi)
end if
Next
badWords = stringa
End Function
a=badWords(request.form("nome"))
b=badWords(request.form("messaggi"))
Set Conn=Server.CreateObject("ADODB.Connection")
strConn="driver={Microsoft Access Driver (*.mdb)}; "
strConn= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("/mdb-database/messaggi.mdb")&";"
Conn.Open strConn
sql = "SELECT * FROM Messaggix"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn ,3,3
'scrittura nuovo record
rs.addnew
rs(1) = a
rs(2) = b
rs.update
' Chiusura del database
rs.Close
set rs = Nothing
conn.Close
set conn = Nothing
response.write "inserimento avvenuto"
%>
</body>