# `Phoenix.HTML.FormData`
[🔗](https://github.com/phoenixframework/phoenix_html/blob/v4.4.0/lib/phoenix_html/form_data.ex#L1)

A protocol for converting data structure into a `Phoenix.HTML.Form` struct.

The functions here are rarely invoked directly by application developers.
Rather, this is low-level entrypoint used by libraries. For working
with forms in your Phoenix application, you likely want to use
[`Phoenix.Component.to_form/2`](https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#to_form/2)
instead.

# `t`

```elixir
@type t() :: term()
```

All the types that implement this protocol.

# `input_validations`

```elixir
@spec input_validations(t(), Phoenix.HTML.Form.t(), Phoenix.HTML.Form.field()) ::
  Keyword.t()
```

Returns the HTML5 validations that would apply to
the given field.

# `input_value`

```elixir
@spec input_value(t(), Phoenix.HTML.Form.t(), Phoenix.HTML.Form.field()) :: term()
```

Returns the value for the given field.

# `to_form`

```elixir
@spec to_form(t(), Keyword.t()) :: Phoenix.HTML.Form.t()
```

Converts a data structure into a [`Phoenix.HTML.Form`](`t:Phoenix.HTML.Form.t/0`) struct.

The options have their meaning defined by the underlying
implementation but all shared options below are expected to
be implemented. All remaining options must be stored in the
returned struct.

## Shared options

  * `:as` - the value to be used as the form name

  * `:id` - the ID of the form attribute. All form inputs will
    be prefixed by the given ID

# `to_form`

```elixir
@spec to_form(t(), Phoenix.HTML.Form.t(), Phoenix.HTML.Form.field(), Keyword.t()) :: [
  Phoenix.HTML.Form.t()
]
```

Converts the field in the given form based on the data structure
into a list of [`Phoenix.HTML.Form`](`t:Phoenix.HTML.Form.t/0`) structs.

The options have their meaning defined by the underlying
implementation but all shared options below are expected to
be implemented. All remaining options must be stored in the
returned struct.

## Shared Options

  * `:id` - the id to be used in the form, defaults to the
    concatenation of the given `field` to the parent form id

  * `:as` - the name to be used in the form, defaults to the
    concatenation of the given `field` to the parent form name

  * `:default` - the value to use if none is available

  * `:prepend` - the values to prepend when rendering. This only
    applies if the field value is a list and no parameters were
    sent through the form.

  * `:append` - the values to append when rendering. This only
    applies if the field value is a list and no parameters were
    sent through the form.

  * `:action` - The user defined action being taken by the form, such
    as `:validate`, `:save`, etc.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
