form

Using `form_for` in Phoenix without `Ecto.Changeset`

form_for expect the first argument to be any data structure that implements the Phoenix.HTML.FormData protocol. Phoenix implements this protocol for Plug.Conn. Hence to create form not backing by any data layer:

<%= form_for @conn, to: Routes.search_path(@conn, :new) do |f| %>
  ...
<% end %>

Adding CSS class to Phoenix `form_for`

Passing in class: "form-class" to form_for in Phoenix doesn’t work. Instead, it expect a keyword list. Hence, to add custom CSS class to form_for, use:

<%= form_for @conn, ... , [class: "form-class"], fn f -> %>
   ...
<% end %>

All of the HTML attributes of a form element can be pass in this way. For more available options, see Phoenix.HTML.Form documentation.