Missing form parameters in Compojure POST request?

Up vote 3 down vote favorite 1 share g+ share fb share tw.

I'm having problems getting the form parameters in the following Compojure example: (ns hello-world (:use compojure. Core, ring.adapter. Jetty) (:require compojure.

Route :as route)) (defn view-form (str "" "" "Title " "" "")) (defroutes main-routes (GET "/" "Hello World") (GET "/new" (view-form)) (POST "/new" {params :params} (prn "params:" params)) (route/not-found "Not Found")) (run-jetty main-routes {:port 8088}) When submitting the form the output is always params: {} and I can't figure out why the title parameter is not in the params map. I'm using Compojure 0. 6.2. Clojure compojure link|improve this question asked May 17 '11 at 20:31cretzel3,00532142 97% accept rate.

Have you taken into account this: As of version 0.6.0, Compojure no longer adds default middleware to routes. This means you must explicitly add the wrap-params and wrap-cookies middleware to your routes. Source: github.com/weavejester/compojure I tried your example with my current setup and it worked.

I have included the following: require compojure. Handler :as handler and (handler/api routes).

You can just give a list of parameters; compojure will automatically get them out of POST/GET params accordingly. If you need to do more complex stuff you can, but I've never looked into how. For example, here's a snippet from the code for 4clojure: (POST "/problems/submit" title tags description code (create-problem title tags description code)).

I also tried it this way, but I only get nil for the parameters. – cretzel May 17 '11 at 20:50.

This is a great example of how to handle parameters (ns example2 (:use ring.adapter. Jetty :only run-jetty compojure. Core :only defroutes GET POST ring.middleware.

Params :only wrap-params)) (defroutes routes (POST "/" name (str "Thanks " name)) (GET "/" " What's your name? ")) (def app (wrap-params routes)) (run-jetty app {:port 8080}) github.com/heow/compojure-cookies-example See under Example 2 - Middleware is Features.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions