views:

19

answers:

1

When creating search forms in web pages, I generally use the GET method. This allow the results to be URI Addressable. It also makes for easy pagination of results in the standard manner.

But what about a form with a large number of options and fairly long field names? Using a GET request means that the URL of the results page can actually crack the practical URL length limit of 2KB.

If I change to using POST, I beat the URL length limit. But then I lose the URI addressability. Also, all pagination links need to be reimplemented as little subforms with all the search parameter data stored in hidden fields; making these operate as links would then require something like onclick handlers, which makes them usable only when client-side scripting is enabled.

So, what is the advice for long search forms that:

  • maintain URI addressability
  • allow reasonable pagination links
  • don't break a practical URL 2KB length limit

The only thing I'm coming up with is sticking with GET, but reducing the lengths of the field names so that we are less likely to bust the URL limit.

Whaddya think? Many thanks in advance.

A: 

What you need to do is use the post method - you can't get around this if your URL is going to be over the limit (although you can delay the inevitable by abbreviating names and values).

Take the post and then redirect the client to a get, to keep things addressable you can either store the search server side against a key and retrieve it on the get (e.g. from memory or a database), or you could encode the keys into a single querystring key or a smaller number of keys which capture the behaviour. The resulting response will be bookmarkable etc.

Pagination is easy enough - just look for the presence or absence of the navigation buttons in the form collection and respond accordingly.

FinnNk
Aaah, post, store params (or results) with a key (maybe an md5 or some such) and then redirect to a get that retrieves using the key. Nice idea. Thanks!I'm going to leave the question open (unanswered) for a bit to see if we get some other ideas. But your answer sure looks like a solid accept candidate. Thanks!
David Weinraub