par
Jabe » 20 sept. 2009, 16:03
Bonjour,
Je cherche à rediriger une recherche en fonction du bouton radio sélectionné ou du choix d'une liste déroulante.
J'ai mis une page de test en ligne
ici.
Mon code HTML est le suivant:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test moteur de recherche</title>
<style type="text/css">
.page {
text-align: center;
}
</style>
</head>
<body class="page">
<form method="get" action="actions.php">
<div class="input">
<input type="text" size="80" name="champ_de_recherche" />
<button type="submit">OK</button>
</div>
<div class="options">
<label for="google">
<input type="radio" name="choix_de_recherche_1" id="google" value="google" />Google:</label>
<select name="liste_de_choix_google">
<option id="google_francais" value="google_francais">Google Français</option>
<option id="google_anglais" value="google_anglais">Google Anglais</option>
<option id="google_espagnol" value="google_espagnol">Google Espagnol</option>
<option id="google_allemand" value="google_allemand">Google Allemand</option>
</select>
<label for="bing"><input type="radio" name="choix_de_recherche_1" id="bing" value="bing" />Bing</label>
<label for="wikipedia"><input type="radio" name="choix_de_recherche_1" id="wikipedia" value="wikipedia" />Wikipédia:</label>
<select name="choix_de_recherche_wikipedia">
<option id="wikipedia_francais" value="wikipedia_francais">Wikipédia Français</option>
<option id="wikipedia_anglais" value="wikipedia_anglais">Wikipédia Anglais</option>
<option id="wikipedia_espagnol" value="wikipedia_espagnol">Wikipédia Espagnol</option>
<option id="wikipedia_allemand" value="wikipedia_allemand">Wikipédia Allemand</option>
</select>
<br />
<br />
</div>
</form>
<form method="get" action="actions.php">
<div class="input">
<input type="text" size="80" name="champ_media" />
<button type="submit">OK</button>
</div>
<div class="options">
<label for="audio"><input type="radio" name="choix_de_recherche_2" id="audio" value="audio" />Audio:</label>
<select name="liste_de_choix_audio">
<option id="deezer" value="deezer">Deezer</option>
<option id="jiwa" value="jiwa">Jiwa</option>
<option id="last.fm" value="last.fm">Last.fm</option>
</select>
<label for="google_images"><input type="radio" name="choix_de_recherche_2" id="google_images" value="google_images" />Google Images</label>
<label for="video"><input type="radio" name="choix_de_recherche_2" id="video" value="video" />Video:</label>
<select name="liste_de_choix_video">
<option id="youtube" value="youtube">Youtube</option>
<option id="dailymotion" value="dailymotion">Dailymotion</option>
<option id="google_video" value="google_video">Google Video</option>
</select>
</div>
</form>
</body>
</html>
Mon code PHP (qui je sais est faux !) est:
<?php
if (!empty($_REQUEST['champ_de_recherche']))
{
$url = array(
'google_anglais'=>'http://www.google.com/#hl=en&q=__motscles__',
'google_espagnol'=>'http://www.google.com/#hl=es&q=__motscles__',
'google_allemand'=>'http://www.google.com/#hl=de&q=__motscles__',
'google_francais'=>'http://www.google.com/#hl=fr&q=__motscles__',
'bing'=>'http://www.bing.com/search?q=__motscles__',
'wikipedia_anglais'=>'http://en.wikipedia.org/wiki/Special:Search?search=__motscles__',
'wikipedia_espagnol'=>'http://es.wikipedia.org/wiki/Special:Search?search=__motscles__',
'wikipedia_allemand'=>'http://de.wikipedia.org/wiki/Special:Search?search=__motscles__',
'wikipedia_francais'=>'http://fr.wikipedia.org/wiki/Special:Search?search=__motscles__');
header('Location:'.str_replace('__motscles__',preg_replace('/(\ )+/', '+', trim($_REQUEST['champ_de_recherche'])),$url[trim($_REQUEST['choix_de_recherche_1'])]));
die();
}
else if (!empty($_REQUEST['champ_media']))
{
$url = array(
'deezer'=>'http://www.deezer.com/music/result/all/__motscles__',
'jiwa'=>'http://www.jiwa.fm/#search/track/{%22q%22%3A%22__motscles__%22}',
'last.fm'=>'http://www.last.fm/music?q=__motscles__',
'google_images'=>'http://images.google.com/images?&q=__motscles__',
'youtube'=>'http://www.youtube.com/results?search_query=__motscles__',
'dailymotion'=>'http://www.dailymotion.com/relevance/search/__motscles__',
'google_video'=>'http://images.google.com/images?q=__motscles__');
header('Location:'.str_replace('__motscles__',preg_replace('/(\ )+/', '+', trim($_REQUEST['champ_media'])),$url[trim($_REQUEST['choix_de_recherche_2'])]));
die();
}
else
{
// S'il n'y a pas de termes de recherche cela redirige vers la page de recherche
header('Location:index.html');
die();
}
?>
La version plus ancienne de mon code qui fonctionne correctement mais avec des boutons radios uniquement est disponible en test
ici.
Je n'arrive pas à le faire avec la liste déroulante, si quelqu'un pouvait m'arranger mon code qu'il fonctionne ce serait génial.
Merci d'avance pour votre aide.
Bonjour,
Je cherche à rediriger une recherche en fonction du bouton radio sélectionné ou du choix d'une liste déroulante.
J'ai mis une page de test en ligne [url=http://lostsymphonia.free.fr/r/fr/2/index.html]ici.[/url]
Mon code HTML est le suivant:
[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test moteur de recherche</title>
<style type="text/css">
.page {
text-align: center;
}
</style>
</head>
<body class="page">
<form method="get" action="actions.php">
<div class="input">
<input type="text" size="80" name="champ_de_recherche" />
<button type="submit">OK</button>
</div>
<div class="options">
<label for="google">
<input type="radio" name="choix_de_recherche_1" id="google" value="google" />Google:</label>
<select name="liste_de_choix_google">
<option id="google_francais" value="google_francais">Google Français</option>
<option id="google_anglais" value="google_anglais">Google Anglais</option>
<option id="google_espagnol" value="google_espagnol">Google Espagnol</option>
<option id="google_allemand" value="google_allemand">Google Allemand</option>
</select>
<label for="bing"><input type="radio" name="choix_de_recherche_1" id="bing" value="bing" />Bing</label>
<label for="wikipedia"><input type="radio" name="choix_de_recherche_1" id="wikipedia" value="wikipedia" />Wikipédia:</label>
<select name="choix_de_recherche_wikipedia">
<option id="wikipedia_francais" value="wikipedia_francais">Wikipédia Français</option>
<option id="wikipedia_anglais" value="wikipedia_anglais">Wikipédia Anglais</option>
<option id="wikipedia_espagnol" value="wikipedia_espagnol">Wikipédia Espagnol</option>
<option id="wikipedia_allemand" value="wikipedia_allemand">Wikipédia Allemand</option>
</select>
<br />
<br />
</div>
</form>
<form method="get" action="actions.php">
<div class="input">
<input type="text" size="80" name="champ_media" />
<button type="submit">OK</button>
</div>
<div class="options">
<label for="audio"><input type="radio" name="choix_de_recherche_2" id="audio" value="audio" />Audio:</label>
<select name="liste_de_choix_audio">
<option id="deezer" value="deezer">Deezer</option>
<option id="jiwa" value="jiwa">Jiwa</option>
<option id="last.fm" value="last.fm">Last.fm</option>
</select>
<label for="google_images"><input type="radio" name="choix_de_recherche_2" id="google_images" value="google_images" />Google Images</label>
<label for="video"><input type="radio" name="choix_de_recherche_2" id="video" value="video" />Video:</label>
<select name="liste_de_choix_video">
<option id="youtube" value="youtube">Youtube</option>
<option id="dailymotion" value="dailymotion">Dailymotion</option>
<option id="google_video" value="google_video">Google Video</option>
</select>
</div>
</form>
</body>
</html>
[/html]
Mon code PHP (qui je sais est faux !) est:
[php]
<?php
if (!empty($_REQUEST['champ_de_recherche']))
{
$url = array(
'google_anglais'=>'http://www.google.com/#hl=en&q=__motscles__',
'google_espagnol'=>'http://www.google.com/#hl=es&q=__motscles__',
'google_allemand'=>'http://www.google.com/#hl=de&q=__motscles__',
'google_francais'=>'http://www.google.com/#hl=fr&q=__motscles__',
'bing'=>'http://www.bing.com/search?q=__motscles__',
'wikipedia_anglais'=>'http://en.wikipedia.org/wiki/Special:Search?search=__motscles__',
'wikipedia_espagnol'=>'http://es.wikipedia.org/wiki/Special:Search?search=__motscles__',
'wikipedia_allemand'=>'http://de.wikipedia.org/wiki/Special:Search?search=__motscles__',
'wikipedia_francais'=>'http://fr.wikipedia.org/wiki/Special:Search?search=__motscles__');
header('Location:'.str_replace('__motscles__',preg_replace('/(\ )+/', '+', trim($_REQUEST['champ_de_recherche'])),$url[trim($_REQUEST['choix_de_recherche_1'])]));
die();
}
else if (!empty($_REQUEST['champ_media']))
{
$url = array(
'deezer'=>'http://www.deezer.com/music/result/all/__motscles__',
'jiwa'=>'http://www.jiwa.fm/#search/track/{%22q%22%3A%22__motscles__%22}',
'last.fm'=>'http://www.last.fm/music?q=__motscles__',
'google_images'=>'http://images.google.com/images?&q=__motscles__',
'youtube'=>'http://www.youtube.com/results?search_query=__motscles__',
'dailymotion'=>'http://www.dailymotion.com/relevance/search/__motscles__',
'google_video'=>'http://images.google.com/images?q=__motscles__');
header('Location:'.str_replace('__motscles__',preg_replace('/(\ )+/', '+', trim($_REQUEST['champ_media'])),$url[trim($_REQUEST['choix_de_recherche_2'])]));
die();
}
else
{
// S'il n'y a pas de termes de recherche cela redirige vers la page de recherche
header('Location:index.html');
die();
}
?>
[/php]
La version plus ancienne de mon code qui fonctionne correctement mais avec des boutons radios uniquement est disponible en test [url=http://lostsymphonia.free.fr/r/index.html]ici[/url].
Je n'arrive pas à le faire avec la liste déroulante, si quelqu'un pouvait m'arranger mon code qu'il fonctionne ce serait génial.
Merci d'avance pour votre aide.