Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it L'avatar di tigerjack
    Registrato dal
    Aug 2003
    Messaggi
    1,661

    [php] campi chekbox se non selezionati valore 0

    ciao,

    con questo codice prelevo i valori di una seri chekbox
    if(isset($_POST['check'])){
    foreach($_POST['check'] as $key => $value) {
    $affare_auto_optional[$key] = $value;
    }
    // creo $affare_auto_optional per inserirolo nel database...
    foreach($affare_auto_optional as $key => $value) {
    //echo "$key,$value;";
    $var_optional .= "$value;";
    }
    }

    questi sono i checkbox:
    codice:
     <table cellspacing="0" cellpadding="1" border="0">
                <tbody>
                  <tr>
                    <td><input name="check[0]" type="checkbox" value="1" />Climatizzatore</td>
                  </tr>
                  <tr>
                    <td><input name="check[1]" type="checkbox" value="2" />Controllo automatico clima</td>
                  </tr>
                  <tr>
                    <td><input name="check[2]" type="checkbox" value="3" />Interni in pelle</td>
                  </tr>
                  <tr>
                    <td><input name="check[3]" type="checkbox" value="4" />Alzacristalli elettrici</td>
                  </tr>
                  <tr>
                    <td><input name="check[4]" type="checkbox" value="5" />Sistema di navigazione</td>
                  </tr>
                  <tr>
                    <td><input name="check[5]" type="checkbox" value="6" />Regolazione elettrica sedili</td>
                  </tr>
                  <tr>
                    <td><input name="check[6]" type="checkbox" value="7" />Tettuccio apribile</td>
                  </tr>
                  <tr>
                    <td><input name="check[7]" type="checkbox" value="8" />Sedili riscaldati</td>
                  </tr>
                  <tr>
                    <td><input name="check[8]" type="checkbox" value="9" />Lettore CD</td>
                  </tr>
                  <tr>
                    <td><input name="check[9]" type="checkbox" value="10" />Autoradio</td>
                  </tr>
                  <tr>
                    <td><input name="check[10]" type="checkbox" value="11" />Adatta a portatori di handicap</td>
                  </tr>
                </tbody>
              </table>
    <table cellspacing="0" cellpadding="1" border="0">
                <tbody>
                  <tr>
                    <td><input name="check[11]" type="checkbox" value="12" />ABS</td>
                  </tr>
                  <tr>
                    <td><input name="check[12]" type="checkbox" value="13" />Airbag</td>
                  </tr>
                  <tr>
                    <td><input name="check[13]" type="checkbox" value="14" />Airbag passeggero</td>
                  </tr>
                  <tr>
                    <td><input name="check[14]" type="checkbox" value="15" />Airbag laterale</td>
                  </tr>
                  <tr>
                    <td><input name="check[15]" type="checkbox" value="16" />Fari Xenon</td>
                  </tr>
                  <tr>
                    <td><input name="check[16]" type="checkbox" value="17" />Chiusura centralizzata</td>
                  </tr>
                  <tr>
                    <td><input name="check[17]" type="checkbox" value="18" />Antifurto</td>
                  </tr>
                  <tr>
                    <td><input name="check[18]" type="checkbox" value="19" />Immobilizzatore elettronico</td>
                  </tr>
                  <tr>
                    <td><input name="check[19]" type="checkbox" value="20" />Controllo automatico trazione</td>
                  </tr>
                  <tr>
                    <td><input name="check[20]" type="checkbox" value="21" />ESP</td>
                  </tr>
                </tbody>
              </table></td>
          <td><table cellspacing="0" cellpadding="1" border="0">
            <tbody>
              <tr>
                <td><input name="check[21]" type="checkbox" value="22" />Trazione integrale</td>
              </tr>
              <tr>
                <td><input name="check[22]" type="checkbox" value="23" />Veicolo elaborato</td>
              </tr>
              <tr>
                <td><input name="check[23]" type="checkbox" value="24" />Cerchi in lega</td>
              </tr>
              <tr>
                <td><input name="check[24]" type="checkbox" value="25" />Portapacchi</td>
              </tr>
              <tr>
                <td><input name="check[25]" type="checkbox" value="26" />Fendinebbia</td>
              </tr>
              <tr>
                <td><input name="check[26]" type="checkbox" value="27" />Servosterzo</td>
              </tr>
              <tr>
                <td><input name="check[27]" type="checkbox" value="28" />Cruise Control</td>
              </tr>
              <tr>
                <td><input name="check[28]" type="checkbox" value="29" />Gancio traino</td>
              </tr>
            </tbody>
          </table>
    in pratica nel database mi scrive:
    questa riga: 1;2;3;4;5;6;7;8;9;10;12;13;14;15;16;17;18;19;20;22 ;23;24;25;26;27;28;

    come potete notare in corrispondenza dei check che non sono stati selezionati (es.Adatta ai portatori di Handicap, ESP, Gancio traino) non mi scrive nulla... da esempio sono quelli nelle posizioni 11, 21 e 29.... io inveve ho bisogno che mi deve mettere uno 0 (zero) al posto di 11, 21 e 29....

    come si può fare?


    grazie

  2. #2
    Il protocollo HTTP, per natura invia solo i dati interessanti.
    Questo vuol dire che non ti verranno inviati i valori dei checkbox non compilati ne i campi disabilitati ecc....

    Puoi affrontare il problema con javascript, prima di inviare il form, creandoti una lista in un campo hidden, oppure effettuare i confronti lato server con una array salvato in session al momento del caricamento dei dati.

    Ora non mi viene in mente altro.

    Ciao
    Mirko Agrati
    WEB : http://mirkoagrati.110mb.com
    RSS : http://feeds.feedburner.com/MirkoAgratiArticoli

  3. #3
    Utente di HTML.it L'avatar di tigerjack
    Registrato dal
    Aug 2003
    Messaggi
    1,661
    tradotto in codice?


    grazie

  4. #4
    Utente di HTML.it L'avatar di tigerjack
    Registrato dal
    Aug 2003
    Messaggi
    1,661
    up....

    è possibile una soluzione alternativa?


    grazie

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.