Aserveでフォームから入力データを受け取る

SBCL & Aserve でHTMLフォームよりデータを受け取る処理です。

HTMLフォーム

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>テスト</title>
</head>
<body>
<form action="/app/form.html" method="post">
<h3>フォームテスト</h3><br>
名前<br>
<input type="text" name="name" size="40"><br><br>
性別<br>
<input type="radio" name="sex" value="male"><input type="radio" name="sex" value="female"><br><br>
血液型:<select name="blood">
<option value="A">A型</option>
<option value="B">B型</option>
<option value="O">O型</option>
<option value="AB">AB型</option>
</select><br><br>
<input type="submit" value="送信">
</form>
</body>
</html>

フォームのデータを受け取る処理

(use-package :net.aserve)
(use-package :net.html.generator)

(publish
 :path "/app/form.html"
 :content-type "text/html"
 :function
 #'(lambda (req ent)
     (let* ((name (cdr (assoc "name" (request-query req)
			       :test #'equal)))
	    (sex (cdr (assoc "sex" (request-query req)
			      :test #'equal)))
	    (blood (cdr (assoc "blood" (request-query req)
			      :test #'equal))))
       (with-http-response
	(req ent)
	(with-http-body
	 (req ent)
	 (html
	  (:html
	   (:head (:title "test"))
	   (:body 
	    (:princ-safe name)
	     :br (:princ-safe sex)
	     :br (:princ-safe blood)))))))))