Salta al contenuto
  • CATEGORIES
  • La Community Connect.gt
  • Presentati alla Community
  • News Ufficiali da Connect.gt
  • Internet News
  • A Scuola Di
  • Digital Marketing
  • Intelligenza Artificiale
  • SEO & GEO
  • Web Marketing e Content
  • Google Analytics e Web Analytics
  • Google Ads & Advertising
  • YouTube
  • TikTok, Instagram e altri Social
  • Google Adsense, Affiliazioni e Guadagno
  • E-Commerce
  • Coding e Sistemistica
  • Help Center: consigli per il tuo progetto
  • Hosting e Cloud
  • Coding
  • CMS & Piattaforme Self-Hosted
  • Annunci e Collaborazioni
  • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
  • Collaborazioni WEB e Lavoro: offro e cerco
  • Impresa, Fisco e Leggi
  • Consulenza Legale e Professioni Web
  • Consulenza Fiscale, Imprese, Startup e P.Iva
  • Gli Off Topic
  • PC, Smartphone e altri Hardware
  • Tutti i Software
  • GT Fetish Cafè
  • Discussioni
  • 0 Non letti 0
  • Recenti
  • Hashtag
  • Popolare
  • Utenti
  • Privacy
  • Termini e condizioni
  • © 2026 Search On Media Group S.r.l.
Collassa
Connect.gt
Il network Search On
Connect.gt WMF AI Festival Accademia Advanced SEO Tool AgentCy Social Media Strategies Search Tech
Registrati Accedi
Connect.gt
Stream Interest Categorie Hashtag
  1. La community italiana di SEO, marketing digitale e AI
  2. Categorie
  3. Coding e Sistemistica
  4. Coding
  5. Problema Checkbox Privacy Contact form - Aiuto!!

Problema Checkbox Privacy Contact form - Aiuto!!

Pianificato Fissato Bloccato Spostato Coding
3 Post 2 Autori 981 Visualizzazioni 1 Seguito
  • Da Vecchi a Nuovi
  • Da Nuovi a Vecchi
  • Più Voti
Rispondi
  • Risposta alla discussione
Effettua l'accesso per rispondere
Questa discussione è stata eliminata. Solo gli utenti con diritti di gestione possono vederla.
  • G
    G
    giuspin87
    scritto su ultima modifica di
    User Newbie 0
    #1
    Problema Checkbox Privacy Contact form - Aiuto!!

    Salve a tutti, vi espongo il mio problema e sono certo che riuscirete a darmi una mano,
    allora, ho il seguente contact form, tutto funziona benissimo solo che ho voluto implementare il checkbox per la privacy.
    adesso il problema è che il checkbox non mi manda i dati nella mail, praticamente quando mi arriva la mail tutti i dati arrivano correttamente, nome, email, testo ecc.. ma vorrei che il checkbox mi mandasse il valore "accetto" se spuntato, in caso contrario "non accetto".
    ho provato ad implementare nel file php vari codici per il checkbox ma purtroppo non sono riuscito a far funzionare niente, praticamente sto impazzendo da giorni, aiutatemi per favore, consigliatemi il codice da aggiungere per poter ricevere i valori del checkbox.
    vi ringrazio in anticipo

    qui il codice html

    <form id="contact-form" method="post" action="process.php">                            
    <div class="form-div-1 element">                                
    <label>                                
    <input type="text" placeholder="Nome: *(obbligatorio)" name="name" class="text" /></label>                            
    </div>                            
    <div class="form-div-2 element">                                
    <label>                                
    <input type="text" placeholder="Email: *(obbligatorio)" name="email" class="text" /></label>                            
    </div>                            
    <div class="form-div-3 element">                                
    <label>                                
    input type="text" placeholder="Telefono:" name="website" class="text" /></label>                            
    </div>                                                        
    <div class="element1">                                
    <label class="message">                                
    <textarea name="comment" placeholder="Messaggio: *(obbligatorio)" class="text textarea" /></textarea>
    </label>                            
    </div>                            
    <div class="form-div-1 element">                            
    <label>                            
    <input type="checkbox" id="privacy" name="privacy" value="si" />                             
    </label>
    <p>Accetto <a href="#" title="leggi la nostra informativa" class="informativa_link">l'informativa sulla privacy</a><br /></p>                            
    </div>                                                        
    <div class="element">                                                                
    <input type="submit" value="CONTATTACI" id="submit"/>                                                            
    </div>                            
    </form>
    

    il codice javascript

    <script type="text/javascript">$(document).ready(function() {  
         
    //if submit button is clicked    
    $('#submit').click(function () { 
    
    //Get the data from all the fields        
    var name = $('input[name=name]');        
    var email = $('input[name=email]');        
    var website = $('input[name=website]');        
    var comment = $('textarea[name=comment]');        
    var privacy = $('input[name=privacy]');
    
    //Simple validation to make sure user entered something        
    //If error found, add hightlight class to the text field        
    if (name.val()=='') {            
    name.addClass('hightlight');            
    return false;        
    } else name.removeClass('hightlight');                
    
    if (email.val()=='') {            
    email.addClass('hightlight');            
    return false;        
    } else email.removeClass('hightlight');                
    
    if (comment.val()=='') {            
    comment.addClass('hightlight');            
    return false;        
    } else comment.removeClass('hightlight');                
    
    //organize the data properly        
    var data = 'name=' + name.val() + '&email=' + email.val() + '&website=' +         website.val() + '&comment='  + encodeURIComponent(comment.val());                
    
    //disabled all the text fields        
    $('.text').attr('disabled','true');                
    
    //show the loading sign        
    $('.loading').show();                
    
    //start the ajax        
    $.ajax({            
    //this is the php file that processes the data and send mail            
    url: "process.php",                            
    //GET method is used            
    type: "GET",
    //pass the data                        
    data: data,                                
    //Do not cache the page            
    cache: false,                        
    //success            
    success: function (html) {                                
    //if process.php returned 1/true (send mail success)                
    if (html==1) {                                        
    //hide the form                    
    $('.form').fadeOut('slow');                                                            
    //show the success message                    
    $('.done').fadeIn('slow');          
                              
    //if process.php returned 0/false (send mail failed)                
    } else alert('Sorry, unexpected error. Please try again later.');                            
    }                
    });                
    
    //cancel the submit button default behaviours        
    return false;    
    });    
    });    
    </script>
    

    Adesso di seguito invece il file process.php

    <?php
    //Retrieve form data. 
    //GET - user submitted data using AJAX//POST - in case user does not support javascript, we'll use POST instead
    $name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
    $email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
    $website = ($_GET['website']) ?$_GET['website'] : $_POST['website'];
    $comment = ($_GET['comment']) ?$_GET['comment'] : $_POST['comment'];
    if (!empty($_POST['privacy'])) {
    $privacy="accetto";
    }
    else{
    $privacy="non accetto";
    }  
    //flag to indicate which method it uses. If POST set it to 1
    if ($_POST) $post=1;
    //Simple server side validation for POST data, of course, you should validate the email
    if (!$name) $errors[count($errors)] = '(obbligatorio) Inserisci il tuo Nome.';
    if (!$email) $errors[count($errors)] = '(obbligatorio) Inserisci la tua Email.'; 
    if (!$comment) $errors[count($errors)] = '(obbligatorio) Scrivi un Messaggio.'; 
    //if the errors array is empty, send the mailif (!$errors) {
    //recipient
    $to = 'Your Name <[email protected]>';    
    //sender
    $from = $name . ' <' . $email . '>';    
    //subject and the html message
    $subject = 'Contact form - Messaggio da ' . 
    $name;          
    $message = ' 
    
    <head>
    </head>
    <body>
    <table>
    <tr><td>Name</td><td>' . $name . '</td></tr>
    <tr><td>Email</td><td>' . $email . '</td></tr>
    <tr><td>Website</td><td>' . $website . '</td></tr>
    <tr><td>Privacy</td><td>' .$privacy. '</td></tr>
    <tr><td>Comment</td><td>' . nl2br($comment) . '</td></tr>        
    </table>
    </body>
    </html>';
    //send the mail
    $result = sendmail($to, $subject, $message, $from);    
    
    //if POST was used, display the message straight away
    if ($_POST) {
    if ($result) echo 'Messaggio Inviato! Risponderemo al più presto. Grazie.';else echo 'Spiecenti, Si è verificato un errore. Riprova più tardi.';       
    //else if GET was used, return the boolean value so that 
    //ajax script can react accordingly
    //1 means success, 0 means failed} 
    else 
    {echo $result;    
    }
    
    //if the errors array has values} 
    else {
    //display the errors message
    for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
    echo '<a href="form.php">Back</a>';
    exit;}
    
    //Simple mail function with HTML headerfunction sendmail ($to, $subject, $message, $from {
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= 'From: ' . $from . "\r\n";    
    
    $result = mail($to,$subject,$message,$headers);    
    
    if ($result) return 1;
    else return 0;}
    ?>
    
    1 Risposta Ultima Risposta
    Miglior risposta 0
    0
    • G
      G
      giuspin87
      scritto su ultima modifica di
      User Newbie 0
      #2

      Nessuno che mi può aiutare? 😞

      1 Risposta Ultima Risposta
      Miglior risposta 0
      0
      • O
        O
        oslino
        scritto su ultima modifica di
        User Attivo 0
        #3

        A parte che vedo errori nel php di parentesi graffe non aperte o non chiuse, puoi provare così:

        if (isset($_POST['privacy'])) {
               $privacy = "accetto";
           } else { 
               $privacy = "non accetto";
         }
        

        Ciao.

        1 Risposta Ultima Risposta
        Miglior risposta 0
        0

        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
        Rispondi
        • Risposta alla discussione
        Effettua l'accesso per rispondere
        • Da Vecchi a Nuovi
        • Da Nuovi a Vecchi
        • Più Voti


        • Accedi

        • Non hai un account? Registrati

        • Accedi o registrati per effettuare la ricerca.
        • Primo post
          Ultimo post
        Home Accedi Registrati
        Menu
        • CATEGORIES
        • La Community Connect.gt
        • Presentati alla Community
        • News Ufficiali da Connect.gt
        • Internet News
        • A Scuola Di
        • Digital Marketing
        • Intelligenza Artificiale
        • SEO & GEO
        • Web Marketing e Content
        • Google Analytics e Web Analytics
        • Google Ads & Advertising
        • YouTube
        • TikTok, Instagram e altri Social
        • Google Adsense, Affiliazioni e Guadagno
        • E-Commerce
        • Coding e Sistemistica
        • Help Center: consigli per il tuo progetto
        • Hosting e Cloud
        • Coding
        • CMS & Piattaforme Self-Hosted
        • Annunci e Collaborazioni
        • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
        • Collaborazioni WEB e Lavoro: offro e cerco
        • Impresa, Fisco e Leggi
        • Consulenza Legale e Professioni Web
        • Consulenza Fiscale, Imprese, Startup e P.Iva
        • Gli Off Topic
        • PC, Smartphone e altri Hardware
        • Tutti i Software
        • GT Fetish Cafè
        • Discussioni
        • Non letti 0
        • Recenti
        • Hashtag
        • Popolare
        • Utenti
        • Privacy
        • Termini e condizioni
        • © 2026 Search On Media Group S.r.l.