SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,786
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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="^$">

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,786
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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="^$">

  6. #6
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys. I decided to use regexp to decode the specific part.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,786
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by svcghost View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •