Results 1 to 6 of 6

Thread: Validating Drop Down Menu

  1. #1
    Join Date
    May 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Validating Drop Down Menu

    Hey

    How would you validate a drop down menu using PHP. I know how to do it with Javascript

    Cheers

    Tom Evans
    Last edited by gold2040; 05-30-2006 at 01:30 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Assuming your dropdown is named "dropdown" and the form's method is "post"...

    PHP Code:
    <?php
    if ($_POST['dropdown'] == "value1") {
       
    //do stuff like:
       
    echo "it works!";
       }
    else {
       
    //do something else like:
       
    echo "error";
       }
    ?>
    But... what do you want, specifically?

    Lots can be done to verify....

    At least that's a basic example.

    php.net has lot of info about various php things if you want to learn... look up "form handling"...
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey

    Cheers for that. I mean like you just have to select 1 option out the dropdown menu

    Tom Evans

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Well... hate to point out the obvious... but it's worthless to have a dropdown menu "choice" if one is required... it's like an election with one candidate

    Anyway... the above will do what you want.

    Just for the "do stuff" make it continue in your script, and for else use, maybe, die("error. please try again.");

    die() stops the page from loading at that point and outputs the string in the parentheses. You can use html in there too, like a JS-based back link.


    that's the basics... not sure what funtionality you want if it's right or if it's wrong.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    it's like an election with one candidate
    Totally pointless, but makes people think they have some choice in the matter?

    We've had those for decades.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    quite true.

    also, I'm guessing this might be related to "do you accept these terms: yes/no", in which case it's totally valid.

    still worth pointing out, though
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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