View Full Version : Validating Drop Down Menu
gold2040
05-30-2006, 01:18 PM
Hey
How would you validate a drop down menu using PHP. I know how to do it with Javascript
Cheers
Tom Evans
djr33
05-30-2006, 01:42 PM
Assuming your dropdown is named "dropdown" and the form's method is "post"...
<?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"...
gold2040
05-30-2006, 01:44 PM
Hey
Cheers for that. I mean like you just have to select 1 option out the dropdown menu
Tom Evans
djr33
05-30-2006, 01:48 PM
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 :p
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.
it's like an election with one candidateTotally pointless, but makes people think they have some choice in the matter?
We've had those for decades. :)
djr33
05-30-2006, 02:06 PM
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 :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.