I'm having an issue with a PHP page that generates an HTML document. On the page, there is a form that has a <select>
box, and each <option>
inside has a value with the URL parameters to use when changing the window location when the form is "submitted". The issue is that I noticed is that one of the parameters is a name, and when that name has a space in it, it breaks the window location because the space remains in the URL.
I've tried simply doing a str_replace()
on the string before it generates the <option>
tag, and when I view the <option>
in Firefox' inspector, it DOES contain a %20
instead of a space, but when I look at the URL bar after clicking the <option>
, it still retains the space instead of the %20
. Can anyone tell me what's wrong with the following snippet?
print("<form name=sel1>");
print("<select size=10 style='width:200;font-family:courier,monospace;
font-weight:bold;color:black;' ");
print("onchange=\"location = this.options[this.selectedIndex].value;\">");
for($i = 0; $i < count($allGroups); $i++)
{
print("<option value='groups.php?action=");
if($advancedPermissions)
{
if($modGroups)
{
print("edit");
}
else
{
print("view");
}
}
else
{
print("edit");
}
print("&group_id=");
print(str_replace(" ", "%20", $allGroups[$i][0])."'>");
print($allGroups[$i][0]);
if($allGroups[$i][2] != 'Y')
{
print(" - inactive");
}
}
print("</select></form>");
The relevant lines are the line with location =
and the line just after the group_id
parameter is added, where the str_replace()
is done.
I do the str_replace()
on just the value, not the display text, so it will show normally to the user, but contain the %20
character for when it is passed to the window location, but regardless, it either ignores it, or something else is happening I am not aware of.