dev.metalisp.sbt/docs/pattern/questionnaire.org

129 lines
4.5 KiB
Org Mode
Raw Permalink Normal View History

2024-03-14 18:20:24 +01:00
#+title: Creating a Questionnaire using dev.metalisp.sbt/component/questionnaire Macros in a Web Application
2023-09-14 15:00:36 +02:00
#+author: Marcus Kammer
#+email: marcus.kammer@mailbox.org
2024-04-21 22:01:47 +02:00
#+date: [2024-04-21 18:55]
2023-09-14 15:00:36 +02:00
* Introduction
Questionnaires are powerful tools for gathering information and insights from
users. They are crucial for understanding user behaviors, preferences, and
requirements. This document will demonstrate how to build a web-based
questionnaire using the cl-sbt/questionnaire macros in a Common Lisp
application.
** The Importance of Questionnaires
Questionnaires help in collecting data for various purposes including market
research, user experience study, and many more. They can be in multiple formats
like single-choice, multiple-choice, or open-ended questions.
*** Types of Questions
- Single Choice: Questions that allow one answer.
- Multiple Choice: Questions that allow multiple answers.
- Text: Open-ended questions for free text input.
2024-02-10 13:38:57 +01:00
* Integrating dev.metalisp.sbt/component/questionnaire Macros
2023-09-14 15:00:36 +02:00
To create a questionnaire in your Common Lisp web application,
cl-sbt/questionnaire macros can be employed. These macros generate the HTML
required for different types of questions in a questionnaire.
2023-08-25 22:01:32 +02:00
2024-03-16 14:00:59 +01:00
#+begin_src lisp
(ql:quickload '(:dev.metalisp.sbt :hunchentoot))
#+end_src
#+RESULTS:
| :DEV.METALISP.SBT |
2024-03-16 11:54:18 +01:00
#+begin_src lisp
2024-02-04 15:13:35 +01:00
(defpackage my-web-questionnaire-app
(:use :cl)
(:import-from :dev.metalisp.sbt :with-page)
2024-04-21 22:01:47 +02:00
(:import-from :dev.metalisp.sbt/questionnaire :questionnaire)
2024-02-04 15:13:35 +01:00
(:export :generate-questionnaire-page))
2024-03-16 11:54:18 +01:00
#+end_src
2023-09-15 10:32:46 +02:00
2024-03-16 14:00:59 +01:00
#+RESULTS:
: #<PACKAGE "MY-WEB-QUESTIONNAIRE-APP">
2024-03-16 11:54:18 +01:00
#+name: questionnaire-page
#+begin_src lisp :results output file :file-ext html
2024-02-04 15:13:35 +01:00
(in-package :my-web-questionnaire-app)
2023-08-25 22:01:32 +02:00
2023-09-15 10:32:46 +02:00
(defun generate-questionnaire-page ()
2024-02-04 15:13:35 +01:00
"Generates an HTML page with questionnaires using questionnaire macros."
(with-output-to-string (spinneret:*html*)
(with-page (:title "Questionnaire Example" :main-con t)
2024-04-21 22:01:47 +02:00
(questionnaire "#" "none"
(:ask "How old are you?"
:group "age"
:choices (:radio "18-24" "25-34" "35-44" "45-54" "55+"))
2024-03-14 18:12:37 +01:00
(:ask "Gender"
:group "gender"
2024-04-21 22:01:47 +02:00
:choices (:radio "Male" "Female" "Non-binary" "Prefer not to say" "Other" :text "Please specify"))
2024-03-14 18:12:37 +01:00
(:ask "How many hours per day, on average, do you spend browsing the internet?"
:group "webbrowsing"
2024-01-28 11:38:41 +01:00
:choices (:radio "Less than 1 hour" "1-3 hours" "3-5 hours" "5+ hours"))
2024-03-14 18:12:37 +01:00
2024-01-28 11:38:41 +01:00
(:ask "What are your favorite brands?"
:group "brands"
2024-04-21 22:01:47 +02:00
:choices (:checkbox "Brand A" "Brand B" "Brand C" "None" "Other" :text "Please specify"))
2024-03-14 18:12:37 +01:00
2024-01-28 11:38:41 +01:00
(:ask "How often do you shop online?"
:group "shopping"
:choices (:radio "Daily" "Weekly" "Monthly" "Rarely" "Never"))
2024-03-14 18:12:37 +01:00
2024-01-28 11:38:41 +01:00
(:ask "Which of the following devices do you own?"
:group "devices"
:choices (:checkbox "Smartphone" "Laptop/PC" "Tablet" "Smartwatch" "None"))
2024-03-14 18:12:37 +01:00
2024-01-28 11:38:41 +01:00
(:ask "What is your preferred method of payment for online purchases?"
:group "payment"
:choices (:radio "Credit/Debit Card" "PayPal" "Bank Transfer" "Cash on Delivery" "Cryptocurrency"))
2024-03-14 18:12:37 +01:00
2024-01-28 11:38:41 +01:00
(:ask "Which social media platforms do you use regularly?"
:group "socialmedia"
2024-04-21 22:01:47 +02:00
:choices (:checkbox "Facebook" "Twitter" "Instagram" "LinkedIn" "TikTok" "None" "Other" :text "Please specify"))
2024-03-14 18:12:37 +01:00
2024-01-28 11:38:41 +01:00
(:ask "How do you usually consume news?"
:group "newsconsumption"
:choices (:radio "Online News Websites" "Social Media" "Television" "Newspapers/Magazines" "Radio" "None"))))))
2023-08-25 22:01:32 +02:00
(format t (generate-questionnaire-page))
2023-08-25 22:01:32 +02:00
#+end_src
2023-09-15 10:32:46 +02:00
2023-09-21 15:17:47 +02:00
#+RESULTS: questionnaire-page
[[file:questionnaire-page.html]]
2023-09-15 10:32:46 +02:00
This example demonstrates the integration of the cl-sbt/questionnaire macros into a
web application. The macros assist in generating the required HTML for
different types of Bootstrap questionnaires.
2024-03-16 11:54:18 +01:00
#+begin_src lisp
(in-package :my-web-questionnaire-app)
2024-04-18 16:41:38 +02:00
(defvar *basic-server* nil)
2024-03-16 11:54:18 +01:00
2024-03-16 14:00:59 +01:00
(defun start-server ()
(setf *basic-server* (make-instance 'hunchentoot:easy-acceptor :name "basic-server" :port 8080))
(hunchentoot:start *basic-server*))
2024-03-16 11:54:18 +01:00
(defun stop-server (server)
2024-03-16 14:00:59 +01:00
(when server
(hunchentoot:stop server)
(setf *basic-server* nil)))
2024-03-16 11:54:18 +01:00
(defun restart-server (server)
(stop-server server)
2024-03-16 14:00:59 +01:00
(start-server))
2024-04-18 16:41:38 +02:00
(hunchentoot:define-easy-handler (submit :uri "/submit")
((data :parameter-type :post))
(format nil "Hello, ~a!" data))
2024-03-16 11:54:18 +01:00
#+end_src
2024-03-16 14:00:59 +01:00
#+RESULTS:
2024-04-18 16:41:38 +02:00
: SUBMIT