weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.69k stars 177 forks source link

hiccup.form/form-to action parameter optional #54

Closed mefesto closed 12 years ago

mefesto commented 12 years ago

I'd like to request that the action parameter of hiccup.form/form-to be optional -- if omitted then no action attribute is needed in the HTML markup which will default the form to submit to the current url.

Below is an example of my use case:

(ns myapp.routes
  (:require [myapp.views :as form]))

(defroutes app-routes
  (GET "/myform" [] form/show)
  (POST "/myform" [] form/update))
(ns myapp.views)

(defn show [request]
  (layout/standard
    [:h1 "My Test Form"]
    (form/form-to
      [:post ""]
      (form/label :name "Name")
      (form/text-field :name)
      (form/submit-button "Submit"))))

(defn update [request]
  (do-stuff)
  (redirect "/"))

I do this frequently and just thought it would be a sensible default.

weavejester commented 12 years ago

So you're saying:

(form-to [:post] ...)

Should be the same as:

(form-to [:post ""] ...)

?

mefesto commented 12 years ago

Yep :-)

weavejester commented 12 years ago

On reflection, I think it's better to keep the action as explicit, even when it's just a blank string.