Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14

Discussione: Controllo dati form

  1. #1

    Controllo dati form

    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>

  2. #2
    Ciao,

    ma lo script per il controllo è nella pagina "inserisci.asp"?

    Secondo, la parte che cerca le parole nel txt...che poi aggiunge..ecc.., devi inserirla nel controllo, non fuori.

    Se tu metti quel codice di controllo all'inizio, e poi esegui comunque il resto del codice, ti da errore probabilmente sulle funzioni con i vari split e replace, perché trova le variabili vuote...

    Quindi:

    questo va bene all'inizio della pagina inserisci.asp, ma il codice che poi parte per l'inserimento devi metterlo dove ti evidenzio in rosso:

    <%@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

    QUI

    End If
    %>


    Quindi, dove c'è il "QUI", metti il codice di inserimento che parte con:

    Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")

    filePath = Server.Mappath("badwords_IT.txt")
    filePath2 = Server.Mappath("badwords_EN.txt")

    ....

    e finisce con

    response.write "inserimento avvenuto"


    Fai delle prove e dicci...
    vado a pranzo..poi alle 14 ricominciamo...

    Ciao

  3. #3
    ciao e scusa, ho avuto solo adesso lapossibilità di provare e di risponderti, prima di tutto Grazie per la risposta, poi, si lo script per il controllo è nella pagina inserisci asp, ho fatto le modifiche, e mi dice sempre di inserire i dati anche se li ho inseriti, ti posto il codice, grazie.

    !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">
    <%@LANGUAGE = VBScript%>
    <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>
    <p class="style2">
    <%
    Dim Nome, Messaggi
    nome = Request.Form("nome")
    messaggi = Request.Form("messaggi")
    If nome = "" Then
    Response.Write "DEVI INSERIRE IL TUO NOME!"
    ElseIf messaggio = "" Then
    Response.Write "DEVI INSERIRE IL MESSAGGIO"

    Else
    With Response
    .Write "NOME: " & NOME & "
    "
    .Write "messaggio: " & MESSAGGIO & "
    "
    End With

    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"

    End If

  4. #4
    ho eliminato questa parte e mi inserisce il messaggio, ma mi fa uscire sia il messaggio: inserimento avvenuto, che quello di compilare il form!


    Else
    With Response
    .Write "NOME: " & NOME & "
    "
    .Write "messaggio: " & MESSAGGIO & "
    "
    End With

  5. #5
    Ciao,

    ElseIf messaggio = "" Then

    in realtà è

    ElseIf messaggi = "" Then

    altrimenti ti scrive sì di inserire il messaggio...perché è una variabile sempre vuota..

    Riprova così.

  6. #6
    ciao così non mi da il mess dell'avvenuto invio, ne quello dei dati errati! .. ormai è tardi ciao e grazie!

  7. #7
    Codice PHP:
    <%
    Dim NomeMessaggi
    nome 
    Request.Form("nome")
    messaggi Request.Form("messaggi")
    If 
    nome "" Then Response.Write "DEVI INSERIRE IL TUO NOME!"
    If messaggi "" Then Response.Write "DEVI INSERIRE IL MESSAGGIO"


    if nome<>"" and messaggi<>"" then

    Set objFileSystem 
    Server.CreateObject("Scripting.FileSystemObject")

    filePath Server.Mappath("badwords_IT.txt")
    filePath2 Server.Mappath("badwords_EN.txt")

    if 
    objFileSystem.FileExists(filePaththen
    Set objFile 
    objFileSystem.OpenTextFile(filePath1)
    '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(stringawords2(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 sqlconn ,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"

    End If
    %> 
    Prova così...

  8. #8
    ciao, così funziona!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ma posso aggiungere una cosa del tipo se non trovi errori chiudi la finestra in esecuzione? (che poi è in un popup)

  9. #9
    Qui passiamo a Javascript...comunque:

    al posto di

    response.write "inserimento avvenuto"

    puoi mettere ad esempio:

    Questo codice se vuoi che ti chiuda solo la finestra popup

    %>
    <p style="text-align: center; color: #008000;">Inserimento effettuato correttamente!</p>
    <p style="text-align: center;">Chiudi la finestra</p>
    <%

    Questo se vuoi che oltre a chiudere la finestra, ti ricarichi anche la pagina che ha aperto la popup

    %>
    <p style="text-align: center; color: #008000;">Inserimento effettuato correttamente!</p>
    <p style="text-align: center;">Chiudi la finestra</p>
    <%

    Prova...

  10. #10
    ciao, grazie infinite, lo provo stasera, perchè al lavoro non riesco ad accedere al server che mi serve... sai i proxy!!!
    comunque grazie, se passi da da garibaldi,cadorna o zona lotto dimmelo che hai qualche caffè di credito!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.