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.
| SitePoint Sponsor |
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.
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.

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.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">


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.
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.

It still doesn't end up encoded in the URL though.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
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.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
Bookmarks