I wonder if he suspected there was a better way.
-
Here's a little bit of code I came across on a production server. The following function creates a select menu where the selected value is the argument provided. Thankfully I'll never have to maintain this project.
On a sidenote I've changed the drop-down values to anonymize it a bit, so there are a few WTFs with them too. You can disregard that.
<?php
function select_period($x10)
{
?>
<select name="x10" >
<?php
if ($x10 != "")
{
$option_values = '<BR>
<option value="">Choose a time period</option>
<option value="2000">Ancient</option>
<option value="1000">Prehistoric</option>
<option value="1200">Palaiolithic</option>
<option value="1300">Mesolithic</option>
<option value="1400">Neolithic</option>
<option value="1499">Bronze Age</option>
<option value="1599">Ancient Greece</option>
<option value="1620">Ancient</option>
<option value="1630">Classic</option>
<option value="1700">Greek</option>
<option value="1800">Roman</option>
<option value="1999">Byzantine/Post Byzantine</option>
<option value="2099">Byzantine</option>
<option value="2599">Post Byzantine</option>
<option value="2999">Modern</option>';
//CASES WITH TIME PERIODS
switch ($x10) {
case "2000":
echo '<option selected value="2000">Ancient</option>';
echo $option_values;
break;
case "1000":
echo '<option selected value="1000">Prehistoric</option>';
echo $option_values;
break;
case "1200":
echo '<option selected value="1200">Palaiolithic</option>';
echo $option_values;
break;
case "1300":
echo '<option selected value="1300">Mesolithic</option>';
echo $option_values;
break;
case "1400":
echo '<option selected value="1400">Neolithic</option>';
echo $option_values;
break;
case "1499":
echo '<option selected value="1499">Bronze Age</option>';
echo $option_values;
break;
case "1599":
echo '<option selected value="1599">Ancient Greece</option>';
echo $option_values;
break;
case "1620":
echo '<option selected value="1620">Ancient</option>';
echo $option_values;
break;
case "1630":
echo '<option selected value="1630">Classic</option>';
echo $option_values;
break;
case "1700":
echo '<option selected value="1700">Greek</option>';
echo $option_values;
break;
case "1800":
echo '<option selected value="1800">Roman</option>';
echo $option_values;
break;
case "1999":
echo '<option selected value="1999">Byzantine/Post Byzantine</option>';
echo $option_values;
break;
case "2099":
echo '<option selected value="2099">Byzantine</option>';
echo $option_values;
break;
case "2599":
echo '<option selected value="2599">Post Byzantine</option>';
echo $option_values;
break;
case "2999":
echo '<option selected value="2999">Modern</option>';
echo $option_values;
break;
}//END SWITCH
}
else
{
?>
<option selected value="">Choose a time period</option>
<option value="2000">Ancient</option>
<option value="1000">Prehistoric</option>
<option value="1200">Palaiolithic</option>
<option value="1300">Mesolithic</option>
<option value="1400">Neolithic</option>
<option value="1499">Bronze Age</option>
<option value="1599">Ancient Greece</option>
<option value="1620">Ancient</option>
<option value="1630">Classic</option>
<option value="1700">Greek</option>
<option value="1800">Roman</option>
<option value="1999">Byzantine/Post Byzantine</option>
<option value="2099">Byzantine</option>
<option value="2599">Post Byzantine</option>
<option value="2999">Modern</option>
</select>
<?php
}
}
-
<option value="3010">Rise Of Skynet</option>';
<option value="3011">Skynet's Defense Grid Smashed</option>';
<option value="3012">John Connor Elected World Dominar</option>';
-
Quite brillant. So... what exactly does the $option_values variable provide which a code comment couldn't?
And what will a <br /> do inside a select?
Addendum: and yes, I always write my br tags XHTML compliant. I got used to that while using the text-only post editor in this very forum.
-
@derula said:
Addendum: and yes, I always write my br tags XHTML compliant. I got used to that while using the text-only post editor in this very forum.
The problem is that this forum doesn't serve proper XHTML, so technically you are just tossing more poorly-formed HTML into the mess. Not that it really matters.
-
@morbiuswilters said:
The problem is that this forum doesn't serve proper XHTML, so technically you are just tossing more poorly-formed HTML into the mess.
Well, I thought "CS is already spilling lots of poorly-formed HTML, so what do you want to get used to? Correct HTML or correct XHTML?", and I decided to do the latter, because that might also be useful if I ever were to maintain enterprisey XML data formats.@morbiuswilters said:
Not that it really matters.
This.
-
@derula said:
Well, I thought "CS is already spilling lots of poorly-formed HTML, so what do you want to get used to? Correct HTML or correct XHTML?", and I decided to do the latter, because that might also be useful if I ever were to maintain enterprisey XML data formats.
Using advanced forensic techniques, I've uncovered what you initially said, to which I feel the need to point out that non-XML HTML isn't dead, and I don't really see how closing your break tags prepares you for SAX or XPATH or XSLT or any other technology with an "X" in it.
-
@bstorer said:
Using advanced forensic techniques, I've uncovered what you initially said
Wait, give me a break. How the hell did you do that? It was 4096 bit RSA encrypted, then rot-13'ed and finally base64'ed before I had it MD5'ed and then completely erased it!
-
@derula said:
@bstorer said:
Using advanced forensic techniques, I've uncovered what you initially said
Wait, give me a break. How the hell did you do that? It was 4096 bit RSA encrypted, then rot-13'ed and finally base64'ed before I had it MD5'ed and then completely erased it!
Hmm, that sounds very insecure. Perhaps you should have embedded it in a proper XML structure before encrypting it. Like <utterance><meaning overt="false">I hate your guts, you slimey weasel know-all ueberachiever!</meaning><meaning overt="true">Well, I thought "CS is already spilling lots of poorly-formed HTML, so
what do you want to get used to? Correct HTML or correct XHTML?", and I
decided to do the latter, because that might also be useful if I ever
were to maintain enterprisey XML data formats.</meaning></utterance>. Then you instruct the reader to select only those meanings where overt equals "true" and you're done.
-
@DOA said:
Palaiolithic
Should be "Paleolithic" (American) or "Palaeolithic" (British).
Since this is in your production app, I thought you should know.
-
@SlyEcho said:
Should be "Paleolithic" (American) or "Palaeolithic" (British).
Since this is in your production app, I thought you should know.
@DOA said:
On a sidenote I've changed the drop-down values to anonymize it a bit, so there are a few WTFs with them too. You can disregard that.
-
@bstorer said:
... except maybe X-Windows, but that's not so much a technology as it is a disease.@derula said:
Well, I thought "CS is already spilling lots of poorly-formed HTML, so what do you want to get used to? Correct HTML or correct XHTML?", and I decided to do the latter, because that might also be useful if I ever were to maintain enterprisey XML data formats.
Using advanced forensic techniques, I've uncovered what you initially said, to which I feel the need to point out that non-XML HTML isn't dead, and I don't really see how closing your break tags prepares you for SAX or XPATH or XSLT or any other technology with an "X" in it.
-
@DaveK said:
except maybe X-Windows, but that's not so much a technology as it is a disease.
With a few lifestyle changes, it is a condition you live with.
There are several treatment options, unfortunately I've found all of them much more painful than the disease itself.