Language selection using images in PHP
I have found an open source PHP script that uses a select menu to choose the language.
In the code session makes use of a loop to fill in the select menu, as above...
$la = 0;
foreach($trans['languages'] as $short=>$langname) {
$params['LANGSEL'][$la]['LANG_SHORT'] = $short;
$params['LANGSEL'][$la]['LANG_LONG'] = $langname;
$la++;
}
In the php template creates the select menu like that...
<td><select class="select" name="lang"><#FOR LANGSEL#>
<option value="<#LANG_SHORT#>"><#LANG_LONG#></option>
<#/FOR LANGSEL#></select></td>
So this code works fine but i find it kinda ugly so i am trying to make an image input instead So i thought something like that would work..
<input type="image" name="lang" value="http://localhost/index.php?lang=en" src=" <#IMAGES_DIRECTORY#>/english.png"></td>
<input type="image" name="lang" value="http://localhost/index.php?lang=it" src=" <#IMAGES_DIRECTORY#>/itali开发者_运维技巧an.png"></td>
But nothing changes, the page always shows up in italian that is the default language.. Thanks in advance from a newbie that is struggling to learn some html and php.
The value of your name field should be <#LANG_SHORT#>
. You don't say what it looks like after being processed but I'm pretty sure it's something like en
or it
. However, you provide a URL. You also prepend several white spaces to the image's URL.
This will probably work:
<input type="image" name="lang" value="<#LANG_SHORT#>" src="<#IMAGES_DIRECTORY#>/english.png"></td>
Remember to test it in Internet Explorer. It's traditionally had several problem with <input type="image">
elements.
The problem here is that you have two images with different name
s, whereas you need to only have one form element, called name
, whose value is the correct <#LANG_SHORT#>
string. In this regard, select
and radio
form elements are perfectly suited to the job, whereas input
s are not.
It also seems unlikely to me that the form element really has a value of http://localhost/index.php?lang=en
. Isn't that merely the URL that results from changing the language? It seems more likely that the proper value for your form fields is just en
/it
.
Ultimately, I reckon you're going to need a hidden form field, and some Javascript on your image
s to set that field's value when required. And be aware that the usability/accessibility of your site just went from [potentially] high to [definitely] very low.
精彩评论