(:head (:title 'Simple Form'))
(:body
(:form :method 'POST' :action '/show-query-params'
(:table
(:tr (:td 'Foo')
(:td (:input :name 'foo' :size 20)))
(:tr (:td 'Password')
(:td (:input :name 'password' :type 'password' :size 20))))
(:p (:input :name 'submit' :type 'submit' :value 'Okay')
(:input ::type 'reset' :value 'Reset'))))))))))
(publish :path '/simple-form' :function 'simple-form)
Point your browser to http://localhost:2001/simple-form
, and you should see a page like the one in Figure 26-5.

If you fill in the form with the 'abc' and 'def' values, clicking the Okay button should take you to a page like the one in Figure 26-6.

However, most of the time you won't need to iterate over all the query parameters; you'll want to pick out individual parameters. For instance, you might want to modify random-number
so the limit value you pass to RANDOM
can be supplied via a query parameter. In that case, you use the function request-query-value
, which takes the request object and the name of the parameter whose value you want and returns the value as a string or NIL
if no such parameter has been supplied. A parameterizable version of random-number
might look like this:
(defun random-number (request entity)
(with-http-response (request entity :content-type 'text/html')
(with-http-body (request entity)
(let* ((*html-output* (request-reply-stream request))
(limit-string (or (request-query-value 'limit' request) ''))
(limit (or (parse-integer limit-string :junk-allowed t) 1000)))
(html
(:html
(:head (:title 'Random'))
(:body
(:p 'Random number: ' (:print (random limit))))))))))
Because request-query-value
can return either NIL
or an empty string, you have to deal with both those cases when parsing the parameter into a number to pass to RANDOM
. You can deal with a NIL
value when you bind limit-string
, binding it to ''
if there's no 'limit' query parameter. Then you can use the :junk-allowed
argument to PARSE- INTEGER
to ensure that it returns either NIL
(if it can't parse an integer from the string given) or an integer. In the section 'A Small Application Framework,' you'll develop some macros to make it easier to deal with grabbing query parameters and converting them to various types.