Wednesday, July 1, 2009

HttpRequest class - Support for multivalue requests (e.g. checkbox)

A colleague of mine needed to process values from a form with checkboxes. In some instances, the amount of checked boxes (select all) was so great that he hit the 32k limit of Domino fields.

I suggested that he tried posting to an agent/used my HttpRequest class. This didn't work, as each checkboxvalue is sendt as a single parameter.

E.g. ...make_report?OpenAgent&user=tom&user=jane&user=jack

The previous version of the class only fetched the last parameter.
Dim request As New HttpRequest()
Print request.parameter("user")
' Prints jack


I updated the code, so that the class aggregates the values into a comma separated string dynamic array. Single value parameters are still Strings.
Dim request As New HttpRequest()
Print Join( request.parameter("user"), "," )
' Prints tom,jane,jack


>> The class in a txt-file

Share and enjoy!

3 comments:

Bjørn Cintra said...

Wouldn't it be more "correct" if the request.parameter returned an array?
I know I can just split it and get an array easily, but it just seems (to me at least) that it should be an array.

Btw, liking your approach, and thinking of "borrowing" parts of it for my own HttpSession class :)

Tommy Valand said...

I chose using a string due to simplicity. Most of the parameters you're going to deal with are single parameter types.

Dealing with values from multi select lists/checkboxes is somewhat of a rarity.

I am however going to rewrite the class to use an array internally to concatenate the values. This to make the concatenation more effective/less memory hungry. The class should be updated by 12 CET.

Tommy Valand said...

Argh! Forgot one thing.. If the "multi-select"-parameter contains a comma, the developer using the class is screwed..

To keep the usage simple, I'm going to return a variant. In case of a multi-select parameter, I'll return a dynamic array, else a String.