Why are [ ] characters processed this way in my URL?

Asked

Viewed 47 times

1

When sending a $_GET of my application have the following expression tipo%5B%5D=CASA in my url. The data comes from an HTML element of the type checkbox of name="tipo[]".

These characters simply represent [ and ].

Does anyone know why this is happening and how to fix it?

<input type="checkbox" name="tipo[]" value="APARTAMENTO/APTO DUPLEX" id="tp1">
<label for="tp1">Apartamento</label>

<input type="checkbox" name="tipo[]" value="CASA" id="tp2">
<label for="tp2">Casa</label>

<input type="checkbox" name="tipo[]" value="CASA EM CONDOMINIO" id="tp3">
<label for="tp3">Casa Condomínio</label>

1 answer

3


There’s nothing wrong with that string. This is a way to encode characters to be transmitted safely (with a code that does not allow mistakes).

Thus:

%5B is '['
%5D is ']'
%20 is a blank space

If you want to have this back to a javascript string you can use it like this:

decodeURI('tipo%5B%5D=CASA')
// resultado: "tipo[]=CASA"

var codificado = 'tipo%5B%5D=CASA';
var descodificado = decodeURI(codificado);
alert(descodificado);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.