Radyo düğmesi veya seçilen açılan listesinde bağlı PHP form yönlendirmeyi nasıl değiştirilir?

1 Cevap php

The idea is to be able to perform some search query depending on radio button selected or drop-down choice. I know my PHP code is wrong, that's why I need your help ;-)

Benim test sayfası available here (click).

HTML kodu:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Engine Test</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="search_field" />
        <button type="submit">OK</button>
    </div>
    <div class="options">
        <label for="google">
        <input type="radio" name="search_choices_1" id="google" value="google" />Google:</label>
        <select name="google_lang_dropdown">
                <option id="google_english" value="google_english">Google English</option>
                <option id="google_spanish" value="google_spanish">Google Spanish</option>
                <option id="google_german" value="google_german">Google German</option>
                <option id="google_french" value="google_french">Google French</option>
        </select>
        <label for="bing"><input type="radio" name="search_choices_1" id="bing" value="bing" />Bing</label>
        <label for="wikipedia"><input type="radio" name="search_choices_1" id="wikipedia" value="wikipedia" />Wikipedia:</label>
        <select name="wikipedia_lang_dropdown">
                <option id="wikipedia_english" value="wikipedia_english">Wikipedia English</option>
                <option id="wikipedia_spanish" value="wikipedia_spanish">Wikipedia Spanish</option>
                <option id="wikipedia_german" value="wikipedia_german">Wikipedia German</option>
                <option id="wikipedia_french" value="wikipedia_french">Wikipedia French</option>
        </select>
        <br />
        <br />
    </div>
</form>
<form method="get" action="actions.php">
    <div class="input">
        <input type="text" size="80" name="media_field" />
        <button type="submit">OK</button>
    </div>
    <div class="options">
        <label for="audio"><input type="radio" name="search_choices_2" id="audio" value="audio" />Audio:</label>
        <select name="audio_choice_dropdown">
                <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="search_choices_2" id="google_images" value="google_images" />Google Images</label>
        <label for="video"><input type="radio" name="search_choices_2" id="video" value="video" />Video:</label>
        <select name="video_choice_dropdown">
                <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>

PHP kodu:

<?php
if (!empty($_REQUEST['search_field']))
{
    $url = array(
        'google_english'=>'http://www.google.com/#hl=en&q=__keywords__',
        'google_spanish'=>'http://www.google.com/#hl=es&q=__keywords__',
        'google_german'=>'http://www.google.com/#hl=de&q=__keywords__',
    	'google_french'=>'http://www.google.com/#hl=fr&q=__keywords__',
    	'bing'=>'http://www.bing.com/search?q=__keywords__',
        'wikipedia_english'=>'http://en.wikipedia.org/wiki/Special:Search?search=__keywords__',
        'wikipedia_spanish'=>'http://es.wikipedia.org/wiki/Special:Search?search=__keywords__',
        'wikipedia_german'=>'http://de.wikipedia.org/wiki/Special:Search?search=__keywords__',
    	'wikipedia_french'=>'http://fr.wikipedia.org/wiki/Special:Search?search=__keywords__');
    header('Location:'.str_replace('__keywords__',preg_replace('/(\ )+/', '+', trim($_REQUEST['search_field'])),$url[trim($_REQUEST['search_choices_1'])]));
    die();
}
else if (!empty($_REQUEST['media_field']))
{
    $url = array(
    	'deezer'=>'http://www.deezer.com/music/result/all/__keywords__',
        'jiwa'=>'http://www.jiwa.fm/#search/track/{%22q%22%3A%22__keywords__%22}',
        'last.fm'=>'http://www.last.fm/music?q=__keywords__',
    	'google_images'=>'http://images.google.com/images?&q=__keywords__',
        'youtube'=>'http://www.youtube.com/results?search_query=__keywords__',
    	'dailymotion'=>'http://www.dailymotion.com/relevance/search/__keywords__',
    	'google_video'=>'http://images.google.com/images?q=__keywords__');
    header('Location:'.str_replace('__keywords__',preg_replace('/(\ )+/', '+', trim($_REQUEST['media_field'])),$url[trim($_REQUEST['search_choices_2'])]));
    die();
}

else
{
     // No search query; redirect to search page
    header('Location:index.html');
    die();
}
?>

Radyo düğmeleri ile benim eski sürümü sadece gibi olabilir test here (click) çalışıyor.

-S: Ama ben açılır liste ile bunu nasıl anlamaya olamaz

Cevaplar için teşekkürler.

Not: W3C XHTML olmalı Sıkı uyumlu ve working when JavaScript is disabled (bu radyo düğmesini tek sürümü için önceden olduğu gibi).

1 Cevap

Sen metin girişi, radyo grubu için aynı ad özniteliği ve seçme-seçenek grubu kullanamazsınız.

Farklı isimler ile aralarına ve sonra her durumda işlemek için birden conditionals kullanmayı deneyin.

Örnek:

switch ($_REQUEST['radio_group']) 
{
    case 'google':
        ... look for $_REQUEST['google_lang_dropdown'] ... 
    break;
    case 'bing':
        .. do something..
    break;
    case 'wikipedia':
        ... look for $_REQUEST['wikipedia_lang_dropdown'] ... 
    break;

}