;;;-*- Mode: Lisp; Package: HTTP-DEMO -*- (in-package :http-user) ; ; Events - Bulletin board examples using events ; (defparameter *board* nil) ; Form example with input focus (defun display-bulletin-board (url stream) "Form function to display a bulletin board with a text field." (let ((title "Feedback")) (with-event-handlers (make-focus (:java-script :load "document.myform.text.focus()")) (with-successful-response (stream :html) (with-html-document (:stream stream) (with-document-preamble (:stream stream) (declare-title title :stream ,stream)) (with-document-body (:stream stream :events make-focus) (with-section-heading (title :stream stream) (dolist (topic (reverse *board*)) (when topic (with-paragraph (:stream stream) (write-string-quoting-specials topic stream))) (with-fillout-form (:post url :name "myform" :stream stream) (accept-input 'string "text" :stream stream) (accept-input 'submit-button "Submit" :stream stream)))))))))) (defun update-bulletin-board (url stream alist) "Response function to add an entry to the bulleting board." (bind-query-values (text) (url alist) (atomic-push text *board*) (display-bulletin-board url stream))) (export-url "http://localhost:8000/board.html" :html-computed-form :form-function 'display-bulletin-board :response-function 'update-bulletin-board) ; Form example with field validation (defun display-bulletin-board (url stream) "Routine to display a bulletin board and a form." (let ((title "Feedback")) (with-event-handlers (make-focus (:java-script :load (lambda (stream) (fast-format stream "\"document.myform.mysubmit.disabled = true\"")))) (with-event-handlers (check-field (:java-script :key-press (lambda (stream) (fast-format stream "\"if (this.value == '') document.myform.mysubmit.disabled = false\"")))) (with-successful-response (stream :html) (with-html-document (:stream stream) (with-document-preamble (:stream stream) (declare-title title :stream stream)) (with-document-body (:stream stream :events make-focus) (with-section-heading (title :stream stream) (dolist (topic (reverse *board*)) (with-paragraph (:stream stream) (write-string-quoting-specials topic stream))) (with-fillout-form (:post url :name "myform" :stream stream) (accept-input 'string "text" :events check-field :stream stream) (accept-input 'submit-button "mysubmit" :stream stream))))))))))