RE: [PHP] question about select tag in php



Code wise your form options are too bulky and you need to look at slimming that down like below. Not that my example is prefect but easier to control the option enviroment.


echo "<select name='city1'>";
for($d=1; $d<=2; $d++)
{
if($city1 == "region$d"){
echo "<option selected value='region$d'>region$d;
}ELSE{echo "<option value='region$d'>region$d;}
}
echo "</select><BR><select name='city2'>";
for($d=1; $d<=3; $d++)
{
if($city1 == "region$d"){
echo "<option selected value='region$d'>region$d;
}ELSE{echo "<option value='region$d'>region$d;}
}
echo "</select>";



Also I would use some onblur or onsubmit javascript for form validation submitting and then showing the error is NOT a good way to validate a form.


Richard L. Buskirk

Blame the GUI between your chair and keyboard.


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


















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=="region1"){echo "SELECTED";}?>
value="region1">Select region1</option>
<option <?php if ($city1=="nameofregion1"){echo "SELECTED";}?>
value="nameofregion1">nameofregion1</option>
<option <?php if ($northisland=="0"){echo "SELECTED";}?> value="0"></option>
<option <?php if ($city1=="nameofregion2"){echo "SELECTED";}?>
value="nameofregion2">nameofregion2</option>
<option <?php if ($northisland=="1"){echo "SELECTED";}?> value="1"></option>
</select>


<select name="city2">
<option <?php if ($city2=="region2"){echo "SELECTED";}?>
value="region2">Select region2</option>
<option <?php if ($city2=="nameofregion1"){echo "SELECTED";}?>
value="nameofregion1">nameofregion1</option>
<option <?php if ($northisland=="2"){echo "SELECTED";}?> value="2"></option>
<option <?php if ($city2=="nameofregion2"){echo "SELECTED";}?>
value="nameofregion2">nameofregion2</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.
.



Relevant Pages

  • question about select tag in php
    ... i have two select tags as part of a registration form, city1 city2 ... i am having an issue with the php validation. ...
    (comp.lang.php)
  • question about select tag in php
    ... city1 has a list of regions and similar for city2 ... am having an issue with the php validation. ... user cannot leave both the select tags with the default option which is ...
    (php.general)
  • Re: New Exciting Webmaster tools added! @Services.imasty.com
    ... html validator; the let you know they are mistaken in retrieving the ... The W3C validation tools are generic SGML or XML validators. ... This code cannot be valid according to the document type declaration, ... attempts make our site secure tags and all the tags is well formated ...
    (comp.infosystems.www.authoring.html)
  • Re: Tim Brays Mind
    ... > Verbose syntax of tags are for validation by programs, ... > closing parentheses of which one is missing is error-prone (as everyone ... You mean Lisp programs often don't work because we get the ...
    (comp.lang.lisp)
  • Re: Extending the XHTML transitional XSD
    ... validation functionality in the client side (implemented with javascript ... Then a javascript function processes all the tags and validates the form ... The code must be validated by some XHTML validators around the web. ...
    (comp.text.xml)