I'm trying to create a form that just has a text field and a hidden field that I'm going to use when passing data to an HTTP API, so I don't have a model associated with it, and by extension, no changeset.
Is it possible to do this and use form_for
or is the answer to just write HTML to create the form?
You can use form_for/4 passing a Plug.Conn
as the first argument.
From the docs (specifically the "With connection data" section):
form_for/4 expects as first argument any data structure that implements the Phoenix.HTML.FormData protocol. By default, Phoenix implements this protocol for Plug.Conn, allowing us to create forms based only on connection information.
This is useful when you are creating forms that are not backed by any kind of model data, like a search form.
<%= form_for @conn, search_path(@conn, :new), [as: :search], fn f -> %>
<%= text_input f, :for %>
<%= submit "Search" %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With