# question about select tag in php



## sudhakararaog (Sep 6, 2007)

i have two select tags as part of a registration form, city1 city2 where city1 has a list of regions and similar for city2

there are different regions for city1 and city2 so instead of all the regions appearing one after the other i would like to create a blank option followed by the next set of regions for formatting purpose only.

ex=

value="region1">Select region1
value="nameofregion1">nameofregion1
value="0">
value="nameofregion2">nameofregion2
value="1">

value="region2">Select region2
value="nameofregion1">nameofregion1
value="2">
value="nameofregion2">nameofregion2
value="3">

from a php validation perspective if a user does not select any of the regions or both the regions i am displaying an error message asking them to either select 1 region from either city1 or city2

as of now there is a blank option being displayed which is working fine, i am having an issue with the php validation.

until i introduced value=0 my rules for validating the select tag were:

1. user cannot leave both the select tags with the default option which is "Select region1" & "Select region2"
2. user cannot select both the regions from city1 & city2 select tags

the code of 2. is 
if(!($city1 == "region1") && !($city2 == "region2")) 
{
$error.="Please select only 1 Region
";
}

now by introducing value="0"> there is a conflict with the above php validation code used in point 2.

1. 
is it correct to use 1,2,3 as part of the following tag or should i only use 0 everywhere
value="0">
value="1">

2.
how can i get around the conflict that is being created by introducing this value=0 with 
if(!($city1 == "region1") && !($city2 == "region2")) 
{
$error.="Please select only 1 Region
";
}
as i need the above php code and i also need the blank space for formatting purpose

please advice.

thanks.


----------



## awatson (Jan 29, 2008)

I'm not sure I entirely followed, but I think you may want to use "empty()" to check required fields, rather than looking for a numeric 0.


----------



## TheRobatron (Oct 25, 2007)

Are the $northisland options for formatting purposes? Because if they, I would do as awatson said and just put value="" - you can have the same value for more than one option. Then you can put if (!empty($variable)) { /*The input is valid*/ }.

I got a bit confused but I hope that helps.


----------

