Go Back   Dynamic Drive Forums > General Coding > PHP
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 05-30-2006, 02:18 PM
gold2040 gold2040 is offline
Junior Coders
 
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 02:30 PM.
Reply With Quote
  #2  
Old 05-30-2006, 02:42 PM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 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 - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #3  
Old 05-30-2006, 02:44 PM
gold2040 gold2040 is offline
Junior Coders
 
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
Reply With Quote
  #4  
Old 05-30-2006, 02:48 PM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 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 - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
  #5  
Old 05-30-2006, 03:05 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

Quote:
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!
Reply With Quote
  #6  
Old 05-30-2006, 03:06 PM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 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 - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:46 PM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.