How to use phoenix form for sending Json map

Hello, I get some data from my Json web service, now I’m going to send this map to my router, it should be noted I have 2 phoenix(Json, Html), then I try to send these map to my router in html site which got the data from Json site

my list:

[
%{"id" => "08cdfa55-41e2-4117-bca3-167f0222a3db", "title" => "1.0"}, 
]

my form code:

<%= form_for category_versions, changelog_path(@conn, :changelog, "easyblog"), fn f -> %>
        <label>
          Name: <%= text_input f, :title %>
        </label>
        <% end %>

In the mean time I have no ecto in html site and it shows me this error

Request: GET /changelog/easyblog
** (exit) an exception was raised:
    ** (Protocol.UndefinedError) protocol Phoenix.HTML.FormData not implemented for [%{"id" => "08cdfa55-41e2-4117-bca3-167f0222a3db", "title" => "1.0"}, %{"id" => "f39826df-ed82-4b26-834d-7a6002f03ecc", "title" => "1.1"}]. This protocol is implemented for: Plug.Conn

Ohh, then should I at all use phoenix form, or I should use normal html form ? I just send 2 get parameters to this page which Im here like:
?seo_alias_link=easyblog&version_id=08cdfa55-41e2-4117-bca3-

Why are forms involved at all?

As you see, my user can select version that he needs with select box

after select with normal html form

OK, I see now–your first question was not really clear about what was happening. But yeah, if you check the documentation for form_for you’ll see that it requires specific input that you’re not providing: either Ecto changeset, or your Plug.Conn with params set: https://hexdocs.pm/phoenix_html/Phoenix.HTML.Form.html#content

It’s up to you whether you want to put your data into the format form_for requires, or just use a form tag and select tag + a bit of embedded phoenix to turn your list into the select entries…

2 Likes