bonjour

voila après quelques recherches sur le web j'ai trouvé une petite solution,
grâce a ce nouveau code on peut obtenir les données des checkbox checked
les données sont sous forme d'un Array , le problème c'est que pour parcourir ce tableau
(après avoir cocher quelques checkbox) les donnes prennent un index déferrent
ici dans cette output ci_dessous , j'ai coche 3 checkboxes vous voyez pour accéder a les valeurs de checkboxes
il y'a celles qui sont enregistrées dans Array['index'] et celles dans Array['value'] !!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Array ( [0] => 2 [name] => model [model] => Array ( [1] => 3 ) [value] => 1 [check] => model )
donc ce code nécessite une petite correction pour pouvoir obtenir les données dans l'ordre suivant:

nom de checkbox, valeur de checkbox.

voila mon script
merci d'avance
index.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
<!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" lang="fr" xml:lang="fr">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
 
 
 
 
    <!-- Bootstrap core CSS -->
 
  </head>
 
<body>
<script>
function getData(names) {
	var value= $('input:checkbox:checked').val();
	  var status2 = $('input:checkbox').serialize();
       var dataString = 'name=' + status2 + '&value='+ value + '&check=' + names;
	$.ajax( {
    type: 'POST',
    url: 'getAll.php',
   data: dataString,
 
    success: function(data) {
        $('#showdata').html(data);
    }
} );
}
</script>
<p><b>Couleur</b></p>
<div class="checkbox">
  <label><input type="checkbox" id="model" name="model[]" value=1 onchange="getData(this.name)">Bleu  <span class="badge">(12556)</span></label>
  <label><input type="checkbox" id="model1" name="model[]" value=2 onchange="getData(this.name)">Rouge  <span class="badge">(6268)</span></label>
   <label><input type="checkbox" id="model2" name="model[]" value=3 onchange="getData(this.name)">Argent ou gris  <span class="badge">(21 660)</span></label>
   <label><input type="checkbox" id="model3" name="model[]" value=4 onchange="getData(this.name)">Noir  <span class="badge">(15 740)</span></label>
  <label><input type="checkbox" id="model4" name="model[]" value=5 onchange="getData(this.name)">Beige  <span class="badge">(717)</span></label>
   <label><input type="checkbox" id="model5"  name="model[]" value=6 onchange="getData(this.name)">Brown  <span class="badge">(852)</span></label>
 
 
 
 
</div>
 
 
<p><b>Puissance</b></p>
<div class="checkbox">
  <label><input type="checkbox" name="puissance[]" value=1 onchange="getData(this.name)"><75 ch  <span class="badge">(30 136)</span></label>
  <label><input type="checkbox" name="puissance[]" value=2 onchange="getData(this.name)">75-100 cv  <span class="badge">(15 244)</span></label>
   <label><input type="checkbox" name="puissance[]" value=3 onchange="getData(this.name)">101-125 ch  <span class="badge">(13 885)</span></label>
  <label><input type="checkbox" name="puissance[]" value=4 onchange="getData(this.name)">126-150 ch  <span class="badge">(3707)</span></label>
   <label><input type="checkbox" name="puissance[]" value=5 onchange="getData(this.name)">151-200 ch  <span class="badge">(1976)</span></label>
  <label><input type="checkbox" name="puissance[]" value=6 onchange="getData(this.name)">201-250 hp  <span class="badge">(533)</span></label>
 
 
</div>
<div id="showdata">
 
</div>
</body>
</html>
getAll.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
 
 
<?php
    //The array we begin with
    $start_array = array($_POST);
 
    //Convert the array to a string
    $array_string = print_r($start_array, true);
 
    //Get the new array
    $end_array = text_to_array($array_string);
 
    //Output the array!
    print_r($end_array);
 
    function text_to_array($str) {
 
        //Initialize arrays
        $keys = array();
        $values = array();
        $output = array();
 
        //Is it an array?
        if( substr($str, 0, 5) == 'Array' ) {
 
            //Let's parse it (hopefully it won't clash)
            $array_contents = substr($str, 7, -2);
            $array_contents = str_replace(array('[', ']', '=>'), array('#!#', '#?#', ''), $array_contents);
            $array_fields = explode("#!#", $array_contents);
 
            //For each array-field, we need to explode on the delimiters I've set and make it look funny.
            for($i = 0; $i < count($array_fields); $i++ ) {
 
                //First run is glitched, so let's pass on that one.
                if( $i != 0 ) {
 
                    $bits = explode('#?#', $array_fields[$i]);
                    if( $bits[0] != '' ) $output[$bits[0]] = $bits[1];
 
                }
            }
 
            //Return the output.
            return $output;
 
        } else {
 
            return null;
        }
 
    }
?>