question about select tag in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • runway27
    Banned
    New Member
    • Sep 2007
    • 54

    question about select tag in php

    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= [php]
    <select name="city1">
    <option <?php if ($city1=="regio n1"){echo "SELECTED"; }?> value="region1" >Select region1</option>
    <option <?php if ($city1=="nameo fregion1"){echo "SELECTED"; }?> value="nameofre gion1">nameofre gion1</option>
    <option <?php if ($northisland== "0"){echo "SELECTED"; }?> value="0"></option>
    <option <?php if ($city1=="nameo fregion2"){echo "SELECTED"; }?> value="nameofre gion2">nameofre gion2</option>
    <option <?php if ($northisland== "1"){echo "SELECTED"; }?> value="1"></option>
    </select>

    <select name="city2">
    <option <?php if ($city2=="regio n2"){echo "SELECTED"; }?> value="region2" >Select region2</option>
    <option <?php if ($city2=="nameo fregion1"){echo "SELECTED"; }?> value="nameofre gion1">nameofre gion1</option>
    <option <?php if ($northisland== "2"){echo "SELECTED"; }?> value="2"></option>
    <option <?php if ($city2=="nameo fregion2"){echo "SELECTED"; }?> value="nameofre gion2">nameofre gion2</option>
    <option <?php if ($northisland== "3"){echo "SELECTED"; }?> value="3"></option>
    </select>
    [/php]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 [php]
    if(!($city1 == "region1") && !($city2 == "region2"))
    {
    $error.="Please select only 1 Region<br />";
    }[/php]
    now by introducing <option <?php if ($northisland== "0"){echo "SELECTED"; }?> value="0"></option> 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 <option> tag or should i only use 0 everywhere[php]
    <option <?php if ($northisland== "0"){echo "SELECTED"; }?> value="0"></option>
    <option <?php if ($northisland== "1"){echo "SELECTED"; }?> value="1"></option>[/php]2.
    how can i get around the conflict that is being created by introducing this value=0 with [php]
    if(!($city1 == "region1") && !($city2 == "region2"))
    {
    $error.="Please select only 1 Region<br />";
    }[/php]
    as i need the above php code and i also need the blank space for formatting purpose

    please advice.

    thanks.
    Last edited by ronverdonk; Mar 31 '08, 09:06 AM. Reason: code tags added!!
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Originally posted by runway27
    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=
    <select name="city1">
    <option <?php if ($city1=="regio n1"){echo "SELECTED"; }?> value="region1" >Select region1</option>
    <option <?php if ($city1=="nameo fregion1"){echo "SELECTED"; }?> value="nameofre gion1">nameofre gion1</option>
    <option <?php if ($northisland== "0"){echo "SELECTED"; }?> value="0"></option>
    <option <?php if ($city1=="nameo fregion2"){echo "SELECTED"; }?> value="nameofre gion2">nameofre gion2</option>
    <option <?php if ($northisland== "1"){echo "SELECTED"; }?> value="1"></option>
    </select>


    <select name="city2">
    <option <?php if ($city2=="regio n2"){echo "SELECTED"; }?> value="region2" >Select region2</option>
    <option <?php if ($city2=="nameo fregion1"){echo "SELECTED"; }?> value="nameofre gion1">nameofre gion1</option>
    <option <?php if ($northisland== "2"){echo "SELECTED"; }?> value="2"></option>
    <option <?php if ($city2=="nameo fregion2"){echo "SELECTED"; }?> value="nameofre gion2">nameofre gion2</option>
    <option <?php if ($northisland== "3"){echo "SELECTED"; }?> value="3"></option>
    </select>


    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<br />";
    }


    now by introducing <option <?php if ($northisland== "0"){echo "SELECTED"; }?> value="0"></option> 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 <option> tag or should i only use 0 everywhere
    <option <?php if ($northisland== "0"){echo "SELECTED"; }?> value="0"></option>
    <option <?php if ($northisland== "1"){echo "SELECTED"; }?> value="1"></option>

    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<br />";
    }
    as i need the above php code and i also need the blank space for formatting purpose

    please advice.

    thanks.
    DUDE, i'm so confused with your little rule numbering scheme you got going on, where's Appendix B? (joke)

    Please explain in plain words, you've proven enough to us that you've attempted at some code, we agree to help you, here's what i think you want:

    User can select from 2 drop downs (cities, regions, whatever), and they can only choose one of the two, not both.

    What other conditions do you have on these two fields?

    Let us know,

    thanks,


    DM

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      I did the code tagging for you this time, but next time please enclose your posted code in [code] tags (See How to Ask a Question).

      This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

      Please use [code] tags in future.

      MODERATOR

      Comment

      Working...