Précédent   Forum des professionnels en informatique > PHP > Langage > Formulaires
Formulaires Forum d'entraide sur les formulaires avec PHP. Avant de poster -> FAQ formulaires, Cours de formulaires et Sources de formulaires
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 20/03/2011, 17h00   #1
Nouveau Membre du Club
 
Homme Maxime
Développeur Web et Mobile
Inscription : juin 2010
Messages : 68
Détails du profil
Informations personnelles :
Nom : Homme Maxime
Âge : 21
Localisation : France, Gard (Languedoc Roussillon)

Informations professionnelles :
Activité : Développeur Web et Mobile

Informations forums :
Inscription : juin 2010
Messages : 68
Points : 34
Points : 34
Envoyer un message via MSN à Xenonmax
Par défaut Récupération d'un select avec option multiple

Bonjour, je m'adresse à vous car çà doit faire 2 heures que je bute sur un problème de récupération de select multiple.

Le code suivant à été récupérer sur le net :
<HEAD></HEAD> :
Code :
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
64
 
<script language="JavaScript" type="text/javascript">
 
function deplacer( liste_depart, liste_arrivee ) {
  for( i = 0; i < liste_depart.options.length; i++ ) {
    if( liste_depart.options[i].selected && liste_depart.options[i] != "" ) {
      o = new Option( liste_depart.options[i].text, liste_depart.options[i].value);
      liste_arrivee.options[liste_arrivee.options.length] = o;
      liste_depart.options[i] = null;
      i = i - 1 ;
    }
    else {
      // alert( "aucun element selectionne" );
    }
  }
}
 
function deplacer_tout( liste_depart, liste_arrivee ) {
  for( i = 0; i < liste_depart.options.length; i++ ) {
    o = new Option( liste_depart.options[i].text, liste_depart.options[i].value);
    liste_arrivee.options[liste_arrivee.options.length] = o;
    liste_depart.options[i] = null;
    i = i - 1 ;
  }
}
 
function deplacer_hautbas( liste, sens ) {
  // init
  var listemax = liste.length - 2;
  var listesel = liste.selectedIndex;
  // debordement
  if( ( listesel < 0 ) || ( listesel < 1 && sens == -1 ) || ( listesel > listemax && sens == 1 ) ) {
    return false;
  }
  // permutation
  tmpopt = new Option( liste.options[listesel+sens].text, liste.options[listesel+sens].value );
  liste.options[listesel+sens].text = liste.options[listesel].text;
  liste.options[listesel+sens].value = liste.options[listesel].value;
  liste.options[listesel+sens].selected = true;
  liste.options[listesel].text = tmpopt.text;
  liste.options[listesel].value = tmpopt.value;
  liste.options[listesel].selected = false;
  return true;
}
 
function soumettre_2listes( liste1, liste2 ) {
  var listelen1 = liste1.length;
  for( i = 0; i < listelen1; i++ ) {
    liste1.options[i].selected = true;
  }
  var listelen2 = liste2.length;
  for( j = 0; j < listelen2; j++ ) {
    liste2.options[j].selected = true;
  }
}
 
function soumettre_1liste( liste ) {
  var listelen = liste.length;
  for( i = 0; i < listelen; i++ ) {
    liste.options[i].selected = true;
  }
}
 
</script>
<BODY></BODY> :
Code :
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
64
65
66
67
68
 
<form name="export" method="POST" OnSubmit="javascript: soumettre_1liste( document.forms[0].choix );" action="recuperation.php">
 
<table summary="" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <th style="width:  90px;"></th>
    <th style="width: 220px;"></th>
    <th style="width: 150px;"></th>
    <th style="width: 220px;"></th>
    <th style="width:  90px;"></th>
  </tr>
  <tr>
    <td><br /></td>
    <td>Champ(s) disponible(s)<br /></td>
    <td><br /></td>
    <td>Champ(s) sélectionné(s)<br /></td>
    <td><br /></td>
  </tr>
  <tr>
    <td><br /></td>
    <td rowspan="7">
      <select name="dispo[]" id="dispo" style="width: 210px;" size="16" multiple="multiple" OnDblClick="javascript: deplacer( this.form.dispo, this.form.choix );">
      <?php
        while($data = mysql_fetch_array($result)) {
          echo '<option value="'.$data['geolocalisations_id'].'">'.$data['geolocalisations_libelle'].'<br /></option>';
        }
       ?>
      </select><br />
    </td>
    <td><br /></td>
    <td rowspan="7">
      <select name="choix[]" id="choix" style="width: 210px;" size="16" multiple="multiple" OnDblClick="javascript: deplacer( this.form.choix, this.form.dispo );">
      </select><br />
    </td>
    <td><br /></td>
  </tr>
  <tr>
    <td><br /></td>
    <td><input type="button" value="ajouter >" OnClick="javascript: deplacer( this.form.dispo, this.form.choix );" /><br /></td>
    <td rowspan="2"><input type="button" value="Monter" OnClick="javascript: deplacer_hautbas( this.form.choix, -1 );" /><br /></td>
  </tr>
  <tr>
    <td><br /></td>
    <td><input type="button" value="ajouter tout >>" OnClick="javascript: deplacer_tout( this.form.dispo, this.form.choix );" /><br /></td>
  </tr>
  <tr>
    <td><br /></td>
    <td><br /></td>
    <td><br /></td>
  </tr>
  <tr>
    <td><br /></td>
    <td><input type="button" value="< retirer" OnClick="javascript: deplacer( this.form.choix, this.form.dispo );" /><br /></td>
    <td rowspan="2"><input type="button" value="Descendre" OnClick="javascript: deplacer_hautbas( this.form.choix, 1 );" /><br /></td>
  </tr>
  <tr>
    <td><br /></td>
    <td><input type="button" value="<< retirer tout" OnClick="javascript: deplacer_tout( this.form.choix, this.form.dispo );" /><br /></td>
  </tr>
  <tr>
    <td><br /></td>
    <td><br /></td>
    <td><br /></td>
  </tr>
</table>
<br />
<input type="submit" value="OK" /> <input type="reset" value="Annuler" /><br />
</form>
Et voilà mon code de récupération de la page "recuperation.php" :

Code :
1
2
3
4
5
6
7
8
9
 
<?php
$id=1;
for ($i = 0, $c = count($_POST['choix']); $i < $c; $i++) {
  $query = "INSERT INTO contenir (graphiques_id, libelledonnees_id) VALUES ('".$id."', '".$_POST['choix'][$i]."');";
  echo $query.'</br>';
  // $result = mysql_query($query);
}
?>
Hors aucune requête ne s'affiche à l'écran.

Je vous remercie d'avance de vos réponses.
Xenonmax est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/03/2011, 20h13   #2
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Ta boucle est vraiment très laide : utilise foreach pour ta boucle et un id autoincrementé pour ta table.

Sinon controler ce que tu recois du formulaire :
Ton problème doit plutot se situer sur le Javascript.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/03/2011, 23h37   #3
Nouveau Membre du Club
 
Homme Maxime
Développeur Web et Mobile
Inscription : juin 2010
Messages : 68
Détails du profil
Informations personnelles :
Nom : Homme Maxime
Âge : 21
Localisation : France, Gard (Languedoc Roussillon)

Informations professionnelles :
Activité : Développeur Web et Mobile

Informations forums :
Inscription : juin 2010
Messages : 68
Points : 34
Points : 34
Envoyer un message via MSN à Xenonmax
J'ai trouvé une partie de mon erreur puisque maintenant avec DUMP, je récupère bien mon tableau "choix[]" mais je n'ai toujours rien dedans.
C'est un problème sur la partie JavaScript.
Si quelqu'un a une idée, sinon je demanderai à mes profs d'info jeudi.
Xenonmax est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/03/2011, 14h14   #4
Nouveau Membre du Club
 
Homme Maxime
Développeur Web et Mobile
Inscription : juin 2010
Messages : 68
Détails du profil
Informations personnelles :
Nom : Homme Maxime
Âge : 21
Localisation : France, Gard (Languedoc Roussillon)

Informations professionnelles :
Activité : Développeur Web et Mobile

Informations forums :
Inscription : juin 2010
Messages : 68
Points : 34
Points : 34
Envoyer un message via MSN à Xenonmax
C'est bon j'ai trouvé la solution, en faite c'était javascript qui me posait problème.
Xenonmax est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 20h17.


 
 
 
 
Partenaires

Hébergement Web