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

    Problema validazione form in ajax e PHP

    Ciao a tutti,
    è da una settimana che mi sbatto per far funzionare una validazione form che ho creato utilizzando ajax...(è la mia prima prova con ajax)...
    ho fatto funzionare tutto...tranne che per l'ultimo controllo...cioè che l'utente abbia dato l'autorizzazione al trattamento dei dati personali...(checkbox)...questa infatti non viene mai presa in considerazione per il controllo...(quando clicco su invia)...mentre se scateno il controllo all'evento onChange della check allora questa funziona...
    non so + dove sbattere la testa...
    posto i codici e spero che qualcuno mi dia na mano...

    index.php(il form)
    Codice PHP:
    <?php



    $data 
    = array('nome'=>'''cognome'=>'''sesso'=>'''telefono'=>'''citta'=>'''data_nascita'=>'''email'=>'''email2'=>'','username'=>'''password'=>'''password2'=>'''autorizzazione'=>'');

    $errors null;

    $class 'error';

    $msg '';

    if(
    $_SERVER['REQUEST_METHOD'] == 'POST') {

        require 
    dirname(__FILE__) . '/' 'user.php';
        
    $datiForm = array();
        

        

        foreach( 
    $_POST as $chiave => $valore){
            
    $datiForm[$chiave] = $valore;
        }
        
    $datiForm['autorizzazione'] = $_POST['autorizzazione'] ;
        
        foreach( 
    $datiForm as $chiave => $valore){
            echo 
    $chiave.": ".$valore;
            echo 
    "
    "
    ;
        }
        
    $u = new User($datiForm);
        
        if(isset(
    $u)){

            if(
    $u->validate()) {
                

                if(
    $u->store()) {

                    
    $class 'success';

                    
    $msg 'Registrazione effettuata';

                }

            }
        }

        
    $errors $u->getErrors();

        if(isset(
    $errors['info'])) {

            
    $msg $errors['info'];

            
    $class 'error';

        }

    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

        <head>

            <title>AJAX: Validazione di un form</title>

            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

            <link href="main.css" rel="stylesheet" type="text/css" />

            <script type="text/javascript" src="validate.js"></script>

        </head>

        <body>


            <fieldset>

                <legend>Registrazione Nuovo Utente</legend>



                <div class="<?php echo $class?>" id="info_msg"><?php echo $msg?></div>

            <form name="frmReg" method="post" action="index.php" onsubmit="if(nosubmit) {return false;}">
            
            <table width="100%" border="1">
                
                
                <tr>
                    <td id="label_form">
                        <label for="nome">Nome:</label>

                    </td>
                    <td id="input_form">
                        <input id="nome" name="nome" type="text" onblur="validate(this.id, this.value)" value="<?php if(isset($u)) { echo $u->get('nome'); }?>" >

                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="nome_msg">

                            <?php if(isset($errors['nome'])) {echo $errors['nome'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
                
                
                <tr>
                    <td id="label_form">
                        <label for="cognome">Cognome:</label>

                    </td>
                    <td id="input_form">
                        <input id="cognome" name="cognome" type="text" onblur="validate(this.id, this.value)" value="<?php if(isset($u)) { echo $u->get('cognome'); }?>" >

                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="cognome_msg">

                            <?php if(isset($errors['cognome'])) {echo $errors['cognome'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
                
                
                <tr>
                    <td id="label_form">
                        <label for="sesso">Sesso:</label>

                    </td>
                    <td id="input_form">
                        <select name="sesso" id="sesso" onblur="validate(this.id, this.value)">
                        <?php
                        
    if(isset($u) && $u->get("sesso") != ""){

                        
    ?><option value="<?php echo $u->get("sesso"); ?>" selected = "selected"><?php echo $u->get("sesso"); ?></option>
                            <?php if($u->get("sesso") != "M"){ ?><option value="M">M</option><?php ?>
                            <?php if($u->get("sesso") != "F"){ ?><option value="F">F</option><?php ?>
                        <?php }else{ ?>
                            <option value=""  selected = "selected"></option>
                            <option value="M">M</option>
                            <option value="F">F</option>
                        <?php ?>
                    </select>                
                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="sesso_msg">

                            <?php if(isset($errors['sesso'])) {echo $errors['sesso'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
                
                
                <tr>
                    <td id="label_form">
                        <label for="telefono">Telefono:</label>

                    </td>
                    <td id="input_form">
                        <input id="telefono" name="telefono" type="text" onblur="validate(this.id, this.value)" value="<?php if(isset($u)) { echo $u->get('telefono'); }?>" />

                
                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="telefono_msg">

                            <?php if(isset($errors['telefono'])) {echo $errors['telefono'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
                

                
                <tr>
                    <td id="label_form">
                        <label for="citta">Citt&agrave;:</label>

                    </td>
                    <td id="input_form">
                        <select name="citta" id="citta" onblur="validate(this.id, this.value)">
                            <?php include('js/carica_citta/select_citta.php'); ?>
                        </select>
                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="citta_msg">

                            <?php if(isset($errors['citta'])) {echo $errors['citta'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
                    
                
                <tr>
                    <td id="label_form">
                        <label for="data_nascita">Data di nascita:</label>

                    </td>
                    <td id="input_form">
                        <input id="data_nascita" name="data_nascita" type="text" onblur="validate(this.id, this.value)" value="<?php if(isset($u)) { echo $u->get('data_nascita'); }?>" />

                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="data_nascita_msg">

                            <?php if(isset($errors['data_nascita'])) {echo $errors['data_nascita'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
                

                
                
                <tr>
                    <td id="label_form">
                        <label for="email">Email:</label>

                    </td>
                    <td id="input_form">
                        <input id="email" name="email" type="text" onblur="validate(this.id, this.value)" value="<?php if(isset($u)) { echo $u->get('email'); }?>" >
                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="email_msg">

                            <?php if(isset($errors['email'])) {echo $errors['email'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
                
                
                <tr>
                    <td id="label_form">
                        <label for="email2">Ripeti email:</label>

                    </td>
                    <td id="input_form">
                        <input id="email2" name="email2" type="text" onblur="validateSecondMail(this.id, this.value)" value="<?php if(isset($u)) { echo $u->get('email2'); }?>" >
                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="email2_msg">

                            <?php if(isset($errors['email2'])) {echo $errors['email2'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
                
                
                <tr>
                    <td id="label_form">
                        <label for="username">Username:</label>

                    </td>
                    <td id="input_form">
                        <input id="username" name="username" type="text" onblur="validate(this.id, this.value)" value="<?php if(isset($u)) { echo $u->get('username'); }?>" >

                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="username_msg">

                            <?php if(isset($errors['username'])) {echo $errors['username'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
                
                
                <tr>
                    <td id="label_form">
                        <label for="password">Password:</label>

                    </td>
                    <td id="input_form">
                        <input id="password" name="password" type="text" onblur="validate(this.id, this.value)" value="<?php if(isset($u)) { echo $u->get('password'); }?>"  align="right">
                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="password_msg">

                            <?php if(isset($errors['password'])) {echo $errors['password'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
                
                
                <tr>
                    <td id="label_form">
                        <label for="password2">Ripeti password:</label>
                    </td>
                    <td id="input_form">

                        <input id="password2" name="password2" type="text" onblur="validateSecondPassword(this.id, this.value)" value="<?php if(isset($u)) { echo $u->get('password2'); }?>" >
                    </td>
                    <td id="img_form">
                        [img]img/ajax-loader.gif[/img][img]img/checked.gif[/img]

                    </td>
                </tr>
                <tr>
                    <td id="label_form"></td>
                    <td id="input_form">
                        <span class="error" id="password2_msg">

                            <?php if(isset($errors['password2'])) {echo $errors['password2'];}?>

                        </span>
                    </td>
                    <td id="img_form"></td>
                </tr>
            </table>
                
                
                <input id="autorizzazione" name="autorizzazione" value ="auth" type="checkbox" onMouseUp="validate(this.id, this.checked)">
                [img]img/ajax-loader.gif[/img]
                [img]img/checked.gif[/img]
            Autorizzo il trattamento dei dati personali ai sensi della L. 196/03
            


                        <span class="error" id="autorizzazione_msg">

                            <?php if(isset($errors['autorizzazione'])) {echo $errors['autorizzazione'];}?>

                        </span>

            <hr>



            <input type="submit" name="submit" value="Invia" class="button" />

            </form>

            </fieldset>



        </body>

    </html>

  2. #2
    posto anche le altre due parti dell'"applicativo"
    validate.js
    Codice PHP:
    var xmlHttp getXmlHttpObject();

    var 
    waiting false;

    function 
    validate(fldIdfldVal) {
        

        if (
    xmlHttp && !waiting) {

            var 
    data "fldid=" fldId "&fldval=" encodeURIComponent(fldVal);
            

            
    xmlHttp.open("POST"'validate.php'true);

            
    xmlHttp.setRequestHeader("Content-Type""application/x-www-form-urlencoded");

            
    xmlHttp.onreadystatechange stateChanged;

            
    xmlHttp.send(data);

            
            
    //APPENA MANDO LA RICHIESTA VISUALIZZO LA GIF DI "ELABORAZIONE"        
            
    if(document.all){
                var 
    gifAttend document.all[fldId+'_attend'];
            }else{
                var 
    gifAttend document.getElementById(fldId+"_attend");
            }
        
            
    gifAttend.style.display "block";
            
    waiting true;

        }

    }
    function 
    validateSecondMail(fldIdfldVal) {


        if (
    xmlHttp && !waiting) {
            if(
    document.all){fldVal2 document.all['email'].value;}else{fldVal2 document.getElementById("email").value;}

            var 
    data "fldid=" fldId "&fldval=" encodeURIComponent(fldVal) + "&fldval2=" encodeURIComponent(fldVal2) + "&fldid2=email";
            
    xmlHttp.open("POST"'validate.php'true);

            
    xmlHttp.setRequestHeader("Content-Type""application/x-www-form-urlencoded");

            
    xmlHttp.onreadystatechange stateChanged;

            
    xmlHttp.send(data);

            
    waiting true;

        }

    }
    function 
    validateSecondPassword(fldIdfldVal) {


        if (
    xmlHttp && !waiting) {
            if(
    document.all){fldVal2 document.all['password'].value;}else{fldVal2 document.getElementById("password").value;}

            var 
    data "fldid=" fldId "&fldval=" encodeURIComponent(fldVal) + "&fldval2=" encodeURIComponent(fldVal2) + "&fldid2=password";

            
    xmlHttp.open("POST"'validate.php'true);

            
    xmlHttp.setRequestHeader("Content-Type""application/x-www-form-urlencoded");

            
    xmlHttp.onreadystatechange stateChanged;

            
    xmlHttp.send(data);

            
    //APPENA MANDO LA RICHIESTA VISUALIZZO LA GIF DI "ELABORAZIONE"
            
    if(document.all){
                var 
    gifAttend document.all[fldId+'_attend'];
            }else{
                var 
    gifAttend document.getElementById(fldId+"_attend");
            }
                
            
    gifAttend.style.display "block";

            
    waiting true;

        }

    }

    function 
    stateChanged() {

        if(
    xmlHttp.readyState == 4) {

            
    //Stato OK

            
    if (xmlHttp.status == 200) {
                

                var 
    resp xmlHttp.responseText;

                

                var 
    resp.indexOf(';',0);

                if(
    0) {

                    var 
    fld resp.substr(0,p);//Prende la sottostringa che va da 0 all'a prima occorrenza di ";"

                    //A RICHIESTA ESAURITA NASCONDO LA GIF DI "ELABORAZIONE"
                    
    if(document.all){
                        var 
    gifAttend document.all[fld+'_attend'];
                    }else{
                        var 
    gifAttend document.getElementById(fld+"_attend");
                    }
                
                    
    gifAttend.style.display "none";

                    var 
    msg resp.substr(p+1);

                    var 
    cont document.getElementById(fld '_msg');//E la accoda al contenuto della variabile "field"s

                    
    if(msg) {
                        
    //NASCONDO L'EVENTUALE IMMAGINE DI OK
                        
    if(document.all){
                            var 
    imgOk document.all['ok_'+fld];
                        }else{
                            var 
    imgOk document.getElementById("ok_"+fld);
                        }
                        
    imgOk.style.display "none";




                        
    cont.className'error';

                    } else {
                        
    //MOSTRO L'IMMAGINE DI OK
                        
    if(document.all){
                            var 
    imgOk document.all['ok_'+fld];
                        }else{
                            var 
    imgOk document.getElementById("ok_"+fld);
                        }
                        
    imgOk.style.display "block";


                        
    msg '';

                    }

                    
    cont.innerHTML msg;

                }

                

            }

            
    waiting false;

        }

    }

    function 
    getXmlHttpObject()

    {

      var 
    xmlHttp=null;

      try

        {

        
    // Firefox, Opera 8.0+, Safari

        
    xmlHttp=new XMLHttpRequest();

        }

      catch (
    e)

        {

        
    // Internet Explorer

        
    try

          {

          
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

          }

        catch (
    e)

          {

          
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

          }

        }

      return 
    xmlHttp;



  3. #3
    users.php(la classe utente)

    Codice PHP:
    <?php

    require dirname(__FILE__) . '/' 'dbconfig.php';

    class 
    User {

        var 
    $errors null;
        var 
    $info null;

        var 
    $fields null;

        var 
    $conn;

        
        
    //COSTRUTTORE

        
    function user($data) {
            if(isset(
    $data['nome'])) {
                
    $this->fields['nome'] = trim($data['nome']);

            }

            if(isset(
    $data['cognome'])) {

                
    $this->fields['cognome'] = trim($data['cognome']);

            }
            if(isset(
    $data['telefono'])) {

                
    $this->fields['telefono'] = trim($data['telefono']);

            }

            if(isset(
    $data['citta'])) {

                
    $this->fields['citta'] = trim($data['citta']);

            }
            if(isset(
    $data['data_nascita'])) {

                
    $this->fields['data_nascita'] = trim($data['data_nascita']);

            }

            if(isset(
    $data['email'])) {

                
    $this->fields['email'] = trim($data['email']);

            }
            if(isset(
    $data['email2'])) {

                
    $this->fields['email2'] = trim($data['email2']);

            }

            if(isset(
    $data['username'])) {

                
    $this->fields['username'] = trim($data['username']);

            }
            if(isset(
    $data['password'])) {

                
    $this->fields['password'] = trim($data['password']);

            }

            if(isset(
    $data['password2'])) {

                
    $this->fields['password2'] = trim($data['password2']);

            }

            if(isset(
    $data['autorizzazione'])) {

                
    $this->fields['autorizzazione'] = trim($data['autorizzazione']);

            }

            if(isset(
    $data['sesso'])) {

                
    $this->fields['sesso'] = trim($data['sesso']);

            }

        }

        
        
    //VALIDA UTENTE (METODO  MAIN)

        
    function validate() {
            
    $i=1;
            
    $ret = array();

            foreach(
    $this->fields as $k => $v) {
                
    $returnForm false;

                switch(
    $k) {
                    
                    case 
    'nome':
                    

                        if(
    $v == '') {
                            

                            
    $this->setError('Inserire nome'$k);

                            
    $ret['nome'] = false;

                        } elseif(!
    $this->only_character($k$v)) {
                            
    $this->setError('Nome non valido'$k);

                            
    $ret['nome'] = false;

                        }elseif(!
    $this->check_lenght($k$v"20")) {
                            
    $this->setError('Nome troppo lungo per essere archiviato'$k);

                            
    $ret['nome'] = false;

                        }else{
                            
    $ret['nome']= true;
                            }

                        break;
                        
                    case 
    'cognome':

                        if(
    $v == '') {

                            
    $this->setError('Inserire cognome'$k);

                            
    $ret['cognome'] = false;

                        } elseif(!
    $this->only_character($k$v)) {
                            
    $this->setError('Cognome non valido'$k);

                            
    $ret['cognome'] = false;

                        }elseif(!
    $this->check_lenght($k$v"30")) {
                            
    $this->setError('Cognome troppo lungo per essere archiviato'$k);

                            
    $ret['cognome'] = false;

                        }else{
                            
    $ret['cognome'] = true;
                            }

                        break;
                        
                    case 
    'sesso':

                        if(
    $v == '') {

                            
    $this->setError('Inserire il sesso'$k);

                            
    $ret['sesso'] = false;

                        }else{
                            
    $ret['sesso'] = true;
                            }

                        break;
                        
                    case 
    'telefono':

                        if(
    $v == '') {

                            
    $this->setError('Inserire numero di telefono'$k);

                            
    $ret['telefono'] = false;

                        } elseif(!
    $this->only_number($k$v)) {
                            
    $this->setError('Telefono non valido(solo numeri)'$k);

                            
    $ret['telefono'] = false;

                        }elseif(!
    $this->check_lenght_tel($k$v"10")) {
                            
    //$this->setError('Lunghezza numero di telefono errata(10 caratteri)', $k);

                            
    $ret['telefono'] = false;

                        }else{
                            
    $ret['telefono'] = true;
                            }

                        break;
                        
                        case 
    'citta':

                        if(
    $v == '') {

                            
    $this->setError('Inserire una citt&agrave;'$k);

                            
    $ret['citta']= false;

                        }elseif(
    $v == 'Seleziona una Citt&agrave;') {
                            
    $this->setError('Inserire una citt&agrave;'$k);
                            
    $ret['citta'] = false;
                        }else{
                            
    $ret['citta'] = true;
                            }

                        break;
                        
                        case 
    'data_nascita':

                        if(
    $v == '') {

                            
    $this->setError('Inserire data di nascita'$k);

                            
    $ret['data_nascita']= false;

                        } elseif(!
    $this->check_date_of_birth($k$v)) {
                    
    //        $this->setError('La data di nascita inserita non è corretta(formato: gg/mm/aaaa)', $k);

                            
    $ret['data_nascita'] = false;

                        }else{
                            
    $ret['data_nascita'] = true;
                            }

                        break;
                        
                        case 
    'email':

                        if(
    $v == '') {

                            
    $this->setError('Inserire indirizzo email'$k);

                            
    $ret['email'] = false;

                        }elseif(!
    eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$'$v)) {

                            
    $this->setError('Indirizzo email non valido'$k);

                            
    $ret['email'] = false;

                        } elseif(!
    $this->uniqueField('Indirizzo email'$k$v)) {
                            
    $this->setError('Indirizzo email già presente in archivio'$k);

                            
    $ret['email'] = false;

                        }else{
                            
    $ret['email'] = true;
                            }

                        break;
                        
                        case 
    'email2':
                        if(
    $v == '') {

                            
    $this->setError('Inserire indirizzo email'$k);

                            
    $ret['email2'] = false;

                        }elseif(!
    eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$'$v)) {

                            
    $this->setError('Indirizzo email non valido'$k);

                            
    $ret['email2'] = false;

                        } elseif(!
    $this->uniqueField('Indirizzo email'"email"$v)) {
                            
    $this->setError('Indirizzo email già presente in archivio'$k);
                            
    $ret['email2']= false;
                        }elseif(!
    $this->equals($k$v$this->fields['email'])) {
                            
    $this->setError('L&acute;indirizzo email inserito non coincide con il precedente'$k);
                            
    $ret['email2']= false;
                        }else{
                            
    $ret['email2'] = true;
                            }
                        break;
                        case 
    'username':
                        if(
    $v == '') {

                            
    $this->setError('Inserire nome utente'.$v$k);

                            
    $ret['username']= false;

                        } elseif(!
    $this->uniqueField('Nome utente'$k$v)) {
                            
    $this->setError('L&acute;username scelta è già presente in archivio. Scegliere un&acute;altra user'$k);

                            
    $ret['username'] = false;

                        }else{
                            
    $ret['username']= true;
                            }
                        break;
                        case 
    'password':

                        if(
    $v == '') {
                            
    $this->setError('Inserire password'.$v$k);
                            
    $ret['password'] = false;
                        } elseif(!
    $this->check_password($k$v)) {
                            
    $ret['password'] = false;
                        }else{
                            
    $ret['password'] = true;
                            }
                        break;
                        case 
    'password2':
                        if(
    $v == '') {

                            
    $this->setError('Ripetere password'.$v$k);

                            
    $ret['password2']= false;

                        } elseif(!
    $this->check_password($k$v)) {

                            
    $ret['password2'] = false;

                        }elseif(!
    $this->equals($k$v$this->fields['password'])) {
                            
    $this->setError("Le due password inserite non coincidono"$k);

                            
    $ret['password2']= false;

                        }else{
                            
    $ret['password2'] = true;
                            }

                        break;
                        case 
    'autorizzazione':

                        if(
    $v != 'false' ) {

                            
    $this->setError('Autorizzazione al trattamento dei dati necessaria per la registrazione'$k);

                            
    $ret['autorizzazione']= false;

                        }elseif(
    $v == '' ) {
                            
    $this->setError('Autorizzazione al trattamento dei dati necessaria per la registrazione'$k);
                            
    $ret['autorizzazione']= false;
                        }else{
                            
    $ret['autorizzazione'] = true;
                            }

                        break;
                        

                }
                
    $i++;

            }
            
    //CONTROLLO CHE TUTTI I RITORNI DEI CONTROLLI SIANO TRUE
            
    if($ret['nome'] == true && $ret['cognome'] == true && $ret['sesso'] == true && $ret['telefono'] == true && $ret['citta'] == true && $ret['data_nascita'] == true &&
            
    $ret['username'] == true && $ret['password'] == true && $ret['password2'] == true && $ret['email'] == true && $ret['email2'] == true && $ret['autorizzazione'] == true){
                
    $returnForm true;
                }

            return 
    $returnForm;

        }


    //CONTROLLO CHE NELLA STRINGA PASSWORD SIANO PRESENTI SOLO DETERMINATI CARATTERI E CHE SIA LUNGA MINIMO 6 MAX 12 CARATTERI
        
    function check_password($fld_name$fld_val) {
            
            
    $reg_exp '/^[a-zA-Z0-9\_\*\-\+\!\?\,\:\;\.\xE0\xE8\xE9\xF9\xF2\xEC\x27]{6,10}/';


            if(!
    preg_match($reg_exp$fld_val)){
                    
    $this->setError("Password non conforme(min 6, max 10 caratteri)"$fld_name);
                    return 
    false;
                }

            return 
    true;

        }
        
    //CONTROLLO CHE NELLA STRINGA SIANO PRESENTI SOLO CARATTERI ALFABETICI
        
    function only_character($fld_name$fld_val) {
            
            
    $reg_exp '/^([a-zA-Z])+$/';


            if(!
    preg_match($reg_exp$fld_val)){
                    
    $this->setError("Non sono ammessi caratteri diversi da lettere nel campo '$fld_name'"$fld_name);
                    return 
    false;
                }

            return 
    true;

        }
        
        
    //CONTROLLO CHE NELLA STRINGA SIANO PRESENTI SOLO CARATTERI NUMERICI
        
    function only_number($fld_name$fld_val) {
            
            
    $reg_exp '/^([0-9])+$/';


            if(!
    preg_match($reg_exp$fld_val)){                
                
    $this->setError("Non sono ammessi caratteri diversi da numeri nel campo '$fld_name'"$fld_name);            
                return 
    false;
            }

            return 
    true;

        }
        
        
    //CONTROLLO CHE L'USERNAME INSERITA NON SIA GIÀ PRESENTE IN ARCHIVIO

        
    function uniqueField($fld$fld_name$fld_val) {

            if(!
    $this->_connect()) {

                return 
    false;

            }

                    

            
    $sql "SELECT count(*) FROM utenti " .

            
    "WHERE $fld_name = '" mysql_real_escape_string($fld_val$this->conn) . "'";

            

            
    $r mysql_query($sql$this->conn);

            if(!
    $r) {

                
    $this->setError(mysql_error());

                return 
    false;

            }

            if(
    mysql_result($r0) > 0) {

                
    $this->setError("$fld gi&agrave; esistente"$fld_name);

                return 
    false;

            }

            return 
    true;

        }
        
        
    //CONTROLLO CHE DUE STRINGHE SIANO UGUALI
        
    function equals($fld_name$fld_val$fld_val2) {

            if(
    $fld_val != $fld_val2){
                    
                    return 
    false;
                }

            return 
    true;

        }    

        
    //CONTROLLO CHE LA STRINGA NON SIA PIÙ LUNGA DEL VALORE PASSATO COME SECONDO PARAMETRO
        
    function check_lenght_tel($fld_name$fld_val$lenght) {
            if(
    strlen($fld_val) != $lenght){
                    
    $this->setError("Numero di telefono di lunghezza non prevista"$fld_name);
                    return 
    false;
                }
            return 
    true;
        }

        
    //CONTROLLO CHE LA STRINGA NON SIA PIÙ LUNGA DEL VALORE PASSATO COME SECONDO PARAMETRO
        
    function check_lenght($fld_name$fld_val$lenght) {
            if(
    strlen($fld_val) > $lenght){
                    
    $this->setError("La stringa inserita supera la lunghezza massima prevista"$fld_name);
                    return 
    false;
                }
            return 
    true;
        }
        
        
    //RECUPERO FIELD

        
    function get($fld) {

            if(isset(
    $this->fields[$fld])) {

                return 
    $this->fields[$fld];

            }

        }
        
        
    //SETTO GLI ERRORI

        
    function setError($errmsg$dest'info') {

            
    $this->errors[$dest] = $errmsg;

        }
        
        
    //SETTO GLI INFO

        
    function setInfo($infoMsg$dest'info') {

            
    $this->info[$dest] = $infoMsg;

        }
        
        
    //RECUPERO ERRORI

        
    function getErrors() {

            return 
    $this->errors;

        }
        
            
    //RECUPERO INFO

        
    function getInfo() {

            return 
    $this->info;

        }
        
        
        
    //METODO CHE GESTISCE LA CONNESSIONE

        
    function _connect() {

            if(!
    $conn = @mysql_connect(DB_HOSTDB_USERDB_PASSWORD)) {

                
    $this->setError(mysql_error());

                return 
    false;

            }

            if(!
    mysql_select_db(DB_NAME)) {

                
    $this->setError(mysql_error());

                return 
    false;

            }
            
    $this->conn $conn;
            return 
    true;
        }
    }
    ?>

  4. #4
    Secondo te era necessario postare centinaia di righe di codice? Chiunque vede la barra di scorrimento così lunga non perde tempo a leggere tutto, e passa avanti.
    Cmq i controlli li effettui campo per campo, quando perdono il focus (onblur). Non c'è una funzione che richiami all'invio del form, che ti controlla tutti i valori dei campi.
    Quindi non so cosa intendi dire che viene ignorato quando premi Invia.. dove dovrebbe fare il contrario?
    E poi Ajax per controllare se un utente ha spuntato una checkbox? Scusa ma sono un pò disorientato.. se ci spieghi meglio possiamo aiutarti..

    Ciao!
    Prima di dire che sei un Webmaster, guarda in giro per la rete....

  5. #5
    Beh...ho postato tutto il codice perchè così ci sono tutti i "dati" disponibili a chi sia di buona volontà(moolta ) e voglia aiutarmi...

    Per quanto riguarda la validazione il controllo lo faccio alla pressione del tasto invio in quanto viene richiamata la stessa pagina(index.php) in testa alla quale creo l'oggetto utente e dopo:
    - se il metodo validate() restituisce true allora chiamo sullo stesso oggetto la funzione store()
    - altrimenti popolo l'array "errors" tramite il metodo getErrors() e visualizzo i vari messaggi sotto le input corrispondenti...

    Questo quindi va aldilà dei vari controlli all'evento onBlur...
    in ogni caso è previsto quel controllo li...


    il problema è che per la checkbox se il metodo validate() lo chiamo tramite ajax(all'evento onMouseUp)...chiamando lo script php "validate.php" che non fa altro che creare l'oggetto users con i dati che gli arrivano via post e chiamarci sopra la validazione...allora il messaggio di errore sulla check lo vedo...nel caso dell'invia invece no...come se non arrivasse a users il valore dell'array ("autorizzazione")

    lo so è una spiegazione ingarbugliata...se non si capisce sono pronto a precisare altro...ma vorrei risolvere sto problemino...

    Consigli su come controllare che si abbia checkkato l'autorizzazione o sul form che sto creando in generale, sono ben accetti!!



    Ciao

  6. #6
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Prova a postare il link alla pagina pubblica forse vedendola in funzione si ha l'intuizione giusta (anche se lo ritengo molto difficile)
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  7. #7
    Purtroppo l'esempio non è online...e adesso non riesco neanche a postare l'ultima parte di codice...

    stasera posterò l'ultima parte dopodichè sarà possibile anche copiare il codice e creare quindi i file con i nomi indicati per farlo girare anche in locale chiamando la index.php(unico problema sarebbe l'accesso al db...ma quella parte si può anche togliere...

    grazie cmq per l'interessamento

  8. #8
    In index.php, all'inizio, modifica cos&igrave;:
    Codice PHP:
    if($_SERVER['REQUEST_METHOD'] == 'POST') {

        require 
    dirname(__FILE__) . '/' 'user.php';
        
    $datiForm = array();
        

        
    /* nel caso in cui la form venga inviata SENZA aver toccato la checkbox,
           la chiave 'autorizzazione' non compare nell'array $_POST, quindi mi premunisco
           e, se detta chiave non c'e', aggiungo a $datiForm la chiave 'autorizzazione'
           con valore vuoto, che spero, come credo di aver capito, venga testata oltre ...
        */
        
    if (!isset($_POST['autorizzazione']))
            
    $datiForm['autorizzazione'] = '' ;

        foreach( 
    $_POST as $chiave => $valore){
            
    $datiForm[$chiave] = $valore;
        }
        
    /* la prossima riga va commentata, altrimenti nel caso detto va in errore! */
        /* $datiForm['autorizzazione'] = $_POST['autorizzazione'] ; */
        
        
    foreach( $datiForm as $chiave => $valore){
            echo 
    $chiave.": ".$valore;
            echo 
    "
    "
    ;
        }
        
    ..... 
    eccetera 
    HTH
    Zappa
    [PC:Presario 2515EU][Cpu:P4@2.3GHz][Ram: 512M][HDU:80G@5400 RPM]
    [Wireless:LinkSys][OS: Ubuntu 9.04 - Jaunty Jackalope]

  9. #9
    Grazie mille era proprio lo "spunto" che cercavo...! Dovrei fare quindi un controllo preliminare sulla check...e solo eventualmente validare gli altri campi...adesso ci provo...spero nn saltino fuori altri casini...

    Grazie a tutti cmq per l'interessamento!!!

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.