views:

93

answers:

2

I'm having a bit of a weird situation here. I have a form that submits using the GET method for a search function. On the subsequent page after a search, all the variables are displayed in the URL even if they are empty. For example if I make a search for movie title equaling "hello," I'll get this:

/GetResults?title=hello&year=&director=&firstname=&lastname=

Is this normal or am I doing something wrong? Here is the form I am using:

<form action="/FabFlix/servlet/GetResults" id="search-form" method="get" accept-charset="utf-8">
<p>Movie Title:</p><input type="text" name="title"/>
<br/>
<p>Year:</p><input type="text" name="year"/>
<br/>
<p>Director:</p><input type="text" name="director"/>
<br/>
<p>Star's First Name:</p><input type="text" name="firstname"/>
<br/>
<p>Star's Last Name:</p><input type="text" name="lastname"/>
<br/>
<br/>
<input type="submit"/>
</form>
+2  A: 

This is normal. To prevent this behavior, consider an onsubmit handler on your form which assembles the URL manually and redirects. If you do this, don't forget to test this with javascript both enabled and disabled to make sure both scenarios still work OK.

Justin Grant
Thanks for the answer. I had never noticed this behavior before but I will consider the Javascript solution
trinth
A: 

I believe that's normal operation for GET. Do you have to use GET instead of POST?

It seems that a relatively simple change to get the variables from not displaying in the URL is to use the POST method instead of GET.

mrduclaw
GET was a requirement for the application so I cannot do that.
trinth