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 28/08/2007, 19h32   #1
Membre confirmé
 
Inscription : mars 2003
Messages : 674
Détails du profil
Informations forums :
Inscription : mars 2003
Messages : 674
Points : 242
Points : 242
Par défaut Concaténer les valeurs dans une boucle

Bonjour.

Je suis toujours avec mes cases à cocher.

Je voudrais concaténer les valeurs des case à cocher en faisant une boucle mais je n'ai que la dernière case cochée qui est retournée.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
<input type="checkbox" name="langue[]" value="Français" <?php if(!empty($langue)){ if(in_array("Français",$langue)) { echo 'checked'; }} ?>/>Français<br/>
<input type="checkbox" name="langue[]" value="Anglais" <?php if(!empty($langue)){ if(in_array("Anglais",$langue)) { echo 'checked'; }} ?>/>Anglais<br/>
<input type="checkbox" name="langue[]" value="Italien" <?php if(!empty($langue)){ if(in_array("Italien",$langue)) { echo 'checked'; }} ?>/>Italien<br/>
<input type="checkbox" name="langue[]" value="Allemand" <?php if(!empty($langue)){ if(in_array("Allemand",$langue)) { echo 'checked'; }} ?>/>Allemand<br/>
<input type="checkbox" name="langue[]" value="Espagnol" <?php if(!empty($langue)){ if(in_array("Espagnol",$langue)) { echo 'checked'; }} ?>/>Espagnol<br/>
<input type="checkbox" name="langue[]" value="Portugais" <?php if(!empty($langue)){ if(in_array("Portugais",$langue)) { echo 'checked'; }} ?>/>Portugais<br/>
 
if (isset($_POST['langue'])) {
    for ($i = 0, $c = count($_POST['langue']); $i < $c; $i++) {
        echo  "" . $_POST['langue'][$i] . "";
        $valeur =  "" . $_POST['langue'][$i] . "";
    }
}
Avec echo ça marche mais pas avec $valeur

Donc merci d'avance
philippef est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/08/2007, 19h38   #2
Rédacteur
 
Avatar de Yoshio
 
Homme
Inscription : septembre 2005
Messages : 1 741
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 24
Localisation : Belgique

Informations forums :
Inscription : septembre 2005
Messages : 1 741
Points : 1 497
Points : 1 497
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
<input type="checkbox" name="langue[]" value="Français" <?php if(!empty($langue)){ if(in_array("Français",$langue)) { echo 'checked'; }} ?>/>Français<br/>
<input type="checkbox" name="langue[]" value="Anglais" <?php if(!empty($langue)){ if(in_array("Anglais",$langue)) { echo 'checked'; }} ?>/>Anglais<br/>
<input type="checkbox" name="langue[]" value="Italien" <?php if(!empty($langue)){ if(in_array("Italien",$langue)) { echo 'checked'; }} ?>/>Italien<br/>
<input type="checkbox" name="langue[]" value="Allemand" <?php if(!empty($langue)){ if(in_array("Allemand",$langue)) { echo 'checked'; }} ?>/>Allemand<br/>
<input type="checkbox" name="langue[]" value="Espagnol" <?php if(!empty($langue)){ if(in_array("Espagnol",$langue)) { echo 'checked'; }} ?>/>Espagnol<br/>
<input type="checkbox" name="langue[]" value="Portugais" <?php if(!empty($langue)){ if(in_array("Portugais",$langue)) { echo 'checked'; }} ?>/>Portugais<br/>

if (isset($_POST['langue'])) {
    for ($i = 0, $c = count($_POST['langue']); $i < $c; $i++) {
        echo  "" . $_POST['langue'][$i] . "";
        $valeur .=  " " . $_POST['langue'][$i] . " ";
    }
}
J'ai pas très bien compris mais tu écrase à chaque fois ta variable.
Yoshio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/08/2007, 19h53   #3
Membre confirmé
 
Inscription : mars 2003
Messages : 674
Détails du profil
Informations forums :
Inscription : mars 2003
Messages : 674
Points : 242
Points : 242
Oui c'est bien mon problème.
si je coche "Français" et "Italien", echo me retourne "FrançaisItalien" mais $valeur ne me retourne que "Italien" et je ne sais pas comment obtenir $valeur = "FrançaisItalien" pour enregistrer $valeur dans ma table
philippef est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/08/2007, 20h01   #4
Modérateur
 
Avatar de mathieu
 
Inscription : juin 2003
Messages : 4 893
Détails du profil
Informations forums :
Inscription : juin 2003
Messages : 4 893
Points : 4 466
Points : 4 466
tu as vu la modification que Yoshio a faite dans ton code ?
__________________
Modérateur PHP
mathieu est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/08/2007, 20h08   #5
Membre confirmé
 
Inscription : mars 2003
Messages : 674
Détails du profil
Informations forums :
Inscription : mars 2003
Messages : 674
Points : 242
Points : 242
Désolé j'avais pas fait attention.
Je regarderai mieux la prochaine fois et je mettrais des lunettes.

En tout cas merci.
philippef 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 22h50.


 
 
 
 
Partenaires

Hébergement Web