Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get the post in LISP hunchentoot

I try to implement a simple post example based on Hunchentoot.

Here is the code:

(define-easy-handler (test :uri "/test") () 
  (with-html-output-to-string (*standard-output* nil :prologue t :indent t)
    (:html 
     (:body
      (:h1 "Test")
      (:form :action "/test2" :method "post" :id "addform"
     (:input :type "text" :name "name" :class "txt")
     (:input :type "submit" :class "btn" :value "Submit"))))))

(define-easy-handler (test2 :uri "/test2") (name)
  (with-html-output-to-string (*standard-output* nil :prologue t :indent t)
    (:html 
     (:body
      (:h1 name)))))

I can correctly connect to http://127.0.0.1:8080/test and see the text input form. But when I submit the text, I get a blank page where I expected a page with the title given in text input.

Not sure what is wrong, can anyone advice?

like image 574
Xaving Avatar asked Feb 11 '15 11:02

Xaving


1 Answers

Change your handler to this

(define-easy-handler (test2 :uri "/test2") (name)
  (with-html-output-to-string (*standard-output* nil :prologue t :indent t)
    (:html 
     (:body
     (:h1 (str name))))))

Then it should work. Read the cl-who documentation. Especially the information on local macros. I am including the relevant documentation here.

A form which is neither a string nor a keyword nor a list beginning with a keyword will be left as is except for the following local macros:

  • Forms that look like (str form) will be substituted with

    (let ((result form)) (when result (princ result s)))
    
    (loop for i below 10 do (str i)) =>
    (loop for i below 10 do
      (let ((#:result i))
        (when #:result (princ #:result *standard-output*))))
    
  • Forms that look like (fmt form*) will be substituted with

    (format s form*)
    
    (loop for i below 10 do (fmt "~R" i)) => (loop for i below 10 do (format s "~R" i))
    
  • Forms that look like (esc form) will be substituted with

    (let ((result form)) (when result (write-string (escape-string result s))))
    
  • If a form looks like (htm form*) then each of the forms will be subject to the transformation rules we're just describing, i.e. this is the body is wrapped with another invocation of WITH-HTML-OUTPUT.

    (loop for i below 100 do (htm (:b "foo") :br))
    => (loop for i below 100 do (progn (write-string "<b>foo</b><br />" s)))
    
like image 127
bharath_g Avatar answered Sep 27 '22 18:09

bharath_g