Visualizzazione dei risultati da 1 a 7 su 7
  1. #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

    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>
    questo invece il codice javascript

    codice HTML:
    <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

    Codice 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 (isset(
    $_POST['privacy'])) {
    echo 
    "<input type = \"checkbox\" name = \"privacy\" checked />";
    }else{
    echo 
    "<input type = \"checkbox\" name = \"privacy\" />";
    }
    //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 <miamail@miamail.com>';    
    //sender
    $from $name ' <' $email '>';    
    //subject and the html message
    $subject 'Contact form - Messaggio da ' 
    $name;          
    $message 
    <!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>
    </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;}
    ?>

  2. #2
    Ciao, ad una rapida lettura, mi sa che non hai settato $privacy e siccome la variabile è vuota per questo motivo non ti visualizza nulla nella mail.

  3. #3
    Quote Originariamente inviata da denver1985 Visualizza il messaggio
    Ciao, ad una rapida lettura, mi sa che non hai settato $privacy e siccome la variabile è vuota per questo motivo non ti visualizza nulla nella mail.
    Ciao, grazie per la risposta, hai qualche idea su come fare?

    riesci a postarmi la parte mancante in modo tale da poterlo far funzionare correttamente?

    ti ringrazio in anticipo

  4. #4
    Ciao, credo che così dovrebbe andare:


    Codice PHP:
    $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";

    Ultima modifica di denver1985; 09-06-2014 a 19:33

  5. #5
    Quote Originariamente inviata da denver1985 Visualizza il messaggio
    Ciao, credo che così dovrebbe andare:


    Codice PHP:
    $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";



    Grazie mille per la dritta, praticamente ho provato ad inserire questa parte nel file process.php
    funziona solo in parte, l'invio va benissimo solo che il valore che arriva nella mail è sempre "non accetto" anche se il checkbox è spuntato

  6. #6
    Ciao, ho provato stampando i valori a video (senza mandare la mail) e mi funziona correttamente: se è checkato mi esce "accetto" se non è checkato "non accetto".
    Controlla bene il codice oppure prova a ricaricare la pagina.

  7. #7
    Quote Originariamente inviata da denver1985 Visualizza il messaggio
    Ciao, ho provato stampando i valori a video (senza mandare la mail) e mi funziona correttamente: se è checkato mi esce "accetto" se non è checkato "non accetto".
    Controlla bene il codice oppure prova a ricaricare la pagina.
    Ho provato ancora ma non va, se spunto o meno invia la mail ma sempre con il valore non accetto.. sto impazzendo

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.