Page 1 sur 1

selection d'une liste avec une checkbox

Posté : 30 août 2020, 10:51
par MARJAN
Bonjour,

J'ai un problème que je n'arrive pas à résoudre. Peut-être pouvez-vous m'aider.
Je veux dérouler une liste d'individus dans une page provenant d'une base de données.
Je souhaite que la personne qualifiée puisse changer les informations. Je fais donc un formulaire de la façon suivante :

Code : Tout sélectionner

<form method = "post" action = "ecriturecommissions.php" style ="font-size: 15px;line-height: 20px;""> <br><br> <?php WHILE($donnees = $reponse->fetch()){ if($donnees['NomMembre'] ==''){ $p{$i} = $donnees['PrénomPrésident']; $n{$i} = $donnees['NomPrésident']; }else{ $p{$i}= $donnees['PrénomMembre']; $n{$i} = $donnees['NomMembre']; } ?> <input type = "text" style = "background: #10f9ca;" name ="prenom.{$i}" value = "<?php echo $p{$i};?>" size ="10"/> <input type = "text" style = "background: #10f9ca;" name ="nom.{$i}" value = "<?php echo $n{$i};?>" size ="18"/> <input type = "checkbox" name = "supp{$i}" id = "supp{$i}"/><br> <?php $i = $i + 1; } ?><br><br> <input type = "submit" style = "background: #10f9ca;" class = "align4" value = "Supprimer les noms cochés" /> <br> <?php echo "Ajouter un membre"; ?> <input type = "hidden" name ="ecrire" value = "ecrire"> </form>
J'obtiens bien la liste voulue et une case checkbox pour chaque individu, seulement lorsque je clique sur une case à cocher, toutes le cases deviennent "on", alors que je donne un nom à chaque case : name = "supp{$i}"

Je ne vois pas l'explication. Pouvez-vous m'aider ?
Merci d'avance.

Re: selection d'une liste avec une checkbox

Posté : 30 août 2020, 14:27
par or 1
alors que je donne un nom à chaque case : name = "supp{$i}"
quel est le code html généré par ce code ?

Re: selection d'une liste avec une checkbox

Posté : 30 août 2020, 15:33
par MARJAN

Code : Tout sélectionner

for($i=1;$i<=20;$i++){ if(isset($_POST['supp{$i}'])){ echo "POST supp.$i = ".$_POST['supp{$i}'].'<br>'; }else{ echo "POST supp non transmis".'<br>'; } }
réponse :
POST supp.1 = on
POST supp.2 = on
POST supp.3 = on
POST supp.4 = on
POST supp.5 = on
POST supp.6 = on
POST supp.7 = on
POST supp.8 = on
POST supp.9 = on
POST supp.10 = on
POST supp.11 = on
POST supp.12 = on
POST supp.13 = on
POST supp.14 = on
POST supp.15 = on
POST supp.16 = on
POST supp.17 = on
POST supp.18 = on
POST supp.19 = on
POST supp.20 = on

Re: selection d'une liste avec une checkbox

Posté : 30 août 2020, 22:27
par or 1
quel est le code html généré par ce code ?

Re: selection d'une liste avec une checkbox

Posté : 30 août 2020, 23:06
par MARJAN
C'est un mélange de page faite par un logiciel et des programmes php.

Code : Tout sélectionner

<!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"> <head> <!-- 2020-08-29T18:19:17 *************************--> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7;IE=EmulateIE9" /> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <meta name="robots" content="noindex, follow"/> <meta name="generator" content="WebAcappella 4.6.27 professional (OSX) #569f"/> <title>index</title> <meta name="keywords" content="-----------"/> <meta name="description" content=""/> <style type="text/css"> body{margin-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;background-color:#feaf3f;} </style> <link rel="stylesheet" type="text/css" href="wa_global_style.css"/> <script type="text/javascript" src="jquery.js?v=86c"></script> <script type="text/javascript"> var waJSQuery = jQuery.noConflict(); </script> <script type="text/javascript" src="webacappella_core.js?v=1ups"></script> <!--[if lte IE 8]><script type="text/javascript" src="excanvas.js?v=1f2a"></script> <![endif]--> <!--[if lte IE 8]><script type="text/javascript" src="webacappella_patch_ie8.js?v=tc5"></script> <![endif]--> <script type="text/javascript"> document.write("\u003cscript type='text/javascript' src='wa_site_global_settings.js?v=1jay2sqg8j08g1"+urlSuffixe(1)+"'>\u003c/script>"); </script> <script type="text/javascript" src="jquery.mousewheel.js?v=use"></script> <link href="webacappella.css?v=10nl" rel="stylesheet" type="text/css" media="all"/> <!--[if lte IE 7]> <link href="webacappella_ie.css?v=1tjn" rel="stylesheet" type="text/css" media="all"/> <![endif]--> <script type="text/javascript" src="webacappella_tools.js?v=blf"></script> <script type="text/javascript"> waJSQuery(function() { initializeWA_JQuery() }); </script> <script type="text/javascript"> var waWebFontDescription={families:[ ]} </script> </head> <body><div id='wa-dialog-container' class='wa-fullscreen-contenair' style='position:absolute;z-index:52000;'></div><div id='html-centered' style='position:relative;width:100%;z-index:200;'><div id='is-global-layer' class='wa-main-page-contenair' style='position:relative;z-index:200;top:0px;width:1200px;;text-align:left;margin:0 auto; '><div style="position:absolute;top:1px;left:0px;width:1px;height:1px;"><a name="anchor-top">&nbsp;</a></div> <iframe class="wa-comp" style="position:absolute;z-index:10020;left:446px;top:44px;width:349px;height:560px;" name="frm-38ljio9l577x8" frameborder="0" width="349px" height="560px" src="http://www.lionsclubannonay.fr/compositioncommissions.php" scrolling="auto"></iframe><div style="position:absolute;z-index:10024;left:920px;top:44px;width:280px;height:560px;border:0px;background:rgba(0,0,0,0);overflow:hidden;" class="wa-comp wa-text wa-bg-gradient param[grad(rgba(0,0,0,0)) border(0 #969696)] " ><div style="position:absolute;z-index:10;line-height:1.2;margin:2px;top:0px;left:0px;width:278px;height:558px;word-wrap:break-word;overflow-y:auto;overflow-x:hidden;" ><div align="justify"><span style="font-family:'Arial';font-size:18px;font-weight:bold;color:#000000;" >Vous pouvez modifier les attributions des membres du bureau, ainsi que la composition des commissions.</span></div><div style="font-family:''Arial'';font-size:18px;font-weight:bold;">&nbsp;<br /></div><div align="justify"><span style="font-family:'Arial';font-size:18px;font-weight:bold;color:#000000;" >1&#176;) Remplissez ou modifiez</span></div><div align="center"><span style="font-family:'Arial';font-size:18px;font-weight:bold;color:#000000;" > &#34;BUREAU&#34;.</span></div><div align="justify"><span style="font-family:'Arial';font-size:18px;font-weight:bold;color:#000000;" >Enregistrez vos modifications.</span></div><div style="font-family:''Arial'';font-size:18px;font-weight:bold;">&nbsp;<br /></div><div align="justify"><span style="font-family:'Arial';font-size:18px;font-weight:bold;color:#000000;" >2&#176;) Remplissez ou modifiez</span></div><div align="center"><span style="font-family:'Arial';font-size:18px;font-weight:bold;color:#000000;" > &#34;COMMISSIONS&#34;. </span></div><div style="font-family:''Arial'';font-size:18px;font-weight:bold;">&nbsp;<br /></div><div align="left"><span style="font-family:'Arial';font-size:18px;font-weight:bold;color:#000000;" >La liste des membres s'applique &#224; la commission qui est indiqu&#233;e en haut avec le nom de son Pr&#233;sident.</span></div><div align="justify"><span style="font-family:'Arial';font-size:18px;font-weight:bold;color:#000000;" >Validez vos modifications pour chaque commission.</span></div><div style="font-family:''Arial'';font-size:18px;font-weight:bold;">&nbsp;<br /></div><div align="justify"><span style="font-family:'Arial';font-size:18px;font-weight:bold;color:#000000;" >Ces tableaux sont absolument</span></div><div align="justify"><span style="font-family:'Arial';font-size:18px;font-weight:bold;color:#000000;" >n&#233;cessaires pour la bonne marche du site. Veuillez les remplir avec le meilleur soin s'il vous plait.</span></div></div></div><div style="position:absolute;z-index:10016;left:518px;top:9px;width:220px;height:40px;border:0px;background:rgba(0,0,0,0);overflow:hidden;" class="wa-comp wa-text wa-bg-gradient param[grad(rgba(0,0,0,0)) border(0 #969696)] " ><div style="position:absolute;z-index:10;line-height:1.2;margin:2px;top:0px;left:0px;width:218px;height:38px;word-wrap:break-word;overflow-y:auto;overflow-x:hidden;" ><div align="center"><span style="font-family:'Arial';font-size:20px;font-weight:bold;color:#000000;" >Commissions</span></div></div></div><iframe class="wa-comp" style="position:absolute;z-index:10012;left:0px;top:44px;width:171px;height:560px;" name="frm-9k9agwqg8i8jbn" frameborder="0" width="171px" height="560px" src="http://www.lionsclubannonay.fr/compositionbureau.php" scrolling="auto"></iframe><iframe class="wa-comp" style="position:absolute;z-index:10008;left:170px;top:44px;width:273px;height:560px;" name="frm-7gm3c0qgbxnlim" frameborder="0" width="273px" height="560px" src="http://www.lionsclubannonay.fr/compositionbureau2.php" scrolling="auto"></iframe><div style="position:absolute;z-index:10004;left:69px;top:9px;width:220px;height:40px;border:0px;background:rgba(0,0,0,0);overflow:hidden;" class="wa-comp wa-text wa-bg-gradient param[grad(rgba(0,0,0,0)) border(0 #969696)] " ><div style="position:absolute;z-index:10;line-height:1.2;margin:2px;top:0px;left:0px;width:218px;height:38px;word-wrap:break-word;overflow-y:auto;overflow-x:hidden;" ><div align="center"><span style="font-family:'Arial';font-size:20px;font-weight:bold;color:#000000;" >Bureau</span></div></div></div><div onclick="return waOnClick('crbst_63.html',{})" class="wa-button-link wa-comp param[bord(#3d3d3d) inner_bord(rgba(255,255,255,0.4)) bg(#3d3d3d #5b5b5b) txt(#ffffff) u(0) bg_img() img() ]" style="position:absolute;z-index:10000;left:372px;top:605px;width:130px;height:30px;;cursor:pointer;cursor:hand;text-decoration:none;"><div class="waButInner" style="position:absolute;left:1px;top:1px;padding:0px;margin:0px;width:126px;height:26px;border:1px solid rgba(255,255,255,0.4);-moz-border-radius:4px;border-radius:4px;-webkit-border-radius:4px;" ></div> <div class="waButGlossInner" style="position:absolute;left:0px;top:0px;margin:0px;width:130px;height:15px;background:-webkit-gradient(linear,0 0, 0 15,from(rgba(255,255,255,0.5)),to(rgba(255,255,255,0.1)));background:-moz-linear-gradient(top left 270deg,rgba(255,255,255,0.5) 0px,rgba(255,255,255,0.1) 15px);-moz-border-radius:4px;border-radius:4px;-webkit-border-radius:4px;" ></div> <button class="wa-button param[grad(0 21 0 30 #8df12a #cbff97) aqua(1) border(#8df12a) inborder(rgba(255,255,255,0.4)) ]" style="overflow: hidden; position:static;margin:0px;padding:0px;width:130px;height:30px;-moz-border-radius:4px;border-radius:4px;-webkit-border-radius:4px;border:1px solid #8df12a;background:-webkit-gradient(linear,0 21, 0 30,from(#8df12a),to(#cbff97));background:-moz-linear-gradient(top left 270deg,#8df12a 21px,#cbff97 30px);text-align:center;cursor:pointer;font-weight:bold;font-size:12px;color:#000000;font-family:'Arial';" > <div><a href="crbst_63.html" onclick="return false;" class="wa-but-txt " style="position:relative;margin:0px;padding:0px;display:inline;vertical-align:middle;font-weight:bold;font-size:12px;color:#000000;font-family:'Arial';text-decoration:none;" >RETOUR</a></div></button> </div><div style="position:absolute;top:614px;left:0px;width:1px;height:1px;" ><a name="anchor-bottom">&nbsp;</a></div> <div id='dynmenu-container' style='position:absolute;z-index:51000;'></div></div> </div> <!--end html-centered--> <script type="text/javascript"> <!-- document.webaca_page_option_background=0 document.webaca_page_background_img_size=[-1,-1] document.webaca_page_is_centered=true; document.webaca_width_page=1200; document.webaca_height_page=634; document.webaca_banner_height=0; document.webaca_is_preview=false; var wa_global_market = {markets:new Array(),id_modif_dlg_js:''}; Translator.m_lang="fr"; Translator.m_languages={} Translator.m_lang_for_filename=""; function wa_timeout(_fct,_time,p1,p2,p3){return setTimeout(_fct,_time,p1,p2,p3)} function wa_evaluate(_s){return eval(_s)} function IS_onload(){ IS_onload_WA(); } --> </script> <script type="text/javascript" src='wa_common_messages_fr.js?v='></script> <script type="text/javascript"> <!-- WA_loadMessages(); --> </script> <script type="text/javascript"> <!-- --> </script> </body> </html>

Re: selection d'une liste avec une checkbox

Posté : 30 août 2020, 23:38
par or 1
quel est le code html généré par le code php du premier message de cette discussion ? code qui commence par
<form method = "post" action = "ecriturecommissions.php" style ="font-size: 15px;line-height: 20px;"">
que l'on doit donc retrouver dans le html généré.

Re: selection d'une liste avec une checkbox

Posté : 31 août 2020, 12:08
par MARJAN
1°) Tout mon code est en php, il est donc caché en html. Je mets donc ci-dessous le code php.

2°) le premier code est celui de membrescommissions.php qui comporte :
<input nom> <input prenom> <input checkbox>
le bouton submit renvoie à ecriturecommission.php

3°) le second code est celui de ecriturecommission.php
j'essaie de voir pour l'instant dans ce code comment sont transmises les valeurs des checkbox $_POST['supp{$i}']
Si je coche une checkbox dans membrecommissions, toutes les checkbox sont "on"

Code : Tout sélectionner

Membrescommissions.php <?php session_start(); ?> <head> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <link rel="stylesheet" href= "position.css" /> <head> <body style = "background: #955914;color:yellow"> <?php $bdd = newPDO('mysql:host=AAAAA.mysql;dbname=BBBB', 'CCCC', 'DDDD', array (PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'')); $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if($_SESSION['commission1']== "Effectifs"){ echo "Commission : Effectifs".'<br>'; $res = $bdd->query('select count(*) as nb from Effectifs'); $data = $res->fetch(); $nb = $data['nb']; if($nb == 1){ echo '<br>'.$nb." Membre".'<br>'; }else{ echo '<br>'.$nb." Membres".'<br>'; } $reponse = $bdd->query('SELECT * FROM Effectifs'); } if($_SESSION['commission1']== "Communication"){ echo "Commission : Communication".'<br>'; $res = $bdd->query('select count(*) as nb from Communication'); $data = $res->fetch(); $nb = $data['nb']; if($nb == 1){ echo '<br>'.$nb." Membre".'<br>'; }else{ echo '<br>'.$nb." Membres".'<br>'; } $reponse = $bdd->query('SELECT * FROM Communication'); } -------> idem pour toutes les commissions------------- $i = 1; ?> <form method = "post" action = "ecriturecommissions.php" style ="font-size: 15px;line-height: 20px;""> WHILE($donnees = $reponse->fetch()){ if($donnees['NomMembre'] ==''){ $p{$i} = $donnees['PrénomPrésident']; $n{$i} = $donnees['NomPrésident']; }else{ $p{$i}= $donnees['PrénomMembre']; $n{$i} = $donnees['NomMembre']; } ?> <input type = "text" style = "background: #10f9ca;" name ="prenom.{$i}" value = "<?php echo $p{$i};?>" size ="10"/> <input type = "text" style = "background: #10f9ca;" name ="nom.{$i}" value = "<?php echo $n{$i};?>" size ="18"/> <input type = "checkbox" name = "supp{$i}" id = "supp{$i}"/><br> <?php $i = $i + 1; } ?> <input type = "submit" style = "background: #10f9ca;" class = "align4" value = "Supprimer les noms cochés" /><br> <?php echo "Ajouter un membre"; ?> <input type = "hidden" name ="ecrire" value = "ecrire"> </form>

Code : Tout sélectionner

ECRITURECOMMISSION.PHP <?php session_start(); header( 'content-type: text/html; charset=utf-8'); echo "ecriturecommissions.php".'<br>'; ?> <head> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <link rel="stylesheet" href= "position.css" /> </head> <body style = "background: #955914;color:yellow"> <?php echo "SESSION1 =".$_SESSION['commission1'].'<br>'; echo "SESSION2 =".$_SESSION['commission2'].'<br>'; for($i=1;$i<=20;$i++){ if(isset($_POST['supp{$i}'])){ echo "POST supp.$i = ".$_POST['supp{$i}'].'<br>'; }else{ echo "POST supp non transmis".'<br>'; } } exit();
Peut-être pourrez-vous vous contenter du code php ??
Merci d'avance

Re: selection d'une liste avec une checkbox

Posté : 31 août 2020, 13:42
par or 1
quel est le code html généré par le code php du premier message de cette discussion ? code qui commence par
<form method = "post" action = "ecriturecommissions.php" style ="font-size: 15px;line-height: 20px;"">
que l'on doit donc retrouver dans le html généré.

Re: selection d'une liste avec une checkbox

Posté : 31 août 2020, 14:39
par Spols
or1 te demande de copier le code html obtenu dans ton navigateur (ctrl+U)

mais regarde comment tu génère ton code, $i est une variable php qui est parfois en dehors de balise <?php ?> donc pas interprété

Re: selection d'une liste avec une checkbox

Posté : 01 sept. 2020, 14:24
par MARJAN
Pour y voir plus clair, j'ai isolé le problème en le résumant avec les 2 scripts ci-dessous.
Il y a impossibilité de nommer les input du script "essai.php" et de les poster dans le script "essai2.php".
l'erreur vient de là, mais je n'arrive pas à nommer et à poster les variables !...
j'ai tout essayé :
texte{$i}
texte$i
texte.$i
Pouvez-vous m'aider svp ?

essai.php

Code : Tout sélectionner

<?php $i = 1; ?> <form method = "post" action = "essai2.php""> <?php for($i=1;$i<=20;$i++){ ?> <input type = "text" name = "texte{$i}" value = "<?php echo "texte $i";?>" /> <input type ="checkbox" name ="checkbox{$i}" /><br> <?php } ?> <input type="submit" name ="envoi" onclick="submit()" /> <label for="envoi">envoi</label><br /> </form>
essai2.php

Code : Tout sélectionner

<?php session_start(); $i = 1; for($i=1;$i<=20;$i++){ echo $_POST['texte{$i}']; echo $_POST['checkbox{$i}'].'<br>'; }

Re: selection d'une liste avec une checkbox

Posté : 01 sept. 2020, 14:59
par or 1
"$i est une variable php qui est parfois en dehors de balise <?php ?> donc pas interprété"

<input type = "text" name = "texte{$i}" value = "<?php echo "texte $i";?>" />
qu'est-ce que cela affiche dans la source de la page générée ?

Re: [RESOLU] selection d'une liste avec une checkbox

Posté : 02 sept. 2020, 10:11
par MARJAN
J'ai trouvé :
Il s'agit de plusieurs erreurs de concaténation entre texte et variable à l'envoi et à la réception du formulaire : name = "texte{$i}".
Je n'y suis pas arrivé directement, mais j'ai concaténé morceau par morceau et ça a marché.
Merci pour votre aide.