Add :PREFER-POST as an request-type to compute-parameter.
Useful when using redirects to the same script-name to validate form parameters.
Having :both and :prefer-post is pretty confusing. Can they be made into :get-or-post and :post-or-get, with :both as an alias for the former?
I am not so sure anymore if depending on the order of the get and post parameters is such a smart thing.
Here Is the usecase for post-parameters: Simple server side form validation: In the inital request to the handler name is nil and no error message is shown. After the submit the post part checks the form values and redirects to the get part.
(name)
(flet ((invalid-form-values ()
(redirect
(format nil "~a?~{~(~a~)=~a~^&~}"
(script-name*)
(loop for (k . v) in (append
(post-parameters*)
(get-parameters*))
collect (url-encode k)
collect (url-encode v))))))
(ecase (request-method*)
(:post
(when (or (null name)
(zerop (length name)))
(invalid-form-values))
(with-html-output-to-string (out)
(:html
(:h1 "Submit Successful"))))
(:get
(with-html-output-to-string (out)
(:html
(:head
(:style
"form { width:40ch }"
"label { font-size:85% }"
"input { width:100% }"))
(:body
;; to make this form work with current hunchentoot, we have
;; to add an :action attribute.
(:form
:method :post
(:p (:label
"Name"
;; show an error description
(when (and name (zerop (length name)))
(htm (:span "Name must not be empty")))
(:input :name :name :value name)))
(:p (:button "Create"))))))))))```
I think the request-type argument should also accept a
function as a request-type parameter.
stassats: I have followed your suggestions and added the keywords :GET-OR-POST and :POST-OR-GET
The documentation needs to be adjusted too. And I'm thinking, maybe :both shouldn't be documented anymore.