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

2.6 KiB

Creating a Questionnaire using cl-sbt/questionnaire Macros in a Web Application

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.

Integrating cl-sbt/questionnaire Macros

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.

  (defpackage my-web-app
	(:use :cl :cl-sbt/questionnaire)
	(:export :generate-button-page))

  (in-package :my-web-app)

  (defun generate-questionnaire-page ()
	"Generates an HTML page with questionnaires using cl-sbt/questionnaire macros."
	(spinneret:with-html-string
	  (:html
	   (:head
		(:title "Questionnaire Examples")
		(:link :type "text/css"
		  :rel "stylesheet"
		  :href "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"))
	   (:body
		 (:h1 "Questionnaire Examples")
		 ;; ---
		 (questionnaire "/submit"
		   (:ask "How old are you?"
			:group "age"
			:choices (:radio "18-24" "25-34" "35-44" "45-54" "55+"))
		   (:ask "Gender"
			:group "gender"
			:choices (:radio "Male" "Female" "Non-binary" "Prefer not to say" "Other" :text "Other"))
		   (:ask "How many hours per day, on average, do you spend browsing the internet?"
			:group "webbrowsing"
			:choices (:radio "Less than 1 hour" "1-3 hours" "3-5 hours" "5+ hours")))
		 ;; ---
		 (:script :src "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js")))))

  (format t (generate-questionnaire-page))

/marcuskammer/dev.metalisp.sbt/src/commit/87c23ecac9b54584dff349a334dd892cf5187d88/docs/pattern/questionnaire-page.html

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.