Search code examples
common-lisphunchentoot

Hunchentoot handler for dynamic amount of parameters


I want to be able to handle a form which uses a dynamic amount of form fields

e.g.

(form :action "/theaction"
      :method "post"
      (input :type "text" :name "firstinput") (:br)
      (dotimes (i n)
         (:input :type "text" :name (FORMAT nil "INPUT~a" i)))
      (:input :type "submit" :value "submit" :name "submit"))

how can I define the handler as the &rest is not accepted and would not allow me to access the variable names which I obviously need for further processing.

(define-easy-handler (theaction :uri "/theaction") (&special-rest all-params)
   (log-message* :INFO "~a" all-params))

-> "(("firstinput" . "value") ("INPUT0" . "value") ("INPUT1" . "value") ...)"

A possibility would be to pre-define all variables up to e.g. 100, but this would seem rather cumbersome and unintuitive.


Solution

  • The lambda-list of define-easy-handler is just a shortcut for using lower-level calls. You can get more extensive access to parameters by using functions like like GET-PARAMETER and POST-PARAMETER. You can get an alist of all parameters by using get-parameters* (or post-parameters*) in the body of the handler.