anchor.diff: -;;;; cl-forms.lisp
  -
   (in-package #:cl-forms)
   
   (defvar *form-renderer* nil)
  
positive.code: 
  (defmacro with-form-fields (fields form &body body)
    `(let ,(loop for field in fields
  	      collect `(,field (get-field ,form ',field)))
       ,@body))
  
  (defmacro with-form-field-values (fields form &body body)
    `(let ,(loop for field in fields
  	      collect `(,field (field-value (get-field ,form ',field))))
       ,@body))
  
  (defun get-field (form field-name &optional (error-p t))
    (or 
     (cdr (assoc field-name (form-fields form)))
     (when error-p
       (error "Field ~A not found in ~A" field-name form))))
  
negative.code:     ;; Check the csrf token
      (let ((session-token (get-form-session-csrf-token form)))
        (when (or (not session-token)
                  (not (equalp session-token
                               (hunchentoot:post-parameter (form-csrf-field-name form)))))
          ;; The form is not valid. Throw an error, but reset its CSRF token for next time
          (set-form-session-csrf-token form)
          (error "Invalid CSRF token"))))
    (loop for field in (form-fields form)
       do (field-read-from-request (cdr field) form
                                   (hunchentoot:post-parameters*))))
  
  (defgeneric field-read-from-request (field form parameters))
  
  