Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > Templates > Smarty
Smarty Forum d'entraide sur le moteur de templates Smarty. Avant de poster -> FAQ Smarty et Cours Smarty
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 16/04/2008, 11h02   #1
Membre régulier
 
Inscription : juillet 2007
Messages : 171
Détails du profil
Informations personnelles :
Âge : 30
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : juillet 2007
Messages : 171
Points : 85
Points : 85
Par défaut Récupération de checkbox

Hi all,

Décidement, je suis le seul à avoir des problèmes sous Smarty apparement

Donc, mon problème maintenant est de cocher des checkboxes à l'affichage de ma page.
En clair, j'ai un formulaire qui liste sous forme de checkboxes un certain nombre de logiciels installés sur un ordinateur. A l'ajout du formulaire, je n'ai pas de soucis, je recupère les id que je stocke dans une table.

Mon problème survient lorsque je souhaite modifier ces données. J'aimerai qu'à l'affichage de la page, mes checkboxes donc l'id est dans la base soit cochées...

Voici mes codes :

Fichier tpl :
Code :
1
2
Liste des logiciels : 
{html_checkboxes name=logicielChecked values=$checkboxLogicielIndex output=$checkboxLogicielNom labels=true separator="<br />" selected=logicielChecked.idLogiciel}
Fichier php :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
//Recuperation des logiciels installes
	$params = array("table" => "compose", "champs" => "idLogiciel");
 
	$condition = array();
	$condition[] = new proprieteClass("idMachine", "=", $idServeur, VARIABLE);
 
	//Envoi de la requete
	$tableAff2 = new tableClass();
	$resultatLog = $tableAff2->getTable($params, $condition,1);
	echo "test : ".$resultatLog[1][idLogiciel];
	//Assignation des valeurs
	$smarty->assign("logicielChecked", $resultatLog);	
}
J'ai essayé pas mal de trucs différents, c'est pourquoi mon code actuel ne doit pas être très cohérent...
arnogb69 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/04/2008, 07h19   #2
Membre Expert
 
Avatar de eric.pommereau
 
Homme ERIC POMMEREAU
Ingénieur intégration
Inscription : décembre 2004
Messages : 683
Détails du profil
Informations personnelles :
Nom : Homme ERIC POMMEREAU
Âge : 38
Localisation : France

Informations professionnelles :
Activité : Ingénieur intégration
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : décembre 2004
Messages : 683
Points : 1 294
Points : 1 294
Bonjour,

Je ne vois pas trop comme ça ...

Peux tu faire un debug smarty dans ton html ({debug}) et poster le résultat ?

@+
eric.pommereau est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/04/2008, 09h41   #3
Membre régulier
 
Inscription : juillet 2007
Messages : 171
Détails du profil
Informations personnelles :
Âge : 30
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : juillet 2007
Messages : 171
Points : 85
Points : 85
Je crois que tu as pointé le doigt sur quelque chose eric...

Voici mon debug :
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
{$checkboxLogicielIndex}  	Array (9)
1 => "6"
2 => "1"
3 => "3"
4 => "5"
5 => "4"
6 => "10"
7 => "7"
8 => "9"
9 => "8"
{$checkboxLogicielNom} 	Array (9)
1 => "Adobe Photoshop"
2 => "Logiciel 1"
3 => "Logiciel 3"
4 => "Logiciel Ordi"
5 => "Logiciel Serveur"
6 => "Mac OS X"
7 => "Macromedia DreamWeaver"
8 => "Windows Vista"
9 => "Windows XP Pro"
{$logicielChecked}  	Array (3)
1 => Array (2)
  0 => "3"
  idLogiciel => "3"
2 => Array (2)
  0 => "1"
  idLogiciel => "1"
3 => Array (2)
  0 => "6"
  idLogiciel => "6"

Sinon, voici le code source généré aussi :
Code :
1
2
3
4
5
6
7
8
9
10
<label><input type="checkbox" name="logicielChecked[]" value="6" />Adobe Photoshop</label><br />
<label><input type="checkbox" name="logicielChecked[]" value="1" />Logiciel 1</label><br />
<label><input type="checkbox" name="logicielChecked[]" value="3" />Logiciel 3</label><br />
<label><input type="checkbox" name="logicielChecked[]" value="5" />Logiciel Ordi</label><br />
 
<label><input type="checkbox" name="logicielChecked[]" value="4" />Logiciel Serveur</label><br />
<label><input type="checkbox" name="logicielChecked[]" value="10" />Mac OS X</label><br />
<label><input type="checkbox" name="logicielChecked[]" value="7" />Macromedia DreamWeaver</label><br />
<label><input type="checkbox" name="logicielChecked[]" value="9" />Windows Vista</label><br />
<label><input type="checkbox" name="logicielChecked[]" value="8" />Windows XP Pro</label><br />
arnogb69 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/04/2008, 17h22   #4
Membre régulier
 
Inscription : juillet 2007
Messages : 171
Détails du profil
Informations personnelles :
Âge : 30
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : juillet 2007
Messages : 171
Points : 85
Points : 85
Waouh, enfin, vendredi soir, 17h15

Le problème venait du fait que je lui passais un tableau associatif, alors que Smarty attendait un tableau simple.
Ajouté à cela une faute de syntaxe corrigée, et le problème est résolu. Donc voici le code final et correct

Dans mon template (j'avais oublié le $ avant "logicielChecked", grrrr):
Code :
{html_checkboxes name=logicielChecked values=$checkboxLogicielIndex output=$checkboxLogicielNom labels=true separator="<br />" selected=$logicielChecked}
Et mon code php :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
//Envoi de la requete
		$tableAff2 = new tableClass();
		$resultat = $tableAff2->getTable($params, $condition);
 
		//récuperation des logiciels coches
		$resultatLog = array();
		for($i=0 ; $i < $tableAff2->nb_items ; $i++){
			array_push($resultatLog, $resultat[$i][idLogiciel]);
		}
 
		//Assignation des valeurs
		$smarty->assign("logicielChecked", $resultatLog);
Voilà, si ça peut en aider d'autres
arnogb69 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 15h30.


 
 
 
 
Partenaires

Hébergement Web