Formex v0.6.7 Formex.Controller

Helpers for controller. Imports Formex.Builder. Probably you are looking for Formex.Builder.create_form/5.

Installation:

web/web.ex

def controller do
  quote do
    use Formex.Controller
  end
end

Usage

def new(conn, _params) do
  form = create_form(App.ArticleType, %Article{})
  render(conn, "form.html", form: form)
end
def create(conn, %{"article" => article_params}) do
  App.ArticleType
  |> create_form(%Article{}, article_params)
  |> handle_form
  |> case do
    {:ok, article} ->
      # do something with a new article struct
    {:error, form} ->
      # display errors
      render(conn, "form.html", form: form)
  end
end

For usage with Ecto see Formex.Ecto.Controller

Summary

Functions

Validates form. When is valid, returns {:ok, form.new_struct}, otherwise, {:error, form} with validation errors inside form.errors

Functions

handle_form(form)
handle_form(Formex.Form.t) ::
  {:ok, Map.t} |
  {:error, Formex.Form.t}

Validates form. When is valid, returns {:ok, form.new_struct}, otherwise, {:error, form} with validation errors inside form.errors