<?
///////////////////////
///////////////////////
$OriginalUrlToDisplay=strtok($_SERVER["REQUEST_URI"],'?');
$buttonTypeForColours="radio";
///////////////////////
///////////////////////
?>
<form>
<input type="<?=$buttonTypeForColours ?>" name="colourChoice[]" <? if($_GET["filter"]=="White"){?> onclick="location.href='<?=$OriginalUrlToDisplay?>'" checked="checked" <? } else {?> onclick="location.href='?filter=White'"<? } ?>/> <img src="http://www.gc-cdn.com/mobile/white.png" /> White<br />
<input type="<?=$buttonTypeForColours ?>" name="colourChoice[]" <? if($_GET["filter"]=="Black"){?> onclick="location.href='<?=$OriginalUrlToDisplay?>'" checked="checked" <? } else {?> onclick="location.href='?filter=Black'"<? } ?>/> <img src="http://www.gc-cdn.com/mobile/black.png" /> Black<br />
</form>
Is there a cleaner way to write this. There are over 40 colours. I know it is not really data intensive but it is difficult to read and manage.
You can easily loop it like this:
It is looping trough all the possible colors specified in
$colorsand then displays the right output by using a in-string ternary operator.You could also easily do a non-casesensitive comparison by changing
to