Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use GET or POST for a search form

Tags:

post

forms

get

I have a couple search forms, 1 with ~50 fields and the other with ~100. Typically, as the HTML spec says, I do searches using the GET method as no data is changed. I haven't run into this problem yet, but I'm wondering if I will run out of URL space soon?

The limit of Internet Explorer is 2083 characters. Other browsers, have a much higher limit. I'm running Apache, so the limit there is around 4000 characters, which IIS is 16384 characters.

At 100 fields, say average field name length of 10 characters, that's already 5000 characters...amazing on the 100 field form, I haven't had any errors yet. (25% of the fields are multiple selects, so the field length is much longer.)

So, I'm wondering what my options are. (Shortening the forms is not an option.) Here my ideas:

  • Use POST. I don't like this as much because at the moment users can bookmark their searches and perform them again later--a really dang nice feature.
  • Have JavaScript loop through the form to determine which fields are different than default, populate another form and submit that one. The user would of course bookmark the shortened version.

Any other ideas?

Also, does anyone know if the length is the encoded length or just plain text?

I'm developing in PHP, but it probably doesn't make a difference.

Edit: I am unable to remove any fields; I am unable to shorten the form. This is what the client has asked for and they often do use a range of fields, in the different categories. I know that it's hard to think of a form that looks nice with this many fields, but the users don't have a problem understanding how it works.

like image 646
Darryl Hein Avatar asked Nov 18 '08 00:11

Darryl Hein


People also ask

Should you use GET or POST for search?

Search API (POST method) uses the POST method to search the CIs. It searches the CIs based on the input parameters that are provided in the JSON format. The advantage of using the search API (POST method) over the search API (GET method) is that you can use any slot names to search the CIs.

Which is better GET or POST method?

POST request is comparatively more secure because the data is not exposed in the URL bar. Request made through GET method are stored in Browser history. Request made through POST method is not stored in Browser history. GET method request can be saved as bookmark in browser.


2 Answers

Are your users actually going to be using all 50-100 fields to do their searches? If they're only using a few, why not POST the search to an "in between" page which header()-redirects them to the results page with only the user-changed fields in the URL? The results page would then use the default values for the fields that don't exist in the URL.

like image 104
Paige Ruten Avatar answered Oct 19 '22 07:10

Paige Ruten


To indirectly address your question, if I was faced with a 100-field form to fill in on one page, I'd most likely close my browser, it sounds like a complete usability nightmare.

My answer is, if there's a danger that I'm getting anywhere near that limit for normal usage of the form, I'm probably Doing It Wrong.

In order of preference, I would

  1. Split the form up and use some server-side state retention
  2. Switch to POST, and then generate and redirect to a shorter URL on POST that resolved to the same result
  3. Give up ;)
like image 30
Gareth Avatar answered Oct 19 '22 09:10

Gareth