Remove %5B%5D from URL when submitting form

forms, html, php, url-rewriting

Solution

Is there someway that I can remove the %5B%5D to make the URL "pretty", with something like htaccess?

No. The `[]` are reserved characters in URLs, so they definitely need to be URL-encoded.

If using POST is not an option, which makes sense given that it's a search form, your best bet is to just give them each a different name with a value of 1 or so.

<form>
    <input type="checkbox" name="option1" value="1" />
    <input type="checkbox" name="option2" value="1" />
</form>

Or, if you really insist in them having the same name, then you should be extracting the query string yourself instead of relying on the PHP specific feature of returning an array when obtaining a parameter with a `[]` suffix in the name.

$params = explode('&', $_SERVER['QUERY_STRING']);

foreach ($params as $param) {
    $name_value = explode('=', $param);
    $name = $name_value[0];
    $value = $name_value[1];
    // ... Collect them yourself.
}

This way you can just keep using the braceless name.

<form>
    <input type="checkbox" name="option" value="option1" />
    <input type="checkbox" name="option" value="option2" />
</form>

Problem

When I submit a form with multiple checkboxes that have the same name I get a URL that looks something like this: www.mysite.com/search.php?myvalue%5B%5D=value1&myvalue%5B%5D=value2 Is there someway that I can remove the %5B%5D to make the URL "pretty", with something like htaccess? Code: ``` <form> <input type="checkbox" name="myvalue[]" value="value1"> <input type="checkbox" name="myvalue[]" value="value2"> </form> ```

Original source

Related problems