Slynderdale
01-20-2003, 10:00 PM
I recently installed the gender hack on my version 2.2.9 forum and looked through adminfunction.php and couldnt find a function to make a select menu si i made my own and figured I'll release it in case it would be helpful to others, any ways, here it is:
// ###################### Start makeselectcode #######################
function makeselectcode ($title,$name,$selectarray,$value="select_null") {
// Makes code for select menu's
unset($content);
if (count($selectarray)) {
$content = "<select name='".$name."'>\n";
while (list($select_name,$select_value) = each($selectarray)) {
if ($select_name) {
unset($selected);
if ((trim(strtolower($select_value)) == trim(strtolower($value))) and $value != "select_null")
$selected = " selected";
$content .= '<option value="'.$select_value.'"'.$selected.'>'.$select_name.'</option>\n';
}
}
$content .= "</select>";
}
echo "<tr class='".getrowbg()."' valign='top'>\n<td><p>$title</p></td>\n<td><p>".$content."</p></td>\n</tr>\n";
}
just place that in adminfunctions.php, like above the ?>
Heres an example on how to use it:
makeselectcode("Gender","gender",array("Undisclosed" => "0","Female" => "1","Male" => "2"),0);
The first parameter in the function is the title of the select menu, the secton param is the select name, the third is an array to male the select menu with, heres how that is set up:
array("Name" => "Value");
and you can have all you want for example:
array("Name" => "Value","Name" => "Value","Name" => "Value");
and the forth and final param is the value of the select menu, as it creates the select menu, if the value in the array matches the value param, it selected it like:
<option value="$Value" selected>$Name</select>
so in:
array("foo1" => "bar1","foo2" => "bar2","foo3" => "bar3");
and you set the function value parameter to bar2 like:
makeselectcode("Test","text",array("foo1" => "bar1","foo2" => "bar2","foo3" => "bar3"),"foo2");
the secon option will be selected like:
<option value="bar2" selected>foo2</select>
I hoped I explained it well enough, also If a function similar to this exsists, can a mod please delete this thread, thank you.
Ill post an attachment below to show the outcome in admin users for the gender hack I installed.
// ###################### Start makeselectcode #######################
function makeselectcode ($title,$name,$selectarray,$value="select_null") {
// Makes code for select menu's
unset($content);
if (count($selectarray)) {
$content = "<select name='".$name."'>\n";
while (list($select_name,$select_value) = each($selectarray)) {
if ($select_name) {
unset($selected);
if ((trim(strtolower($select_value)) == trim(strtolower($value))) and $value != "select_null")
$selected = " selected";
$content .= '<option value="'.$select_value.'"'.$selected.'>'.$select_name.'</option>\n';
}
}
$content .= "</select>";
}
echo "<tr class='".getrowbg()."' valign='top'>\n<td><p>$title</p></td>\n<td><p>".$content."</p></td>\n</tr>\n";
}
just place that in adminfunctions.php, like above the ?>
Heres an example on how to use it:
makeselectcode("Gender","gender",array("Undisclosed" => "0","Female" => "1","Male" => "2"),0);
The first parameter in the function is the title of the select menu, the secton param is the select name, the third is an array to male the select menu with, heres how that is set up:
array("Name" => "Value");
and you can have all you want for example:
array("Name" => "Value","Name" => "Value","Name" => "Value");
and the forth and final param is the value of the select menu, as it creates the select menu, if the value in the array matches the value param, it selected it like:
<option value="$Value" selected>$Name</select>
so in:
array("foo1" => "bar1","foo2" => "bar2","foo3" => "bar3");
and you set the function value parameter to bar2 like:
makeselectcode("Test","text",array("foo1" => "bar1","foo2" => "bar2","foo3" => "bar3"),"foo2");
the secon option will be selected like:
<option value="bar2" selected>foo2</select>
I hoped I explained it well enough, also If a function similar to this exsists, can a mod please delete this thread, thank you.
Ill post an attachment below to show the outcome in admin users for the gender hack I installed.