Search code examples
htmlformshttphttp-get

Submitted Forms not Encoding +'s when using method="get"


With the following form

<form target="dialogiframe" action="ConfigUpdate.cvx" id="TestForm" 
    name="TestForm" method="get">
    <input name="test" type="text" size="40" value="A Sum 1+2=3"/>
    <input type="submit" value="Set" />
</form>

the parameters of the submitted request are encoded as follows

test=A+Sum+1+2=3

After that is decoded, it gives the incorrect value of "A Sum 1 2=3" as the + in the parameter is not encoded (neither is the = ), and this is converted into a space.

if I change the method to post, then parameters are encoded correctly as

test=A+Sum+1%2B2%3D3

and is then converted correctly.

I know I should use POST and indeed am going through my pages and am converting them, but am I missing anything in the form definition to make the GET encode correctly?

Tested with IE8 and FF10, pages in <!DOCTYPE html>


Solution

  • I believe this is a known issue with using GET as the form method. Generally you should use the POST method with your forms.

    From: http://www.cs.tut.fi/~jkorpela/forms/methods.html

    The official recommendations say that "GET" should be used if and only if the form processing is idempotent, which typically means a pure query form. Generally it is advisable to do so. There are, however, problems related to long URLs and non-ASCII character repertoires which can make it necessary to use "POST" even for idempotent processing.