Add with-form macro

This commit is contained in:
Marcus Kammer 2024-06-23 09:11:47 +02:00
parent 4a302c7571
commit b69746436f
Signed by: marcuskammer
GPG key ID: C374817BE285268F

View file

@ -61,7 +61,8 @@
:ctrl-url
:ctrl-week
:ctrl-element
:search-form))
:search-form
:with-form))
(in-package :dev.metalisp.sbt/form)
@ -486,3 +487,22 @@ Example 1:
collect `(:option ,value))))
`(progn ,@(loop for value in values
collect `(:li (apply-input-form ,type ,group ,value))))))))))))
(defmacro with-form (&body body)
"Create a standardized HTML form wrapped in a <main> tag with a pre-defined
class and structure, using the Spinneret library. The form is designed to be
used within a web application served by Hunchentoot, utilizing common layout
and localization practices. The macro automatically sets the forms action to
the current request URI and expects certain functions and variables to be
available in its environment for full functionality."
`(spinneret:with-html
(:main :id "main-content"
:class "container my-5"
(:p "Please fill out the following forms and press the submit button.")
;; action is defined as hunchentoot:request-uri* function
(:form :action (request-uri*)
:method "post"
:class (spacing :property "m" :side "y" :size 5)
,@body
(btn-primary (:type "submit")
(find-l10n "submit" ml-survey:*html-lang* *l10n*))))))