PHP pb cases à cocher + menu déroulant
Résolu/Fermé
Fou riant
Messages postés
32
Date d'inscription
jeudi 5 juin 2008
Statut
Membre
Dernière intervention
10 novembre 2009
-
6 juin 2008 à 09:49
Fou riant Messages postés 32 Date d'inscription jeudi 5 juin 2008 Statut Membre Dernière intervention 10 novembre 2009 - 6 juin 2008 à 14:47
Fou riant Messages postés 32 Date d'inscription jeudi 5 juin 2008 Statut Membre Dernière intervention 10 novembre 2009 - 6 juin 2008 à 14:47
A voir également:
- PHP pb cases à cocher + menu déroulant
- Menu déroulant excel - Guide
- Menu démarrer windows 11 - Guide
- Comment cocher une case sur word ✓ - Forum Word
- Easy php - Télécharger - Divers Web & Internet
- Samira a modifié le menu du jour que juliette lui avait envoyé. retrouvez les modifications proposées par samira : acceptez celles concernant les entrées, refusez celles concernant les plats et les desserts. combien de caractères (en incluant les espaces) contient la version finale du menu ? - Forum Matériel & Système
9 réponses
drizzt_do_urden
Messages postés
40
Date d'inscription
mardi 9 octobre 2007
Statut
Membre
Dernière intervention
28 juillet 2015
4
6 juin 2008 à 09:56
6 juin 2008 à 09:56
Salut,
plutot que
eval('$tmp_chk = $_POST[\'client_'.$n.'\'];');
Il vaudrait pas mieux ca ?
$tmp_chk = $_POST['client_'.$n];
eval($tmp_chk);
Ca donne pas le meme resultat en index mais ca paraitrait beaucoup plus logique.
Tu pourrais montrer ta partie html (ton formulaire) qu on voit un peu le nom des champs.
++
plutot que
eval('$tmp_chk = $_POST[\'client_'.$n.'\'];');
Il vaudrait pas mieux ca ?
$tmp_chk = $_POST['client_'.$n];
eval($tmp_chk);
Ca donne pas le meme resultat en index mais ca paraitrait beaucoup plus logique.
Tu pourrais montrer ta partie html (ton formulaire) qu on voit un peu le nom des champs.
++
Fou riant
Messages postés
32
Date d'inscription
jeudi 5 juin 2008
Statut
Membre
Dernière intervention
10 novembre 2009
2
6 juin 2008 à 10:16
6 juin 2008 à 10:16
Hi,
La partie d'affichage de personnes est la suivante :
//Affichage des données
$i=1;
while($tab = mysqli_fetch_assoc($resultat))
{
$IdClient = $tab['code_prospect'];
if (($i%2)==0)
{
echo '<tr bgcolor=#D1D1D1>';
}
else
{
echo '<tr bgcolor=#ECECEC>';
}
// Un champs hidden permet de conserver l'ID du Prospect lors du POST
echo '<td><input type=checkbox name=client_'.$i.'><input type="hidden" name="hidden_'.$i.'" value="'.$tab['code_prospect'].'"></td>';
echo '<td><font face=arial size=1>'.$tab['nom_civ']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['prenom']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['adresse1']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['adresse2']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['telephone']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['portable']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['fax']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['email']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['code_postal']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['ville']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom_site']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom_succ']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom_struct']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom_serv']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom_fonct']. '</td></font>';
$Date_Visite = preg_replace("!(\d{4})-(\d{2})-(\d{2})!","\\3/\\2/\\1",$tab['date_visite']);
echo '<td><font face=arial size=1>'.$Date_Visite. '</td></font>';
echo '</tr>';
$i++;
}
echo '</table>';
echo '</form>';
Pour ce qui est du menu déroulant :
//menu deroulant des actions
echo '<td colspan=1 rowspan=1>';
echo "<form method=get action=liste_prospects.php>";
echo " <select name=action>";
echo "<option value='Creation' selected='selected'>Creation</option>
<option value='Mailing'>Mailing</option>
<option value='Modification'>Modification</option> //--- fonction demandant une case
<option value='Rechercher'>Recherche avancée</option>
<option value='Suppression'>Suppression</option> //--- fonction demandant une case
<option value='Visite'>Visite</option> //--- fonction demandant une case
</select>";
echo "<input type=submit name=make value='Faire'> ";
Voilà.
La partie d'affichage de personnes est la suivante :
//Affichage des données
$i=1;
while($tab = mysqli_fetch_assoc($resultat))
{
$IdClient = $tab['code_prospect'];
if (($i%2)==0)
{
echo '<tr bgcolor=#D1D1D1>';
}
else
{
echo '<tr bgcolor=#ECECEC>';
}
// Un champs hidden permet de conserver l'ID du Prospect lors du POST
echo '<td><input type=checkbox name=client_'.$i.'><input type="hidden" name="hidden_'.$i.'" value="'.$tab['code_prospect'].'"></td>';
echo '<td><font face=arial size=1>'.$tab['nom_civ']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['prenom']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['adresse1']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['adresse2']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['telephone']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['portable']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['fax']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['email']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['code_postal']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['ville']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom_site']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom_succ']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom_struct']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom_serv']. '</td></font>';
echo '<td><font face=arial size=1>'.$tab['nom_fonct']. '</td></font>';
$Date_Visite = preg_replace("!(\d{4})-(\d{2})-(\d{2})!","\\3/\\2/\\1",$tab['date_visite']);
echo '<td><font face=arial size=1>'.$Date_Visite. '</td></font>';
echo '</tr>';
$i++;
}
echo '</table>';
echo '</form>';
Pour ce qui est du menu déroulant :
//menu deroulant des actions
echo '<td colspan=1 rowspan=1>';
echo "<form method=get action=liste_prospects.php>";
echo " <select name=action>";
echo "<option value='Creation' selected='selected'>Creation</option>
<option value='Mailing'>Mailing</option>
<option value='Modification'>Modification</option> //--- fonction demandant une case
<option value='Rechercher'>Recherche avancée</option>
<option value='Suppression'>Suppression</option> //--- fonction demandant une case
<option value='Visite'>Visite</option> //--- fonction demandant une case
</select>";
echo "<input type=submit name=make value='Faire'> ";
Voilà.
drizzt_do_urden
Messages postés
40
Date d'inscription
mardi 9 octobre 2007
Statut
Membre
Dernière intervention
28 juillet 2015
4
6 juin 2008 à 09:57
6 juin 2008 à 09:57
Salut,
plutot que
eval('$tmp_chk = $_POST[\'client_'.$n.'\'];');
Il vaudrait pas mieux ca ?
$tmp_chk = $_POST['client_'.$n];
eval($tmp_chk);
Ca donne pas le meme resultat en index mais ca paraitrait beaucoup plus logique.
Tu pourrais montrer ta partie html (ton formulaire) qu on voit un peu le nom des champs.
++
plutot que
eval('$tmp_chk = $_POST[\'client_'.$n.'\'];');
Il vaudrait pas mieux ca ?
$tmp_chk = $_POST['client_'.$n];
eval($tmp_chk);
Ca donne pas le meme resultat en index mais ca paraitrait beaucoup plus logique.
Tu pourrais montrer ta partie html (ton formulaire) qu on voit un peu le nom des champs.
++
Fou riant
Messages postés
32
Date d'inscription
jeudi 5 juin 2008
Statut
Membre
Dernière intervention
10 novembre 2009
2
6 juin 2008 à 10:20
6 juin 2008 à 10:20
J'ai essayé de remplacer
eval('$tmp_chk = $_POST[\'client_'.$n.'\'];');
eval('$tmp_hid = $_POST[\'hidden_'.$n.'\'];');
par
$tmp_chk = $_POST['client_'.$n];
eval($tmp_chk);
$tmp_hid = $_POST['hidden_'.$n];
eval($tmp_hid);
mais ça change rien..
(merci de m'aider^^)
eval('$tmp_chk = $_POST[\'client_'.$n.'\'];');
eval('$tmp_hid = $_POST[\'hidden_'.$n.'\'];');
par
$tmp_chk = $_POST['client_'.$n];
eval($tmp_chk);
$tmp_hid = $_POST['hidden_'.$n];
eval($tmp_hid);
mais ça change rien..
(merci de m'aider^^)
drizzt_do_urden
Messages postés
40
Date d'inscription
mardi 9 octobre 2007
Statut
Membre
Dernière intervention
28 juillet 2015
4
6 juin 2008 à 10:25
6 juin 2008 à 10:25
Logique en fait on diriat :
$tmp_chk = $_POST['client_'.$n];
$tmpChk = eval($tmp_chk);
if(isset($tmpChk))
Si ca marche pas, fait un
$tmp_chk = $_POST['client_'.$n];
$tmpChk = eval($tmp_chk);
echo '|'.$tmpChk.'|';
if(isset($tmpChk))
et donne ce qui s affiche ;)
$tmp_chk = $_POST['client_'.$n];
$tmpChk = eval($tmp_chk);
if(isset($tmpChk))
Si ca marche pas, fait un
$tmp_chk = $_POST['client_'.$n];
$tmpChk = eval($tmp_chk);
echo '|'.$tmpChk.'|';
if(isset($tmpChk))
et donne ce qui s affiche ;)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Fou riant
Messages postés
32
Date d'inscription
jeudi 5 juin 2008
Statut
Membre
Dernière intervention
10 novembre 2009
2
6 juin 2008 à 10:36
6 juin 2008 à 10:36
Le code ressemble donc à ça maintenant :
if ($_POST['action'] == 'Suppression')
{
// Déclaration d'un flag pour savoir s'il y a au moins une ligne de cochée
$Flag_Suppr = 0;
// Pour chaque ligne du tableau
for ($n=0; $n<=$nb_aff; $n++)
{
// La commande "eval" permet ici de palier au fait de ne pas connaitre le nom des variables
$tmp_chk = $_POST['client_'.$n];
$tmpChk = eval($tmp_chk);
$tmp_hid = $_POST['hidden_'.$n];
eval($tmp_hid);
// Si la checkbox est cochée
if(isset($tmpChk))
{
if ($Flag_Suppr == 0)
{
$Flag_Suppr = 1;
}
$_SESSION['a :'.$n] = $tmp_hid;
}
}
if ($Flag_Suppr == 1)
{
header("Location: Suppression_Prospect.php?");<---------------------------------**
}
else
{
header("Location: Suppression_Erreur.php");
}
}
Malheureusement, maintenant il me dit que c'est tout le temps coché puisqu'il va toujours à l'instruction **...
if ($_POST['action'] == 'Suppression')
{
// Déclaration d'un flag pour savoir s'il y a au moins une ligne de cochée
$Flag_Suppr = 0;
// Pour chaque ligne du tableau
for ($n=0; $n<=$nb_aff; $n++)
{
// La commande "eval" permet ici de palier au fait de ne pas connaitre le nom des variables
$tmp_chk = $_POST['client_'.$n];
$tmpChk = eval($tmp_chk);
$tmp_hid = $_POST['hidden_'.$n];
eval($tmp_hid);
// Si la checkbox est cochée
if(isset($tmpChk))
{
if ($Flag_Suppr == 0)
{
$Flag_Suppr = 1;
}
$_SESSION['a :'.$n] = $tmp_hid;
}
}
if ($Flag_Suppr == 1)
{
header("Location: Suppression_Prospect.php?");<---------------------------------**
}
else
{
header("Location: Suppression_Erreur.php");
}
}
Malheureusement, maintenant il me dit que c'est tout le temps coché puisqu'il va toujours à l'instruction **...
drizzt_do_urden
Messages postés
40
Date d'inscription
mardi 9 octobre 2007
Statut
Membre
Dernière intervention
28 juillet 2015
4
6 juin 2008 à 10:41
6 juin 2008 à 10:41
if(isset(lavariale) && lavariable != '')
La variable est toujours défini, il faut regarder si elle est vide ou pas ;)
La variable est toujours défini, il faut regarder si elle est vide ou pas ;)
Fou riant
Messages postés
32
Date d'inscription
jeudi 5 juin 2008
Statut
Membre
Dernière intervention
10 novembre 2009
2
6 juin 2008 à 10:47
6 juin 2008 à 10:47
Merci, je viens de changer la condition, mais toujours rien à y faire, maintenant, il me dit toujours le contraire...soit aucune case cochée...
Fou riant
Messages postés
32
Date d'inscription
jeudi 5 juin 2008
Statut
Membre
Dernière intervention
10 novembre 2009
2
6 juin 2008 à 10:56
6 juin 2008 à 10:56
J'ai essayé de mattre l'autre partie de code que tu m'as proposé, ça donne ça :
// Pour chaque ligne du tableau
for ($n=0; $n<=$nb_aff; $n++)
{
// La commande "eval" permet ici de palier au fait de ne pas connaitre le nom des variables
$tmp_chk = $_POST['client_'.$n];
$tmpChk = eval($tmp_chk);
echo '|'.$tmpChk.'|';
// Si la checkbox est cochée
if(isset($tmpChk) && $tmpChk != '')
{
$tmp_hid = $_POST['hidden_'.$n];
$tmpHid = eval($tmp_hid);
if ($Flag_Suppr == 0)
{
$Flag_Suppr = 1;
}
$_SESSION['a :'.$n] = $tmpHid;
}
}
Mais maintenant il me réponds :
||||||||||||||||||||||
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Gestion_Prospect\Liste_Prospects.php:158) in C:\wamp\www\Gestion_Prospect\Liste_Prospects.php on line 177
// Pour chaque ligne du tableau
for ($n=0; $n<=$nb_aff; $n++)
{
// La commande "eval" permet ici de palier au fait de ne pas connaitre le nom des variables
$tmp_chk = $_POST['client_'.$n];
$tmpChk = eval($tmp_chk);
echo '|'.$tmpChk.'|';
// Si la checkbox est cochée
if(isset($tmpChk) && $tmpChk != '')
{
$tmp_hid = $_POST['hidden_'.$n];
$tmpHid = eval($tmp_hid);
if ($Flag_Suppr == 0)
{
$Flag_Suppr = 1;
}
$_SESSION['a :'.$n] = $tmpHid;
}
}
Mais maintenant il me réponds :
||||||||||||||||||||||
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Gestion_Prospect\Liste_Prospects.php:158) in C:\wamp\www\Gestion_Prospect\Liste_Prospects.php on line 177
Fou riant
Messages postés
32
Date d'inscription
jeudi 5 juin 2008
Statut
Membre
Dernière intervention
10 novembre 2009
2
6 juin 2008 à 14:47
6 juin 2008 à 14:47
Je crois que j'ai compris pourquoi je n'arrivais pas à avoir les cases cochées après avoir submit le choix de mon menu déroulant :
lorsque que je validais mon menu, une variable de choix se mettais à jour et donc je pense que le page se reloadais, qui a pour conséquence de désactiver les cases sélectionnées...Voilà pourquoi ça ne voulais pas marcher...
Je pense que je vais abandonner cette solution et trouver une autre manière de relooker la page afin de la rendre plus accessible (et aussi moins moche... faut dire ce qui est, les boutons 'submit' sont moches)
Merci de ton aide.
@+
lorsque que je validais mon menu, une variable de choix se mettais à jour et donc je pense que le page se reloadais, qui a pour conséquence de désactiver les cases sélectionnées...Voilà pourquoi ça ne voulais pas marcher...
Je pense que je vais abandonner cette solution et trouver une autre manière de relooker la page afin de la rendre plus accessible (et aussi moins moche... faut dire ce qui est, les boutons 'submit' sont moches)
Merci de ton aide.
@+