Thread: Form Validation
View Single Post
Old Feb 27th, 2006, 5:56 PM   #5
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
What I would do is create a has out of the country names and generate a dropdown menu based on that.

For example, say we have a small hash

$countries array(0 => "United States", 1 => "United Kingdom", 2 => "Algeria")

then make a foreach loop to do the select box, with the number being the value and the country what it displays. So like
<option value="0">United States</option> except the loop will generate it from the hash.

So then, it sets the post variable to the form action script, so you'll get a 1, a 2, or a 3. You can validate it by saying
$country = $_POST[country]
$country = $countries[$country]

That way not only will it validate for text, but it will validate to make sure that it's a real country from a list that you have pre-defined. You can also easily do this with a SQL database instead of a hash.
__________________
--John Cruz
Web Developer
www.cruzweb.net
Lich is offline   Reply With Quote