Results 1 to 6 of 6

Thread: [RESOLVED] Dropdown Box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    70

    Resolved [RESOLVED] Dropdown Box

    I plan on making a dropdown box with all the most popular search engines, so that visitors may enter the search term in a text box, and then choose the desired search engine from the dropdown box.

    The problem is that depending on which search-engine that is being chosen, the action-attribute will be different.
    e.g.: action="http://www.google.com/custom" || action="http://en.wikipedia.org/wiki/Special:Search"

    I really would appreciate a hint here if someone knows a way to do this!
    Last edited by Mutuz; Jul 31st, 2006 at 04:35 AM.

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Dropdown Box

    Make your own PHP script which will do the final formatting and redirection to the proper url, because the input fields also vary depending on the search engine. For the least, I wouldn't rely on JavaScript to change the field attributes depending on the selected search engine; I for one use NoScript extension by default, thus it would be frustrating if the search didn't work. With a PHP script there will be no problems.

    Also, be careful with character code pages and encodings! Wikipedia takes UTF-8, Google can take UTF-8 or ISO-8859-1... so if your page's content encoding isn't UTF-8, you need to use utf8encode() in the PHP script (and even then it might not work 100% correctly). Although I highly recommend using UTF-8 as the default page encoding, less problems with non-English characters overall.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    70

    Re: Dropdown Box

    Thanks for your reply Merri! I was actually thinking about using Javascript to do the redirect, so thanks for the wake-up call! Wasn't thinking about all of you with No Script extension.

    Also, I wasn't aware of the different encodings among the search engines. That may be a challenge! I'll update you on the process as I get to work on the script, and (surely) run into problems!

    Edit: First encounter already! Any tips on the redirecting in the script?! The problem here, is that if I use:
    PHP Code:
    header("location: [some-url]"); 
    .. then this is done with the header, meaning before the code is being processed. This way, I'll never get to evaluate which engine the user selected, and might as well pick one for him/her.
    Last edited by Mutuz; Jul 31st, 2006 at 04:08 AM.

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Dropdown Box

    PHP Code:
    <?php

    /* process the $_GET or $_POST variables; for example: */
    /* note that I can't remember the exact correct syntax, but you'll get the idea */

    $search_engine $_GET['engine']; // could be a select element
    $search_keyword $_GET['keyword'];

    switch (
    $search_engine) {
        case 
    'google':
            
    $url ''// fill the whole url according Google format
            
    break;
        case 
    'wikipedia':
            
    $url ''// fill the whole url according Wikipedia format
            
    break;
        default:
    }

    header('location: ' $url);
    ?>
    You don't need anything else on the PHP page, the actual page can be blank. It only makes sure the user gets redirected elsewhere

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    70

    Re: Dropdown Box

    Hmm, if this is the case, I must have missed something.. Haven't the headers already been sent out when the script is processed?!

    I'll try it out, thanks!

    Edit: It worked! Thanks a lot Merri, saved me a lot of problem here!
    Last edited by Mutuz; Jul 31st, 2006 at 04:34 AM. Reason: Problem Solved!

  6. #6
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: [RESOLVED] Dropdown Box

    Headers get sent before PHP script runs if there is something before the PHP script starts running, ie. " <?php ... ?>" (without the quotes) prepares and sends the headers, because there is a space character, sendable page content, before the script. If you start with a script right away, then nothing gets sent and you can do to headers whatever you wish. But if you do echo, then you'll again send headers and you can't change headers anymore, because you've sent page content.

    So long story short, you can change and add headers as long as you don't send any data to the client.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width