Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Script per inserimento testo lato amministrazione

    Salve,
    un cliente mi scrive "avere la possibilità di scrivere da parte dell’utente in un box del sito web", per cui avrei la necessità di creare un form con uno script per inserire, da area amministrativa, un testo che può essere aggiornato.
    Qualcuno può aiutarmi? l'area amministrativa credo sia già esistente nel suddetto sito web.
    Hutton

    "Una tela bianca, offre infinite possibilità."

  2. #2
    Potresti creare un form e salvare il testo inserito in un file txt.
    Ti faccio un esempio:

    Codice PHP:
    <?php
    class form {
        
    // parametri
        
    var $separatore_righe "--start--";
        var 
    $separatore_campi "--end--";
            
    // questa variabile serve per stabilire il numero di record mostrati per pagina
        
    var $record_per_pagina 3;
            
    // Info sul file txt
        
    var $percorso_fisico_guest "";
        var 
    $guesttxt "guests.txt";
        var 
    $nomefile;
        
        
    //Largezza dei messaggi mostrati
        
    var $larghezza_tabella "500";
            
            
    // da qui inizia lo script vero e proprio
        
    var $righe = array();
        var 
    $posizione;
        var 
    $numero_righe;
        var 
    $book;
        var 
    $linea;
        function 
    form() {
            
    $this->nomefile $this->percorso_fisico_guest.$this->guesttxt;
            if (isset(
    $_POST["indietro"]) || isset($_POST["avanti"])) {
                
    $this->posizione $_POST["posizione"];
                
    $this->leggi_form();
            } else {
                if (isset(
    $_POST["azione"]) && ($_POST["azione"] == "inserimento")) {
                    
    $this->posizione 0;
                } else {
                    
    $this->leggi_form();
                    
    $this->posizione 0;
                }
            }
        }
        
    //Funzione "data"
        
    function dataora_attuale() {
            
    $mesi = array("gennaio""febbraio""marzo""aprile""maggio""giugno""luglio""agosto""settembre""ottobre""novembre""dicembre");
            
    $mese = (int)date("m") - 1;
            
    $data date("d")." ".$mesi[$mese]." ".date("Y");
            
    $ora strftime ("%H:%M");
            
    $data_finale $data." ore: ".$ora;
            return 
    $data_finale;
        }
        
    // rimuovi i tag HTML
        
    function striptags($stringa) {
            
    $tag_consentiti '[b][i]<u>
    '
    ;
            return 
    strip_tags($stringa$tag_consentiti );
        }
        
        
    // lettura file di testo
        
    function leggi_form() {
            if (!
    file_exists($this->nomefile)) {
                echo 
    '
                    <h2>ERRORE:</h2>
                    Il file '
    .$this->nomefile.' non è presente su disco.

                    Createlo, anche vuoto, e riavviate lo script
                '
    ;
                die;
            }
            
    $dimensione filesize ($this->nomefile);
            if (
    $dimensione == 0) {
                
    $this->numero_righe 0;
                return;
            }
            
    $this->book =  stripslashes(file_get_contents($this->nomefile));
            
    $this->righe split($this->separatore_righe$this->book);
            
    $this->righe array_reverse($this->righe);
            
    $this->numero_righe count($this->righe) - 1;
        }
        
    // mostrare un singolo record
        
    function mostra_record($indice) {
            list (
    $dataora$nome$commento) = split($this->separatore_campi$this->righe[$indice]);
            
    $html_record '<table border="0" width="'.($this->larghezza_tabella-4).'" class="tabellaesterna">';
            
    $html_record .= '
                <tr>
                    <td>
                        <table border="0" width="'
    .($this->larghezza_tabella-20).'" cellspacing="1" cellpadding="4" class="tabellainterna">
                            <tr>
                                <td width="100" align="left" class="intestazione">
                                    inserito il:
                                </td>
                                <td align="left" class="testo">
                                    '
    .$dataora.'
                                </td>
                            </tr>
                            <tr>
                                <td width="100" align="left" class="intestazione">
                                    Nome:
                                </td>
                                <td align="left" class="testo">
                                    '
    .$this->striptags($nome).'
                                </td>
                            </tr>
                            <tr>
                                <td width="100" align="left" class="intestazione" valign="top">
                                    Commento:
                                </td>
                                <td align="left" class="testo" valign="top">
                                    '
    .$this->striptags($commento).'
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            '
    ;
            
    $html_record .= '<tr><td>[url="form.php"]torna alla lista[/url]</td></tr>';
            
    $html_record .= '</table>';
            return 
    $html_record;
        }
        
        
    // metodo per gestire la visualizzazione della lista dei record con paginazione
        
    function mostra_lista() {
            if (
    $this->numero_righe == 0) {
                return 
    "nessuno fin ora ha scritto qualcosa";
            }
            
    $limite $this->record_per_pagina// numero di record mostrati per pagina
            
    if (isset($_POST["indietro"])) { 
                
    $this->posizione--; 
                
    $inizio $this->posizione*$limite;
            } else if (isset(
    $_POST["avanti"])) { 
                    
    $this->posizione++; 
                    
    $inizio $this->posizione*$limite;
                } else {    
                    
    $inizio 0;
                }
            
    $contatore 0;
            
    $indice_riga $inizio;
            
    $html_lista '<table border="0" width="'.($this->larghezza_tabella-4).'" class="tabellaesterna">';
            while ((
    $indice_riga $this->numero_righe) && ($contatore $limite)) {
                list (
    $dataora$nome$email$citta$contatto$commento) = split($this->separatore_campi$this->righe[$indice_riga]);
                if (
    $this->mostra_dettagli) {
                    
    $dettagli '[url="javascript: document.mostradettagli.indice.value=\''.$indice_riga.'\'; document.mostradettagli.submit()"]dettagli[/url]';
                } else {
                    
    $dettagli '';
                }
                
    $html_lista .= '
                    <tr>
                        <td valign="top">
                            <table border="0" width="'
    .($this->larghezza_tabella-26).'" cellspacing="0" cellpadding="4" class="tabellainterna" align="center">
                                <tr>
                                    <td width="100" align="left" class="intestazione">
                                        Nome:
                                    </td>
                                    <td align="left" class="testo">
                                        '
    .$this->striptags($nome).'
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top" width="100" align="left" class="intestazione">
                                        Commento:
                                    </td>
                                    <td valign="top" align="left" class="testo">
                                        '
    .ereg_replace("\n""
    "
    $this->striptags($commento)).'
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        '
    .$dataora.'
                                    </td>
                                </tr>
                            </table>
                        <td>
                    </tr>
                '
    ;
                
    $contatore++;
                
    $indice_riga++;
            }
            
    $html_pulsanti '';
            if (
    $this->numero_righe $limite) {
                if (
    $inizio >=  $limite) {
                    
    $html_pulsanti .= '<input type="submit" value="<<" name="indietro" class="pulsanti">';
                }
                if (
    $indice_riga $this->numero_righe) {
                    
    $html_pulsanti .= '<input type="submit" value=">>" name="avanti" class="pulsanti">';
                }
            }
            
    $html_lista .= '
                        <form method="post" action="form.php" name="pageing">
                <tr>
                    <td>
                            <input type="hidden" value="mostralista" name="azione">
                            <input type="hidden" name="posizione" value="'
    .$this->posizione.'">
                            '
    .$html_pulsanti.'
                    </td>
                </tr>
                        </form>
            '
    ;
            
    $html_lista .= '
                </table>
                        
                '
    ;
            return 
    $html_lista;
        }
        
    // Metodo per l'inserimento di un nuovo record
        
    function aggiungi_record() {
            
    $test_non_vuoto trim($_POST["nome"].$_POST["email"].$_POST["citta"].$_POST["contatto"].$_POST["commento"]);
            if (
    $test_non_vuoto != "") {
                
    $this->linea $this->separatore_righe.$_POST["dataora"].$this->separatore_campi.$_POST["nome"].$this->separatore_campi.$_POST["email"].$this->separatore_campi.$_POST["citta"].$this->separatore_campi.$_POST["contatto"].$this->separatore_campi.$_POST["commento"]."\r\n";
                
    $puntatore fopen($this->nomefile"a");
                
    $this->linea $this->striptags($this->linea);
                
    fputs($puntatore$this->linea);
                
    fclose($puntatore);
            }
            
    $this->leggi_form();
        }
        
    // metodo per la raccolta dati di un nuovo record
        
    function leggi_dati() {
            
    $html_form_immissione '
                <script language="JavaScript">
                    <!--
                        function controlla() {
                            if ((document.inseriscirecord.nome.value == \'\') || (document.inseriscirecord.commento.value == \'\')) {
                                alert(\'inserisci almeno il nome e un commento!\');
                                return false;
                            } else {
                                return true;
                            }
                        }
                    //-->
                </script>
                <form method="post" action="form.php" name="inseriscirecord" onSubmit="return controlla();">
                      <table border="0" width="'
    .($this->larghezza_tabella 2).'" cellspacing="1" cellpadding="4" class="tabellainterna">
                        <tr>
                            <td colspan="2" class="intestazione" width="'
    .($this->larghezza_tabella 2).'">
                                Firma il nostro form!
                            </td>
                        </tr>
                        <tr>
                            <th align="left">
                                nome: 
                            </th>
                            <td>
                                <input type="text" name="nome" size="40" class="areatesto">
                            </td>
                        </tr>
                        <tr>
                            <th align="left" valign="top">
                                commenti: 
                            </th>
                            <td>
                                <textarea name="commento" rows="5" cols="45" class="areatesto"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" class="intestazione">
                                <input type="hidden" value="inserimento" name="azione">
                                <input type="hidden" name="dataora" value="'
    .$this->dataora_attuale().'">
                                <input type="submit" name="postati" value="vai !" class="pulsanti">
                                <input type="reset" name="cancell" value="cancella" class="pulsanti">
                            </td>
                        </tr>    
                    </table>
                </form>
            '
    ;
            return 
    $html_form_immissione;
        }
    }
    $guests = new form();
    if (isset(
    $_POST["azione"]) && ($_POST["azione"] == "inserimento")) {
        
    $guests->aggiungi_record();

    $html "<table><tr><td>";
    if (isset(
    $_POST["azione"]) && ($_POST["azione"] == "dettagli")) {
        
    $html .= $guests->mostra_record($_POST["indice"]);
    } else {
        
    $html .= $guests->mostra_lista();
    }
    $html .= "</td></tr><tr><td>";
    $html .= $guests->leggi_dati();
    $html .= "</td></tr></table>";
    unset(
    $guests);
    ?>
    <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> Form </title>
    </head>
    <body>
    <?=$html?>
    </body>
    </html>
    Come si capisce, in questo caso, il codice lo metti in un file "form.php" e crei un file "guests.txt". L'ho ricavato da un mio guestbook, spero di non aver fatto casini!

  3. #3
    Grazie,
    faccio delle prove e poi ti dico!
    Hutton

    "Una tela bianca, offre infinite possibilità."

  4. #4
    dà un pò di errori

    Notice: Undefined index: email in C:\Program Files\EasyPHP\www\testo\form.php on line 197

    Notice: Undefined index: citta in C:\Program Files\EasyPHP\www\testo\form.php on line 197

    Notice: Undefined index: contatto in C:\Program Files\EasyPHP\www\testo\form.php on line 197

    Notice: Undefined index: email in C:\Program Files\EasyPHP\www\testo\form.php on line 199

    Notice: Undefined index: citta in C:\Program Files\EasyPHP\www\testo\form.php on line 199

    Notice: Undefined index: contatto in C:\Program Files\EasyPHP\www\testo\form.php on line 199

    Deprecated: Function split() is deprecated in C:\Program Files\EasyPHP\www\testo\form.php on line 67

    Deprecated: Function split() is deprecated in C:\Program Files\EasyPHP\www\testo\form.php on line 131

    Notice: Undefined property: form::$mostra_dettagli in C:\Program Files\EasyPHP\www\testo\form.php on line 132

    Deprecated: Function ereg_replace() is deprecated in C:\Program Files\EasyPHP\www\testo\form.php on line 154
    Hutton

    "Una tela bianca, offre infinite possibilità."

  5. #5
    ehmmmm... effettivamente è un po' strano!
    No, a parte tutto, sapevo che qualche errore ci sarebbe scappato! Errore nella modifica! Pardon! Ecco qui lo script corretto!

    Codice PHP:
    <?php
    class guestbook {
        var 
    $separatore_righe "--inizioriga--";
        var 
    $separatore_campi "--finecampo--";
        var 
    $record_per_pagina 3;
        var 
    $percorso_fisico_guest "";
        var 
    $guesttxt "guests.txt";
        var 
    $nomefile;
        var 
    $larghezza_tabella "500";
        var 
    $mostra_dettagli true;
        var 
    $righe = array();
        var 
    $posizione;
        var 
    $numero_righe;
        var 
    $book;
        var 
    $linea;
        function 
    guestbook() {
            
    $this->nomefile $this->percorso_fisico_guest.$this->guesttxt;
            if (isset(
    $_POST["indietro"]) || isset($_POST["avanti"])) {
                
    $this->posizione $_POST["posizione"];
                
    $this->leggi_guestbook();
            } else {
                if (isset(
    $_POST["azione"]) && ($_POST["azione"] == "inserimento")) {
                    
    $this->posizione 0;
                } else {
                    
    $this->leggi_guestbook();
                    
    $this->posizione 0;
                }
            }
        }
        function 
    dataora_attuale() {
            
    $mesi = array("gennaio""febbraio""marzo""aprile""maggio""giugno""luglio""agosto""settembre""ottobre""novembre""dicembre");
            
    $mese = (int)date("m") - 1;
            
    $data date("d")." ".$mesi[$mese]." ".date("Y");
            
    $ora strftime ("%H:%M");
            
    $data_finale $data." ore: ".$ora;
            return 
    $data_finale;
        }
        function 
    striptags($stringa) {
            
    $tag_consentiti '[b][i]<u>
    '
    ;
            return 
    strip_tags($stringa$tag_consentiti );
        }
        function 
    leggi_guestbook() {
            if (!
    file_exists($this->nomefile)) {
                echo 
    '
                    <h2>ERRORE:</h2>
                    Il file '
    .$this->nomefile.' non è presente su disco.

                    Createlo, anche vuoto, e riavviate lo script
                '
    ;
                die;
            }
            
    $dimensione filesize ($this->nomefile);
            if (
    $dimensione == 0) {
                
    $this->numero_righe 0;
                return;
            }
            
    $this->book =  stripslashes(file_get_contents($this->nomefile));
            
    $this->righe split($this->separatore_righe$this->book);
            
    $this->righe array_reverse($this->righe);
            
    $this->numero_righe count($this->righe) - 1;
        }
        function 
    mostra_record($indice) {
            list (
    $dataora$nome$email$citta$contatto$commento) = split($this->separatore_campi$this->righe[$indice]);
            
    $html_record '<table border="0" width="'.($this->larghezza_tabella-4).'" class="tabellaesterna">';
            
    $html_record .= '
                <tr>
                    <td>
                        <table border="0" width="'
    .($this->larghezza_tabella-20).'" cellspacing="1" cellpadding="4" class="tabellainterna">
                            <tr>
                                <td width="100" align="left" class="intestazione">
                                    inserito il:
                                </td>
                                <td align="left" class="testo">
                                    '
    .$dataora.'
                                </td>
                            </tr>
                            <tr>
                                <td width="100" align="left" class="intestazione">
                                    Nome:
                                </td>
                                <td align="left" class="testo">
                                    '
    .$this->striptags($nome).'
                                </td>
                            </tr>
                            <tr>
                                <td width="100" align="left" class="intestazione">
                                    e-mail:
                                </td>
                                <td align="left" class="testo">
                                    '
    .$this->striptags($email).'
                                </td>
                            </tr>
                            <tr>
                                <td width="100" align="left" class="intestazione">
                                    Città:
                                </td>
                                <td align="left" class="testo">
                                    '
    .$this->striptags($citta).'
                                </td>
                            </tr>
                            <tr>
                                <td width="100" align="left" class="intestazione">
                                    riferito da:
                                </td>
                                <td align="left" class="testo">
                                    '
    .$this->striptags($contatto).'
                                </td>
                            </tr>
                            <tr>
                                <td width="100" align="left" class="intestazione" valign="top">
                                    Commento:
                                </td>
                                <td align="left" class="testo" valign="top">
                                    '
    .$this->striptags($commento).'
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            '
    ;
            
    $html_record .= '<tr><td>[url="form.php"]torna alla lista[/url]</td></tr>';
            
    $html_record .= '</table>';
            return 
    $html_record;
        }
        function 
    mostra_lista() {
            if (
    $this->numero_righe == 0) {
                return 
    "nessuno fin ora ha firmato il guestbook";
            }
            
    $limite $this->record_per_pagina;
            if (isset(
    $_POST["indietro"])) { 
                
    $this->posizione--; 
                
    $inizio $this->posizione*$limite;
            } else if (isset(
    $_POST["avanti"])) { 
                    
    $this->posizione++; 
                    
    $inizio $this->posizione*$limite;
                } else {    
                    
    $inizio 0;
                }
            
    $contatore 0;
            
    $indice_riga $inizio;
            
    $html_lista '<table border="0" width="'.($this->larghezza_tabella-4).'" class="tabellaesterna">';
            while ((
    $indice_riga $this->numero_righe) && ($contatore $limite)) {
                list (
    $dataora$nome$email$citta$contatto$commento) = split($this->separatore_campi$this->righe[$indice_riga]);
                if (
    $this->mostra_dettagli) {
                    
    $dettagli '[url="javascript: document.mostradettagli.indice.value=\''.$indice_riga.'\'; document.mostradettagli.submit()"]dettagli[/url]';
                } else {
                    
    $dettagli '';
                }
                
    $html_lista .= '
                    <tr>
                        <td valign="top">
                            <table border="0" width="'
    .($this->larghezza_tabella-26).'" cellspacing="0" cellpadding="4" class="tabellainterna" align="center">
                                <tr>
                                    <td width="100" align="left" class="intestazione">
                                        Nome:
                                    </td>
                                    <td align="left" class="testo">
                                        '
    .$this->striptags($nome).'
                                    </td>
                                </tr>
                                <tr>
                                    <td width="100" align="left" class="intestazione">
                                        Città:
                                    </td>
                                    <td align="left" class="testo">
                                        '
    .$this->striptags($citta).'
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top" width="100" align="left" class="intestazione">
                                        Commento:
                                    </td>
                                    <td valign="top" align="left" class="testo">
                                        '
    .ereg_replace("\n""
    "
    $this->striptags($commento)).'
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" width="100" valign="top" class="intestazione">
                                        '
    .$dettagli.'
                                    </td>
                                    <td align="right">
                                        '
    .$dataora.'
                                    </td>
                                </tr>
                            </table>
                        <td>
                    </tr>
                '
    ;
                
    $contatore++;
                
    $indice_riga++;
            }
            
    $html_pulsanti '';
            if (
    $this->numero_righe $limite) {
                if (
    $inizio >=  $limite) {
                    
    $html_pulsanti .= '<input type="submit" value="<<" name="indietro" class="pulsanti">';
                }
                if (
    $indice_riga $this->numero_righe) {
                    
    $html_pulsanti .= '<input type="submit" value=">>" name="avanti" class="pulsanti">';
                }
            }
            
    $html_lista .= '
                        <form method="post" action="form.php" name="pageing">
                <tr>
                    <td>
                            <input type="hidden" value="mostralista" name="azione">
                            <input type="hidden" name="posizione" value="'
    .$this->posizione.'">
                            '
    .$html_pulsanti.'
                    </td>
                </tr>
                        </form>
            '
    ;
            
    $html_lista .= '
                </table>
                        <form method="post" action="form.php" name="mostradettagli">
                            <input type="hidden" value="dettagli" name="azione">
                            <input type="hidden" name="indice" value="">
                        </form>
                '
    ;
            return 
    $html_lista;
        }
        function 
    aggiungi_record() {
            
    $test_non_vuoto trim($_POST["nome"].$_POST["email"].$_POST["citta"].$_POST["contatto"].$_POST["commento"]);
            if (
    $test_non_vuoto != "") {
                
    $this->linea $this->separatore_righe.$_POST["dataora"].$this->separatore_campi.$_POST["nome"].$this->separatore_campi.$_POST["email"].$this->separatore_campi.$_POST["citta"].$this->separatore_campi.$_POST["contatto"].$this->separatore_campi.$_POST["commento"]."\r\n";
                
    $puntatore fopen($this->nomefile"a");
                
    $this->linea $this->striptags($this->linea);
                
    fputs($puntatore$this->linea);
                
    fclose($puntatore);
            }
            
    $this->leggi_guestbook();
        }
        function 
    leggi_dati() {
            
    $html_form_immissione '
                <script language="JavaScript">
                    <!--
                        function controlla() {
                            if ((document.inseriscirecord.nome.value == \'\') || (document.inseriscirecord.commento.value == \'\')) {
                                alert(\'inserisci almeno il nome e un commento!\');
                                return false;
                            } else {
                                return true;
                            }
                        }
                    //-->
                </script>
                <form method="post" action="form.php" name="inseriscirecord" onSubmit="return controlla();">
                      <table border="0" width="'
    .($this->larghezza_tabella 2).'" cellspacing="1" cellpadding="4" class="tabellainterna">
                        <tr>
                            <td colspan="2" class="intestazione" width="'
    .($this->larghezza_tabella 2).'">
                                Firma il nostro guestbook!
                            </td>
                        </tr>
                        <tr>
                            <th align="left">
                                nome: 
                            </th>
                            <td>
                                <input type="text" name="nome" size="40" class="areatesto">
                            </td>
                        </tr>
                        <tr>
                            <th align="left">
                                e-mail: 
                            </th>
                            <td>
                                <input type="text" name="email" size="40" class="areatesto">
                            </td>
                        </tr>
                        <tr>
                            <th align="left">
                                città: 
                            </th>
                            <td>
                                <input type="text" name="citta" size="40" class="areatesto">
                            </td>
                        </tr>
                        <tr>
                            <th align="left">
                                riferito

                                da: 
                            </th>
                            <td>
                                <input type="text" name="contatto" size="40" class="areatesto">
                            </td>
                        </tr>
                        <tr>
                            <th align="left" valign="top">
                                commenti: 
                            </th>
                            <td>
                                <textarea name="commento" rows="5" cols="45" class="areatesto"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" class="intestazione">
                                <input type="hidden" value="inserimento" name="azione">
                                <input type="hidden" name="dataora" value="'
    .$this->dataora_attuale().'">
                                <input type="submit" name="postati" value="vai !" class="pulsanti">
                                <input type="reset" name="cancell" value="cancella" class="pulsanti">
                            </td>
                        </tr>    
                    </table>
                </form>
            '
    ;
            return 
    $html_form_immissione;
        }
    }
    $guests = new guestbook();
    if (isset(
    $_POST["azione"]) && ($_POST["azione"] == "inserimento")) {
        
    $guests->aggiungi_record();

    $html "<table><tr><td>";
    if (isset(
    $_POST["azione"]) && ($_POST["azione"] == "dettagli")) {
        
    $html .= $guests->mostra_record($_POST["indice"]);
    } else {
        
    $html .= $guests->mostra_lista();
    }
    $html .= "</td></tr><tr><td>";
    $html .= $guests->leggi_dati();
    $html .= "</td></tr></table>";
    unset(
    $guests);
    ?>
    <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> Form </title>
    </head>
    <body>
    <?=$html?>
    </body>
    </html>

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 © 2024 vBulletin Solutions, Inc. All rights reserved.