Prevent a GET <form> from being encoded

Hey guys,

Is there any way to prevent an <input> value that is submitted in a GET form from being encoded in the URL? There is just one input value that I want to be decoded, while keeping the others encoded.

No. Browsers encode characters that are not allowed to appear in URLs when submitting a form with the GET method… because those characters are not allowed to appear in URLs and the resulting HTTP request for the content at that URL would not be valid.

If your browser did not encode forms, your browser would not work for browsing the web.

If you don’t want it to be encoded in the URL then you could POST the form instead - that doesn’t need to be encoded because it isn’t part of a URL.

Forms are still encoded when sent by POST. The default encoding is the same as GET (URL encoded – application/x-www-form-urlencoded).

Forms in HTML documents

Under the default encoding, the browser forms and encodes the key/value pairs exactly the same. If the method is GET, that data string is appended to the URL after a ?. If the method is POST, that string is sent as the request body. The string of data is identical either way.

It still doesn’t end up encoded in the URL though.

Thanks guys. I decided to use regexp to decode the specific part.

Where is it that you are decoding it - if it is on the server and you are running PHP then there is a specific function to decode it - urldecode().

Similarly if it is in the browser using JavaScript then there is also a specific function to decode it - decodeURIComponent().

You can’t use regexp in HTML and you can’t decode it in the actual URL being passed.