Précédent   Forum des professionnels en informatique > PHP > Langage > Syntaxe
Syntaxe Forum d'entraide sur la syntaxe de PHP et la POO. Avant de poster -> FAQ syntaxe, Cours d'initiation et cours de POO
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 07/04/2008, 21h02   #1
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
Par défaut [PHP-JS] Ouverture d'un fichier dont le nom est dynamique

Bonjour a vous,
Je recherche la syntaxe pour ouvrir un fichier de cette façon :
le visiteur a fait des choix qui sont stocker dans des variables.
Je voudrais qu'il ouvre le fichier "choix1"_"choix2"_"Choix3.php comment faire pour concaténer ces 3 élémetns ?
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/04/2008, 21h42   #2
Modératrice
 
Avatar de Celira
 
Femme
Développeuse PHP/Java
Inscription : avril 2007
Messages : 3 686
Détails du profil
Informations personnelles :
Sexe : Femme
Âge : 27
Localisation : France

Informations professionnelles :
Activité : Développeuse PHP/Java

Informations forums :
Inscription : avril 2007
Messages : 3 686
Points : 5 453
Points : 5 453
Une bête concaténation pour obtenir le nom du fichier ?
Code :
$nom_du_fichier = $choix1.'_'.$choix2.'_'.$choix3.'.php';
__________________
Modératrice PHP
Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)

Pour afficher votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur)
Celira est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/04/2008, 22h01   #3
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
j'essaye de faire ce petit bout de code mais il ne m'affiche pas la page :-(
Code html :
1
2
3
4
5
6
7
8
<form name="form" action="$choix1.'_'.$choix2.'_'.$choix3.'.php'" method="post">
<p align="center">Nom  : <input type="text" name="nom"></p>
<p align="center">Prenom: <input type="text" name="mod"></p>
<p align="center">Option 1 : <input type="text" name="op1"></p>
<p align="center">Option 2 : <input type="text" name="op2"></p>
<p align="center">Option 3 : <input type="text" name="op3"></p>
<p align="center">Option 4 : <input type="text" name="op4"></p>
<p align="center">
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/04/2008, 22h30   #4
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
Je dois etre tout pres de la solution, le visiteur choisit dans la premiere liste un élément, une liste correspondante a son choix est afficher dans la 2eme liste. Puis une 3eme liste indépendante des deux autres ou le visiteur effectue un choix.
Quand ce choix est effectuer, sans qu'il click, la page suivante s'ouvre ( choix1_choix2_choix3.php
Voici mon script :
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
69
70
71
72
73
74
75
76
77
78
79
<script type="text/javascript">
<!--
function choix(boite)
{
var j, n;
var i = boite.selectedIndex;
var boite2 = document.getElementById("boite2");
var tab = null, liens = null;
 
n = boite2.options.length;
for(j = 1; j <n; j++)
    boite2.remove(1);
 
 
if (i == 0)
{
    return;
}
else
{
 
    switch (i)
    {
        case 1 : tab = new Array("n1","n2","n3","n4","n5");
                break;
        case 2 : tab = new Array("s1","s2","s3");
               break;
        case 3 : tab = new Array("so1","so2","so3","so4","so5","so6");
                break;
        case 4 : tab = new Array("L1");
                break;
        case 5 : tab = new Array("sag1","sag2");
                break;
    }
 
    for(j = 0; j<tab.length; j++)
        boite2.options.add(new Option(tab[j], false, false));
}
 
    boite2.selectedIndex=0;
}
function ouvrepage(boite)
{
    if (boite.selectedIndex!=0)
    {
        document.location.href = boite.value;
    }
 
} 
 
//-->
</script>
</head>
 
<body>
<form id="formulaire">
 
<select id="boite1" onchange="choix(this)">
  <option selected="selected">...........Choisissez ...........</option>
  <option>Test1</option>
  <option>Test2</option>
  <option>Test3</option>
  <option>Test4</option>
  <option>Test5</option>
</select>
 
<select id="boite2">
  <option selected="selected">...........Choisissez ...........</option>
</select>
 
<select id="boite3" onchange="ouvrepage(this)">
  <option selected="selected">...........Choisissez ...........</option>
  <option>3emeChoix1</option>
  <option>3emechoix2</option>
  <option>3emechoix3</option>
</select>
 
 
</form>
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/04/2008, 09h43   #5
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
Je suis en crise la
La passage de la liste 1 a 2 est ok, la 3eme liste indépendante des deux autres s'affiche niquel, par contre quand le visiteur a fait son 3eme choix, le prog doit concatener les 3 choix effectuer pour ouvrir la page suivante "choix1""choix2"choix3".php , mais cette syntaxe ne fonctionne pas ,une piste ?
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/04/2008, 03h37   #6
Nouveau Membre du Club
 
Inscription : avril 2004
Messages : 56
Détails du profil
Informations forums :
Inscription : avril 2004
Messages : 56
Points : 31
Points : 31
yuyu599 il faut récupérer les valeurs et les concaténer

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
69
70
71
72
73
74
75
76
<html>
<head>
<script type="text/javascript">
<!--
function choix(boite){
	var j, n;
	var i = boite.selectedIndex;
	var boite2 = document.getElementById("boite2");
	var tab = null, liens = null;
 
	n = boite2.options.length;
	for(j = 1; j <n; j++){
	    boite2.remove(1);
	}
 
	if (i == 0){
	    return;
	}else{
	    switch (i){
	        case 1 : tab = new Array("n1","n2","n3","n4","n5");
	                break;
	        case 2 : tab = new Array("s1","s2","s3");
	               break;
	        case 3 : tab = new Array("so1","so2","so3","so4","so5","so6");
	                break;
	        case 4 : tab = new Array("L1");
	                break;
	        case 5 : tab = new Array("sag1","sag2");
	                break;
	    }
 
	    for(j = 0; j<tab.length; j++)
	        boite2.options.add(new Option(tab[j], false, false));
		}
 
	    boite2.selectedIndex=0;
	}
 
	function ouvrepage(boite){
   		if (boite.selectedIndex!=0){
        	document.location.href = boite1.value + "_" + boite2.options[boite2.selectedIndex].text + "_" + boite.value + ".html";
    	}
 
} 
 
//-->
</script>
</head>
 
<body>
<form id="formulaire">
 
<select id="boite1" onchange="choix(this)">
  <option selected="selected">...........Choisissez ...........</option>
  <option>Test1</option>
  <option>Test2</option>
  <option>Test3</option>
  <option>Test4</option>
  <option>Test5</option>
</select>
 
<select id="boite2">
  <option selected="selected">...........Choisissez ...........</option>
</select>
 
<select id="boite3" onchange="ouvrepage(this)">
  <option selected="selected">...........Choisissez ...........</option>
  <option>3emeChoix1</option>
  <option>3emechoix2</option>
  <option>3emechoix3</option>
</select>
 
 
</form>
</body>
</html>
Spaccio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/04/2008, 08h00   #7
Membre Expert
 
Avatar de Jumano
 
Inscription : février 2007
Messages : 1 162
Détails du profil
Informations personnelles :
Âge : 43
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : février 2007
Messages : 1 162
Points : 1 369
Points : 1 369
Bonjour,
Juste une petite précision à propos du code fournit par Spaccio :

Si tu veux récupérer les "values" de tes "selects" alors il faut ajouter dans tes <option> une "value" :
Code :
1
2
 
<option value="Test1">Test1</option>
A ce moment là tu récupères ta valeur de ta "boite1" par exemple avec :
Code :
1
2
 
document.getElementById('boite1').options[document.getElementById('boite1').selectedIndex].value
Si tu n'as pas de "value" dans tes <options>, tu récupères le "text" de ton "select" avec :
Code :
1
2
 
document.getElementById('boite1').options[document.getElementById('boite1').selectedIndex].text
Ce qui te donne comme code (sans "value" dans tes <options>) :
Code :
1
2
3
4
5
6
7
8
 
function ouvrepage(boite)
{
    if (boite.selectedIndex!=0)
    {
      document.location.href = document.getElementById('boite1').options[document.getElementById('boite1').selectedIndex].text +"_"+ document.getElementById('boite2').options[document.getElementById('boite2').selectedIndex].text +"_"+ document.getElementById('boite3').options[document.getElementById('boite3').selectedIndex].text +".php";
    }
}
Un petit tour dans la FAQ Javascript
Jumano est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/04/2008, 14h24   #8
Nouveau Membre du Club
 
Inscription : avril 2004
Messages : 56
Détails du profil
Informations forums :
Inscription : avril 2004
Messages : 56
Points : 31
Points : 31
Je m'incline, maintenant le code est super propre. J'avoue avoir répondu un peu vite
Spaccio 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 19h26.


 
 
 
 
Partenaires

Hébergement Web