Fork me on GitHub
#yada
<
2018-08-20
>
agigao09:08:55

Thanks Malcolm! yeah I’m quite excited about the project, but somehow Yada docs seem to let me down quite often. I’ve opened an issue at github edge repo.

maleghast17:08:45

Anyone about in here, today?

maleghast17:08:44

I am trying to work with a form, but the resource is not parsing the form body automatically, so the only thing I have is the :body key in the context, no [:parameters :form], in fact :parameters is an empty map {} I am wondering if there is a different thing I need to do to define the resource..? At the moment I am saying that it consumes: application/x-www-form-urlencoded

tanzoniteblack17:08:24

@maleghast can you post both how you're calling it?

tanzoniteblack17:08:50

and also you're :parameters map

maleghast17:08:22

The form in the HTML page uses: method="post" action="[URL HERE]" The :post section of the resource looks like this:

:post
     {:consumes [{:media-type #{"application/x-www-form-urlencoded"}
                  :charset "UTF-8"}]
      :response
      (fn [ctx]
        (println ctx)
        (let [formdata (:body ctx)
              db-insert-result (add-organisation-to-db formdata)]
          (case (yada/content-type ctx)
            "text/html" (selmer/render-file
                         "admin/organisation-new-add.html"
                         {:title ""
                          :data db-insert-result
                          :ctx ctx}))))}

maleghast17:08:09

I don't have a :parameters map in the Resource definition - I just want the whole form to be tokenised and turned into a keyword-based map.

tanzoniteblack17:08:02

I think you might need to specify :parameters to get it to work, give me a sec to double check that

maleghast17:08:55

Ah, ok, thanks

tanzoniteblack17:08:23

@maleghast you should be able to do what you want by adding :parameters {:form {schema/Keyword schema/Any}} to your map

tanzoniteblack17:08:36

without that, it'll just ignore the form parameters

tanzoniteblack17:08:16

side note: It's better to explicitly list the parameters you want sent to this endpoint in the :parameters schema (i.e. {:form {:param1 schema/String :param2 schema/Num}})

tanzoniteblack17:08:21

but, you do you 🙂

maleghast18:08:54

Thx very much! Sorry I didn’t respond sooner - was on the Tube

maleghast18:08:29

I want to “get it working” quickly, but once it is I will define the schema properly ;-)